X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gfileutils.c;h=86b33bc00baa30cb3d163c5064d285d27bdaded3;hb=525689823d7dcd269b052c58545a5ff1d8db65f8;hp=e1a870b9d2de50b16486711e5df516621318a57a;hpb=91d5e23f5fa8b9eda5cf07c3aedec46256183550;p=platform%2Fupstream%2Fglib.git diff --git a/gfileutils.c b/gfileutils.c index e1a870b..86b33bc 100644 --- a/gfileutils.c +++ b/gfileutils.c @@ -27,11 +27,13 @@ #include #endif #include +#include #include #include #include #include #include +#include #ifdef G_OS_WIN32 #include @@ -60,7 +62,7 @@ #define O_BINARY 0 #endif -#define _(x) x +#include "glibintl.h" /** * g_file_test: @@ -115,10 +117,25 @@ g_file_error_quark (void) return q; } +/** + * g_file_error_from_errno: + * @err_no: an "errno" value + * + * Gets a #GFileError constant based on the passed-in errno. + * For example, if you pass in EEXIST this function returns + * #G_FILE_ERROR_EXIST. Unlike errno values, you can portably + * assume that all #GFileError values will exist. + * + * Normally a #GFileError value goes into a #GError returned + * from a function that manipulates files. So you would use + * g_file_error_from_errno() when constructing a #GError. + * + * Return value: #GFileError corresponding to the given errno + **/ GFileError -g_file_error_from_errno (gint en) +g_file_error_from_errno (gint err_no) { - switch (en) + switch (err_no) { #ifdef EEXIST case EEXIST: @@ -376,7 +393,8 @@ get_contents_posix (const gchar *filename, struct stat stat_buf; gint fd; - fd = open (filename, O_RDONLY); + /* O_BINARY useful on Cygwin */ + fd = open (filename, O_RDONLY|O_BINARY); if (fd < 0) { @@ -522,7 +540,6 @@ g_file_get_contents (const gchar *filename, * opened for reading and writing. The file is opened in binary mode * on platforms where there is a difference. The file handle should be * closed with close(). In case of errors, -1 is returned. - * */ int g_mkstemp (char *tmpl) @@ -605,9 +622,11 @@ g_mkstemp (char *tmpl) * The actual name used is returned in @name_used if non-NULL. This * string should be freed with g_free when not needed any longer. * - * If some error occurs, @error is set, and -1 is returned. Otherwise, - * the file descriptor to a file opened for reading and writing with - * g_mkstemp() is returned. + * Return value: A file handle (as from open()) to the file + * opened for reading and writing. The file is opened in binary mode + * on platforms where there is a difference. The file handle should be + * closed with close(). In case of errors, -1 is returned and + * @error will be set. **/ int g_file_open_tmp (const char *tmpl, @@ -615,14 +634,18 @@ g_file_open_tmp (const char *tmpl, GError **error) { int retval; - char *tmpdir; + const char *tmpdir; char *sep; char *fulltemplate; if (tmpl == NULL) tmpl = ".XXXXXX"; - if (strchr (tmpl, G_DIR_SEPARATOR)) + if (strchr (tmpl, G_DIR_SEPARATOR) +#ifdef G_OS_WIN32 + || strchr (tmpl, '/') +#endif + ) { g_set_error (error, G_FILE_ERROR, @@ -639,7 +662,7 @@ g_file_open_tmp (const char *tmpl, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, - _("Template '%s' doesn end with XXXXXX"), + _("Template '%s' doesn't end with XXXXXX"), tmpl); return -1; }