glib/glib/gstdioprivate.h
Руслан Ижбулатов 62d387151d W32: significant symlink code changes
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.
2018-10-10 19:19:18 +00:00

68 lines
1.9 KiB
C

/* gstdioprivate.h - Private GLib stdio functions
*
* Copyright 2017 Руслан Ижбулатов
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __G_STDIOPRIVATE_H__
#define __G_STDIOPRIVATE_H__
G_BEGIN_DECLS
#if defined (G_OS_WIN32)
struct _GWin32PrivateStat
{
guint32 volume_serial;
guint64 file_index;
guint64 attributes;
guint64 allocated_size;
guint32 reparse_tag;
guint32 st_dev;
guint32 st_ino;
guint16 st_mode;
guint16 st_uid;
guint16 st_gid;
guint32 st_nlink;
guint64 st_size;
guint64 st_ctime;
guint64 st_atime;
guint64 st_mtime;
};
typedef struct _GWin32PrivateStat GWin32PrivateStat;
int g_win32_stat_utf8 (const gchar *filename,
GWin32PrivateStat *buf);
int g_win32_lstat_utf8 (const gchar *filename,
GWin32PrivateStat *buf);
int g_win32_readlink_utf8 (const gchar *filename,
gchar *buf,
gsize buf_size,
gchar **alloc_buf,
gboolean terminate);
int g_win32_fstat (int fd,
GWin32PrivateStat *buf);
#endif
G_END_DECLS
#endif /* __G_STDIOPRIVATE_H__ */