From: Tor Lillqvist Date: Thu, 9 Jun 2005 10:46:21 +0000 (+0000) Subject: glib/gstdio.h glib/gstdio.c Add a chdir() wrapper, too. X-Git-Tag: GLIB_2_7_0~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f928d83482f16f8803b3c37ba281349d6f218ce6;p=platform%2Fupstream%2Fglib.git glib/gstdio.h glib/gstdio.c Add a chdir() wrapper, too. 2005-06-09 Tor Lillqvist * glib/gstdio.h * glib/gstdio.c * glib/glib.symbols: Add a chdir() wrapper, too. * glib/glib.symbols: Add g_win32_locale_filename_from_utf8(). * glib/gwin32.c (g_win32_locale_filename_from_utf8): Clarify doc comment. --- diff --git a/ChangeLog b/ChangeLog index ccde0de..0a4efe8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-06-09 Tor Lillqvist + + * glib/gstdio.h + * glib/gstdio.c + * glib/glib.symbols: Add a chdir() wrapper, too. + + * glib/glib.symbols: Add g_win32_locale_filename_from_utf8(). + + * glib/gwin32.c (g_win32_locale_filename_from_utf8): Clarify doc + comment. + 2005-06-08 Tor Lillqvist * glib/gutils.c (get_windows_directory_root): New helper function diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index ccde0de..0a4efe8 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,14 @@ +2005-06-09 Tor Lillqvist + + * glib/gstdio.h + * glib/gstdio.c + * glib/glib.symbols: Add a chdir() wrapper, too. + + * glib/glib.symbols: Add g_win32_locale_filename_from_utf8(). + + * glib/gwin32.c (g_win32_locale_filename_from_utf8): Clarify doc + comment. + 2005-06-08 Tor Lillqvist * glib/gutils.c (get_windows_directory_root): New helper function diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index ccde0de..0a4efe8 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,14 @@ +2005-06-09 Tor Lillqvist + + * glib/gstdio.h + * glib/gstdio.c + * glib/glib.symbols: Add a chdir() wrapper, too. + + * glib/glib.symbols: Add g_win32_locale_filename_from_utf8(). + + * glib/gwin32.c (g_win32_locale_filename_from_utf8): Clarify doc + comment. + 2005-06-08 Tor Lillqvist * glib/gutils.c (get_windows_directory_root): New helper function diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index ccde0de..0a4efe8 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,14 @@ +2005-06-09 Tor Lillqvist + + * glib/gstdio.h + * glib/gstdio.c + * glib/glib.symbols: Add a chdir() wrapper, too. + + * glib/glib.symbols: Add g_win32_locale_filename_from_utf8(). + + * glib/gwin32.c (g_win32_locale_filename_from_utf8): Clarify doc + comment. + 2005-06-08 Tor Lillqvist * glib/gutils.c (get_windows_directory_root): New helper function diff --git a/glib/glib.symbols b/glib/glib.symbols index 376c232..411809b 100644 --- a/glib/glib.symbols +++ b/glib/glib.symbols @@ -858,6 +858,7 @@ g_open g_creat g_rename g_mkdir +g_chdir g_stat g_lstat g_unlink @@ -1228,6 +1229,7 @@ g_win32_get_package_installation_subdirectory PRIVATE g_win32_get_package_installation_subdirectory_utf8 g_win32_get_windows_version g_win32_getlocale +g_win32_locale_filename_from_utf8 #endif #endif #endif diff --git a/glib/gstdio.c b/glib/gstdio.c index 97a6027..35fa87e 100644 --- a/glib/gstdio.c +++ b/glib/gstdio.c @@ -50,7 +50,7 @@ /** * g_access: - * @filename: a pathname in the GLib file name encoding + * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) * @mode: as in access() * * A wrapper for the POSIX access() function. This function is used to @@ -120,7 +120,7 @@ g_access (const gchar *filename, /** * g_chmod: - * @filename: a pathname in the GLib file name encoding + * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) * @mode: as in chmod() * * A wrapper for the POSIX chmod() function. The chmod() function is @@ -189,7 +189,7 @@ g_chmod (const gchar *filename, /** * g_open: - * @filename: a pathname in the GLib file name encoding + * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) * @flags: as in open() * @mode: as in open() * @@ -260,7 +260,7 @@ g_open (const gchar *filename, /** * g_creat: - * @filename: a pathname in the GLib file name encoding + * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) * @mode: as in creat() * * A wrapper for the POSIX creat() function. The creat() function is @@ -329,7 +329,7 @@ g_creat (const gchar *filename, /** * g_rename: - * @oldfilename: a pathname in the GLib file name encoding + * @oldfilename: a pathname in the GLib file name encoding (UTF-8 on Windows) * @newfilename: a pathname in the GLib file name encoding * * A wrapper for the POSIX rename() function. The rename() function @@ -419,7 +419,7 @@ g_rename (const gchar *oldfilename, /** * g_mkdir: - * @filename: a pathname in the GLib file name encoding + * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) * @mode: permissions to use for the newly created directory * * A wrapper for the POSIX mkdir() function. The mkdir() function @@ -483,8 +483,70 @@ g_mkdir (const gchar *filename, } /** + * g_chdir: + * @path: a pathname in the GLib file name encoding (UTF-8 on Windows) + * + * A wrapper for the POSIX chdir() function. The function changes the + * current directory of the process to @path. + * + * See your C library manual for more details about chdir(). + * + * Returns: 0 on success, -1 if an error occurred. + * + * Since: 2.8 + */ +int +g_chdir (const gchar *path) +{ +#ifdef G_OS_WIN32 + if (G_WIN32_HAVE_WIDECHAR_API ()) + { + wchar_t *wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL); + int retval; + int save_errno; + + if (wpath == NULL) + { + errno = EINVAL; + return -1; + } + + retval = _wchdir (wpath); + save_errno = errno; + + g_free (wpath); + + errno = save_errno; + return retval; + } + else + { + gchar *cp_path = g_locale_from_utf8 (path, -1, NULL, NULL, NULL); + int retval; + int save_errno; + + if (cp_path == NULL) + { + errno = EINVAL; + return -1; + } + + retval = chdir (cp_path); + save_errno = errno; + + g_free (cp_path); + + errno = save_errno; + return retval; + } +#else + return chdir (path); +#endif +} + +/** * g_stat: - * @filename: a pathname in the GLib file name encoding + * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) * @buf: a pointer to a stat struct, which * will be filled with the file information * @@ -550,7 +612,7 @@ g_stat (const gchar *filename, /** * g_lstat: - * @filename: a pathname in the GLib file name encoding + * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) * @buf: a pointer to a stat struct, which * will be filled with the file information * @@ -581,7 +643,7 @@ g_lstat (const gchar *filename, /** * g_unlink: - * @filename: a pathname in the GLib file name encoding + * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) * * A wrapper for the POSIX unlink() function. The unlink() function * deletes a name from the filesystem. If this was the last link to the @@ -648,7 +710,7 @@ g_unlink (const gchar *filename) /** * g_remove: - * @filename: a pathname in the GLib file name encoding + * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) * * A wrapper for the POSIX remove() function. The remove() function * deletes a name from the filesystem. @@ -722,7 +784,7 @@ g_remove (const gchar *filename) /** * g_rmdir: - * @filename: a pathname in the GLib file name encoding + * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) * * A wrapper for the POSIX rmdir() function. The rmdir() function * deletes a directory from the filesystem. @@ -786,7 +848,7 @@ g_rmdir (const gchar *filename) /** * g_fopen: - * @filename: a pathname in the GLib file name encoding + * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) * @mode: a string describing the mode in which the file should be * opened * @@ -863,7 +925,7 @@ g_fopen (const gchar *filename, /** * g_freopen: - * @filename: a pathname in the GLib file name encoding + * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows) * @mode: a string describing the mode in which the file should be * opened * @stream: an existing stream which will be reused, or %NULL diff --git a/glib/gstdio.h b/glib/gstdio.h index c201882..5b85314 100644 --- a/glib/gstdio.h +++ b/glib/gstdio.h @@ -37,6 +37,7 @@ #define g_creat creat #define g_rename rename #define g_mkdir mkdir +#define g_chdir chdir #define g_stat stat #define g_lstat lstat #define g_unlink unlink @@ -76,6 +77,8 @@ int g_rename (const gchar *oldfilename, int g_mkdir (const gchar *filename, int mode); +int g_chdir (const gchar *path); + int g_stat (const gchar *filename, struct stat *buf); diff --git a/glib/gwin32.c b/glib/gwin32.c index 06b1113..4e9bfc4 100644 --- a/glib/gwin32.c +++ b/glib/gwin32.c @@ -1483,11 +1483,13 @@ g_win32_get_windows_version (void) * In such a case, and if the filename refers to an existing file, and * the file system stores alternate short (8.3) names for directory * entries, the short form of the filename is returned. Note that the - * "short" name might in fact be longer than the Unicode name. If no - * system codepage name for the file is possible, %NULL is returned. + * "short" name might in fact be longer than the Unicode name if the + * Unicode name has very short pathname components containing + * non-ASCII characters. If no system codepage name for the file is + * possible, %NULL is returned. * - * The return value is dynamically allocated and should be freed when - * no longer used. + * The return value is dynamically allocated and should be freed with + * g_free() when no longer needed. * * Return value: The converted filename, or %NULL on conversion * failure and lack of short names.