glib/gstdio.h glib/gstdio.c Wrap also creat(). (#171285)
authorTor Lillqvist <tml@novell.com>
Fri, 8 Apr 2005 12:21:28 +0000 (12:21 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Fri, 8 Apr 2005 12:21:28 +0000 (12:21 +0000)
2005-04-08  Tor Lillqvist  <tml@novell.com>

* glib/gstdio.h
* glib/gstdio.c
* glib/glib.symbols (g_creat): Wrap also  creat(). (#171285)

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-8
glib/glib.symbols
glib/gstdio.c
glib/gstdio.h

index b820035..053bb35 100644 (file)
--- 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  <tml@novell.com>
 
index b820035..053bb35 100644 (file)
@@ -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  <tml@novell.com>
 
index b820035..053bb35 100644 (file)
@@ -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  <tml@novell.com>
 
index b820035..053bb35 100644 (file)
@@ -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  <tml@novell.com>
 
index 28c23e7..f08e034 100644 (file)
@@ -852,6 +852,7 @@ g_spawn_sync
 g_access
 g_chmod
 g_open
+g_creat
 g_rename
 g_mkdir
 g_stat
index 2edd990..609ff05 100644 (file)
@@ -259,6 +259,75 @@ g_open (const gchar *filename,
 }
 
 /**
+ * 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
  * @newfilename: a pathname in the GLib file name encoding
index 1189a41..c201882 100644 (file)
@@ -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);