#endif
}
-GQuark
-g_file_error_quark (void)
-{
- return g_quark_from_static_string ("g-file-error-quark");
-}
+G_DEFINE_QUARK (g-file-error-quark, g_file_error)
/**
* g_file_error_from_errno:
g_set_error (error,
G_FILE_ERROR,
G_FILE_ERROR_NOMEM,
- _("Could not allocate %lu bytes to read file \"%s\""),
+ g_dngettext (GETTEXT_PACKAGE, "Could not allocate %lu byte to read file \"%s\"", "Could not allocate %lu bytes to read file \"%s\"", (gulong)total_allocated),
(gulong) total_allocated,
display_filename);
g_set_error (error,
G_FILE_ERROR,
G_FILE_ERROR_NOMEM,
- _("Could not allocate %lu bytes to read file \"%s\""),
+ g_dngettext (GETTEXT_PACKAGE, "Could not allocate %lu byte to read file \"%s\"", "Could not allocate %lu bytes to read file \"%s\"", (gulong)alloc_size),
(gulong) alloc_size,
display_filename);
display_name,
g_strerror (save_errno));
- fclose (file);
g_unlink (tmp_name);
goto out;
* get_tmp_file based on the mkstemp implementation from the GNU C library.
* Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc.
*/
-typedef gint (*GTmpFileCallback) (gchar *, gint, gint);
+typedef gint (*GTmpFileCallback) (const gchar *, gint, gint);
static gint
get_tmp_file (gchar *tmpl,
return -1;
}
+/* Some GTmpFileCallback implementations.
+ *
+ * Note: we cannot use open() or g_open() directly because even though
+ * they appear compatible, they may be vararg functions and calling
+ * varargs functions through a non-varargs type is undefined.
+ */
static gint
-wrap_mkdir (gchar *tmpl,
- int flags G_GNUC_UNUSED,
- int mode)
+wrap_g_mkdir (const gchar *filename,
+ int flags G_GNUC_UNUSED,
+ int mode)
{
/* tmpl is in UTF-8 on Windows, thus use g_mkdir() */
- return g_mkdir (tmpl, mode);
+ return g_mkdir (filename, mode);
+}
+
+static gint
+wrap_g_open (const gchar *filename,
+ int flags,
+ int mode)
+{
+ return g_open (filename, flags, mode);
}
/**
g_mkdtemp_full (gchar *tmpl,
gint mode)
{
- if (get_tmp_file (tmpl, wrap_mkdir, 0, mode) == -1)
+ if (get_tmp_file (tmpl, wrap_g_mkdir, 0, mode) == -1)
return NULL;
else
return tmpl;
gint mode)
{
/* tmpl is in UTF-8 on Windows, thus use g_open() */
- return get_tmp_file (tmpl, (GTmpFileCallback) g_open,
+ return get_tmp_file (tmpl, wrap_g_open,
flags | O_CREAT | O_EXCL, mode);
}
gint result;
result = g_get_tmp_name (tmpl, &fulltemplate,
- (GTmpFileCallback) g_open,
+ wrap_g_open,
O_CREAT | O_EXCL | O_RDWR | O_BINARY,
0600,
error);
{
gchar *fulltemplate;
- if (g_get_tmp_name (tmpl, &fulltemplate, wrap_mkdir, 0, 0700, error) == -1)
+ if (g_get_tmp_name (tmpl, &fulltemplate, wrap_g_mkdir, 0, 0700, error) == -1)
return NULL;
else
return fulltemplate;
#undef g_mkstemp
+static gint
+wrap_libc_open (const gchar *filename,
+ int flags,
+ int mode)
+{
+ return open (filename, flags, mode);
+}
+
gint
g_mkstemp (gchar *tmpl)
{
/* This is the backward compatibility system codepage version,
* thus use normal open().
*/
- return get_tmp_file (tmpl, (GTmpFileCallback) open,
+ return get_tmp_file (tmpl, wrap_libc_open,
O_RDWR | O_CREAT | O_EXCL, 0600);
}