From ff79c0b525232d6edfab2f8c505d11746cbd5fe7 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Fri, 8 Apr 2005 12:21:28 +0000 Subject: [PATCH] glib/gstdio.h glib/gstdio.c Wrap also creat(). (#171285) 2005-04-08 Tor Lillqvist * glib/gstdio.h * glib/gstdio.c * glib/glib.symbols (g_creat): Wrap also creat(). (#171285) --- ChangeLog | 4 +-- ChangeLog.pre-2-10 | 4 +-- ChangeLog.pre-2-12 | 4 +-- ChangeLog.pre-2-8 | 4 +-- glib/glib.symbols | 1 + glib/gstdio.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++ glib/gstdio.h | 4 +++ 7 files changed, 82 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index b820035af..053bb3588 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,8 +2,8 @@ * glib/gstdio.h * glib/gstdio.c - * glib/glib.symbols (g_access, g_chmod): Wrap also access() and - chmod(). (#169623) + * glib/glib.symbols (g_access, g_chmod, g_creat): Wrap also + access(), chmod() and creat(). (#169623, #171285) 2005-04-08 Tor Lillqvist diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index b820035af..053bb3588 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -2,8 +2,8 @@ * glib/gstdio.h * glib/gstdio.c - * glib/glib.symbols (g_access, g_chmod): Wrap also access() and - chmod(). (#169623) + * glib/glib.symbols (g_access, g_chmod, g_creat): Wrap also + access(), chmod() and creat(). (#169623, #171285) 2005-04-08 Tor Lillqvist diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index b820035af..053bb3588 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -2,8 +2,8 @@ * glib/gstdio.h * glib/gstdio.c - * glib/glib.symbols (g_access, g_chmod): Wrap also access() and - chmod(). (#169623) + * glib/glib.symbols (g_access, g_chmod, g_creat): Wrap also + access(), chmod() and creat(). (#169623, #171285) 2005-04-08 Tor Lillqvist diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index b820035af..053bb3588 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -2,8 +2,8 @@ * glib/gstdio.h * glib/gstdio.c - * glib/glib.symbols (g_access, g_chmod): Wrap also access() and - chmod(). (#169623) + * glib/glib.symbols (g_access, g_chmod, g_creat): Wrap also + access(), chmod() and creat(). (#169623, #171285) 2005-04-08 Tor Lillqvist diff --git a/glib/glib.symbols b/glib/glib.symbols index 28c23e718..f08e03455 100644 --- a/glib/glib.symbols +++ b/glib/glib.symbols @@ -852,6 +852,7 @@ g_spawn_sync g_access g_chmod g_open +g_creat g_rename g_mkdir g_stat diff --git a/glib/gstdio.c b/glib/gstdio.c index 2edd99066..609ff05fc 100644 --- a/glib/gstdio.c +++ b/glib/gstdio.c @@ -258,6 +258,75 @@ g_open (const gchar *filename, #endif } +/** + * g_creat: + * @filename: a pathname in the GLib file name encoding + * @mode: as in creat() + * + * A wrapper for the POSIX creat() function. The creat() function is + * used to convert a pathname into a file descriptor, creating a file + * if necessar. Note that on POSIX systems file descriptors are + * implemented by the operating system. On Windows, it's the C library + * that implements creat() and file descriptors. The actual Windows + * API for opening files is something different. + * + * See the C library manual for more details about creat(). + * + * Returns: a new file descriptor, or -1 if an error occurred. The + * return value can be used exactly like the return value from creat(). + * + * Since: 2.7 + */ +int +g_creat (const gchar *filename, + int mode) +{ +#ifdef G_OS_WIN32 + if (G_WIN32_HAVE_WIDECHAR_API ()) + { + wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL); + int retval; + int save_errno; + + if (wfilename == NULL) + { + errno = EINVAL; + return -1; + } + + retval = _wcreat (wfilename, mode); + save_errno = errno; + + g_free (wfilename); + + errno = save_errno; + return retval; + } + else + { + gchar *cp_filename = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL); + int retval; + int save_errno; + + if (cp_filename == NULL) + { + errno = EINVAL; + return -1; + } + + retval = creat (cp_filename, mode); + save_errno = errno; + + g_free (cp_filename); + + errno = save_errno; + return retval; + } +#else + return creat (filename, mode); +#endif +} + /** * g_rename: * @oldfilename: a pathname in the GLib file name encoding diff --git a/glib/gstdio.h b/glib/gstdio.h index 1189a4177..c201882e5 100644 --- a/glib/gstdio.h +++ b/glib/gstdio.h @@ -34,6 +34,7 @@ #define g_access access #define g_chmod chmod #define g_open open +#define g_creat creat #define g_rename rename #define g_mkdir mkdir #define g_stat stat @@ -66,6 +67,9 @@ int g_open (const gchar *filename, int flags, int mode); +int g_creat (const gchar *filename, + int mode); + int g_rename (const gchar *oldfilename, const gchar *newfilename);