mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-22 17:08:53 +02:00
glib/gstdio.h glib/gstdio.c Wrap also creat(). (#171285)
2005-04-08 Tor Lillqvist <tml@novell.com> * glib/gstdio.h * glib/gstdio.c * glib/glib.symbols (g_creat): Wrap also creat(). (#171285)
This commit is contained in:
committed by
Tor Lillqvist
parent
9099d64b3a
commit
ff79c0b525
@@ -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
|
||||
|
Reference in New Issue
Block a user