odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.66k stars 584 forks source link

Fixed error handling in read_dir on Windows #3706

Closed leidegre closed 3 months ago

leidegre commented 3 months ago

Fix for https://github.com/odin-lang/Odin/issues/3705

Kelimion commented 3 months ago

e wasn't declared yet at this point, so I'd either do so right here, like this:

    find_data := &win32.WIN32_FIND_DATAW{}
    find_handle := win32.FindFirstFileW(raw_data(wpath_search), find_data)
    if find_handle == win32.INVALID_HANDLE_VALUE {
        e := Errno(win32.GetLastError())
        return dfi[:], e
    }
    defer win32.FindClose(find_handle)

Or use the err return value we already have

    find_data := &win32.WIN32_FIND_DATAW{}
    find_handle := win32.FindFirstFileW(raw_data(wpath_search), find_data)
    if find_handle == win32.INVALID_HANDLE_VALUE {
        err = Errno(win32.GetLastError())
        return dfi[:], err
    }
    defer win32.FindClose(find_handle)

We do still need to return dfi[:] so the caller can free the (empty) result list backed by the dynamic array, like they would on a successful call, so return dfi[:], err seems sensible.