Skip to content
  • LRN's avatar
    W32: significant symlink code changes · 62d38715
    LRN authored
    Put the core readlink() code into a separate
    _g_win32_readlink_handle_raw() function that takes a file handle,
    can optionally ensure NUL-terminatedness of its output
    (for cases where we need a NUL-terminator and do *not* need
    to get the exact contents of the symlink as it is stored in FS)
    and can either fill a caller-provided buffer *or* allocate
    its own buffer, and can also read the reparse tag.
    
    Put the rest of readlink() code into separate
    functions that do UTF-16<->UTF-8, strip inconvenient prefix
    and open/close the symlink file handle as needed.
    
    Split _g_win32_stat_utf16_no_trailing_slashes() into
    two functions - the one that takes a filename and the one
    that takes a file descriptor. The part of these functions
    that would have been duplicate is now split into the
    _g_win32_fill_privatestat() funcion.
    
    Add more comments explaining what each function does.
    Only g_win32_readlink_utf8(), which is callable from outside
    via private function interface, gets a real doc-comment,
    the rest get normal, non-doc comments.
    
    Change all callers to use the new version of the private
    g_win32_readlink_utf8() function, which can now NUL-terminate
    and allocate on demand - no need to call it in a loop.
    
    Also, the new code should correctly get reparse tag when the
    caller does fstat() on a symlink. Do note that this requires
    the caller to get a FD for the symlink, not the target. Figuring
    out how to do that is up to the caller.
    
    Since symlink info (target path and reparse tag) are now always
    read directly, via DeviceIoControl(), we don't need to use
    FindFirstFileW() anymore.
    62d38715