* 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>
* 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>
* 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>
* 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>
}
/**
+ * 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