From dd3f4d6bb37b2f8eb4722bcbd2560a45ac1fa2d9 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Mon, 30 Oct 2000 22:06:22 +0000 Subject: [PATCH] gutils.c gutils.h gfileutils.c Actually, g_mkstemp() is better suited in 2000-10-31 Tor Lillqvist * gutils.c * gutils.h * gfileutils.c * gfileutils.h: Actually, g_mkstemp() is better suited in gfileutils. --- ChangeLog | 9 ++++++- ChangeLog.pre-2-0 | 9 ++++++- ChangeLog.pre-2-10 | 9 ++++++- ChangeLog.pre-2-12 | 9 ++++++- ChangeLog.pre-2-2 | 9 ++++++- ChangeLog.pre-2-4 | 9 ++++++- ChangeLog.pre-2-6 | 9 ++++++- ChangeLog.pre-2-8 | 9 ++++++- gfileutils.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ gfileutils.h | 2 ++ glib.def | 2 ++ glib/gfileutils.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ glib/gfileutils.h | 2 ++ glib/glib.def | 2 ++ glib/gutils.c | 76 ------------------------------------------------------ glib/gutils.h | 3 --- gutils.c | 76 ------------------------------------------------------ gutils.h | 3 --- 18 files changed, 222 insertions(+), 166 deletions(-) diff --git a/ChangeLog b/ChangeLog index 23d4930..9628775 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2000-10-31 Tor Lillqvist + + * gutils.c + * gutils.h + * gfileutils.c + * gfileutils.h: Actually, g_mkstemp() is better suited in gfileutils. + 2000-10-30 Tor Lillqvist * configure.in: Check for mkstemp. @@ -7,7 +14,7 @@ * gutils.h: Declare it. - * glib.def: Here, too. + * glib.def: Here, too. Plus two missing functions. 2000-10-30 Sebastian Wilhelmi diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 23d4930..9628775 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,10 @@ +2000-10-31 Tor Lillqvist + + * gutils.c + * gutils.h + * gfileutils.c + * gfileutils.h: Actually, g_mkstemp() is better suited in gfileutils. + 2000-10-30 Tor Lillqvist * configure.in: Check for mkstemp. @@ -7,7 +14,7 @@ * gutils.h: Declare it. - * glib.def: Here, too. + * glib.def: Here, too. Plus two missing functions. 2000-10-30 Sebastian Wilhelmi diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 23d4930..9628775 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +2000-10-31 Tor Lillqvist + + * gutils.c + * gutils.h + * gfileutils.c + * gfileutils.h: Actually, g_mkstemp() is better suited in gfileutils. + 2000-10-30 Tor Lillqvist * configure.in: Check for mkstemp. @@ -7,7 +14,7 @@ * gutils.h: Declare it. - * glib.def: Here, too. + * glib.def: Here, too. Plus two missing functions. 2000-10-30 Sebastian Wilhelmi diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 23d4930..9628775 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,10 @@ +2000-10-31 Tor Lillqvist + + * gutils.c + * gutils.h + * gfileutils.c + * gfileutils.h: Actually, g_mkstemp() is better suited in gfileutils. + 2000-10-30 Tor Lillqvist * configure.in: Check for mkstemp. @@ -7,7 +14,7 @@ * gutils.h: Declare it. - * glib.def: Here, too. + * glib.def: Here, too. Plus two missing functions. 2000-10-30 Sebastian Wilhelmi diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 23d4930..9628775 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,10 @@ +2000-10-31 Tor Lillqvist + + * gutils.c + * gutils.h + * gfileutils.c + * gfileutils.h: Actually, g_mkstemp() is better suited in gfileutils. + 2000-10-30 Tor Lillqvist * configure.in: Check for mkstemp. @@ -7,7 +14,7 @@ * gutils.h: Declare it. - * glib.def: Here, too. + * glib.def: Here, too. Plus two missing functions. 2000-10-30 Sebastian Wilhelmi diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 23d4930..9628775 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,10 @@ +2000-10-31 Tor Lillqvist + + * gutils.c + * gutils.h + * gfileutils.c + * gfileutils.h: Actually, g_mkstemp() is better suited in gfileutils. + 2000-10-30 Tor Lillqvist * configure.in: Check for mkstemp. @@ -7,7 +14,7 @@ * gutils.h: Declare it. - * glib.def: Here, too. + * glib.def: Here, too. Plus two missing functions. 2000-10-30 Sebastian Wilhelmi diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 23d4930..9628775 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +2000-10-31 Tor Lillqvist + + * gutils.c + * gutils.h + * gfileutils.c + * gfileutils.h: Actually, g_mkstemp() is better suited in gfileutils. + 2000-10-30 Tor Lillqvist * configure.in: Check for mkstemp. @@ -7,7 +14,7 @@ * gutils.h: Declare it. - * glib.def: Here, too. + * glib.def: Here, too. Plus two missing functions. 2000-10-30 Sebastian Wilhelmi diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 23d4930..9628775 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +2000-10-31 Tor Lillqvist + + * gutils.c + * gutils.h + * gfileutils.c + * gfileutils.h: Actually, g_mkstemp() is better suited in gfileutils. + 2000-10-30 Tor Lillqvist * configure.in: Check for mkstemp. @@ -7,7 +14,7 @@ * gutils.h: Declare it. - * glib.def: Here, too. + * glib.def: Here, too. Plus two missing functions. 2000-10-30 Sebastian Wilhelmi diff --git a/gfileutils.c b/gfileutils.c index 20a8d37..e983a1d 100644 --- a/gfileutils.c +++ b/gfileutils.c @@ -497,3 +497,78 @@ g_file_get_contents (const gchar *filename, return get_contents_posix (filename, contents, length, error); #endif } + +/** + * g_mkstemp: + * + * Open a temporary file + * + * The parameter is a string that should match the rules for mktemp, i.e. + * end in "XXXXXX". The X string will be modified to form the name + * of a file that didn't exist. + * + * Return value: A file handle (as from open()) to the file 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. + * + * From the GNU C library. + * Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc. + */ +int +g_mkstemp (char *tmpl) +{ +#ifdef HAVE_MKSTEMP + return mkstemp (tmpl); +#else + int len; + char *XXXXXX; + int count, fd; + static const char letters[] = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + glong value; + GTimeVal tv; + + len = strlen (tmpl); + if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX")) + return -1; + + /* This is where the Xs start. */ + XXXXXX = &tmpl[len - 6]; + + /* Get some more or less random data. */ + g_get_current_time (&tv); + value = tv.tv_usec ^ tv.tv_sec; + + for (count = 0; count < 100; value += 7777, ++count) + { + glong v = value; + + /* Fill in the random bits. */ + XXXXXX[0] = letters[v % 62]; + v /= 62; + XXXXXX[1] = letters[v % 62]; + v /= 62; + XXXXXX[2] = letters[v % 62]; + v /= 62; + XXXXXX[3] = letters[v % 62]; + v /= 62; + XXXXXX[4] = letters[v % 62]; + v /= 62; + XXXXXX[5] = letters[v % 62]; + + fd = open (tmpl, O_RDWR | O_CREAT | O_EXCL | O_BINARY, 0600); + + if (fd >= 0) + return fd; + else if (errno != EEXIST) + /* Any other error will apply also to other names we might + * try, and there are 2^32 or so of them, so give up now. + */ + return -1; + } + + /* We got out of the loop because we ran out of combinations to try. */ + return -1; +#endif +} diff --git a/gfileutils.h b/gfileutils.h index d49c921..e452ea7 100644 --- a/gfileutils.h +++ b/gfileutils.h @@ -80,6 +80,8 @@ gboolean g_file_get_contents (const gchar *filename, GError **error); +/* Wrapper / workalike for mkstemp() */ +int g_mkstemp (char *tmpl); G_END_DECLS diff --git a/glib.def b/glib.def index 37f9f9a..8184858 100644 --- a/glib.def +++ b/glib.def @@ -99,6 +99,8 @@ EXPORTS g_error_matches g_error_new g_error_new_literal + g_file_error_from_errno + g_file_error_quark g_file_get_contents g_file_test g_filename_from_utf8 diff --git a/glib/gfileutils.c b/glib/gfileutils.c index 20a8d37..e983a1d 100644 --- a/glib/gfileutils.c +++ b/glib/gfileutils.c @@ -497,3 +497,78 @@ g_file_get_contents (const gchar *filename, return get_contents_posix (filename, contents, length, error); #endif } + +/** + * g_mkstemp: + * + * Open a temporary file + * + * The parameter is a string that should match the rules for mktemp, i.e. + * end in "XXXXXX". The X string will be modified to form the name + * of a file that didn't exist. + * + * Return value: A file handle (as from open()) to the file 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. + * + * From the GNU C library. + * Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc. + */ +int +g_mkstemp (char *tmpl) +{ +#ifdef HAVE_MKSTEMP + return mkstemp (tmpl); +#else + int len; + char *XXXXXX; + int count, fd; + static const char letters[] = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + glong value; + GTimeVal tv; + + len = strlen (tmpl); + if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX")) + return -1; + + /* This is where the Xs start. */ + XXXXXX = &tmpl[len - 6]; + + /* Get some more or less random data. */ + g_get_current_time (&tv); + value = tv.tv_usec ^ tv.tv_sec; + + for (count = 0; count < 100; value += 7777, ++count) + { + glong v = value; + + /* Fill in the random bits. */ + XXXXXX[0] = letters[v % 62]; + v /= 62; + XXXXXX[1] = letters[v % 62]; + v /= 62; + XXXXXX[2] = letters[v % 62]; + v /= 62; + XXXXXX[3] = letters[v % 62]; + v /= 62; + XXXXXX[4] = letters[v % 62]; + v /= 62; + XXXXXX[5] = letters[v % 62]; + + fd = open (tmpl, O_RDWR | O_CREAT | O_EXCL | O_BINARY, 0600); + + if (fd >= 0) + return fd; + else if (errno != EEXIST) + /* Any other error will apply also to other names we might + * try, and there are 2^32 or so of them, so give up now. + */ + return -1; + } + + /* We got out of the loop because we ran out of combinations to try. */ + return -1; +#endif +} diff --git a/glib/gfileutils.h b/glib/gfileutils.h index d49c921..e452ea7 100644 --- a/glib/gfileutils.h +++ b/glib/gfileutils.h @@ -80,6 +80,8 @@ gboolean g_file_get_contents (const gchar *filename, GError **error); +/* Wrapper / workalike for mkstemp() */ +int g_mkstemp (char *tmpl); G_END_DECLS diff --git a/glib/glib.def b/glib/glib.def index 37f9f9a..8184858 100644 --- a/glib/glib.def +++ b/glib/glib.def @@ -99,6 +99,8 @@ EXPORTS g_error_matches g_error_new g_error_new_literal + g_file_error_from_errno + g_file_error_quark g_file_get_contents g_file_test g_filename_from_utf8 diff --git a/glib/gutils.c b/glib/gutils.c index b7b786d..6cb9141 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -40,7 +40,6 @@ #include #include #include -#include #ifdef HAVE_PWD_H #include #endif @@ -969,78 +968,3 @@ g_get_codeset (void) #endif #endif } - -/** - * g_mkstemp: - * - * Open a temporary file - * - * The parameter is a string that should match the rules for mktemp, i.e. - * end in "XXXXXX". The X string will be modified to form the name - * of a file that didn't exist. - * - * Return value: A file handle (as from open()) to the file 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. - * - * From the GNU C library. - * Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc. - */ -int -g_mkstemp (char *tmpl) -{ -#ifdef HAVE_MKSTEMP - return mkstemp (tmpl); -#else - int len; - char *XXXXXX; - int count, fd; - static const char letters[] = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - glong value; - GTimeVal tv; - - len = strlen (tmpl); - if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX")) - return -1; - - /* This is where the Xs start. */ - XXXXXX = &tmpl[len - 6]; - - /* Get some more or less random data. */ - g_get_current_time (&tv); - value = tv.tv_usec ^ tv.tv_sec; - - for (count = 0; count < 100; value += 7777, ++count) - { - glong v = value; - - /* Fill in the random bits. */ - XXXXXX[0] = letters[v % 62]; - v /= 62; - XXXXXX[1] = letters[v % 62]; - v /= 62; - XXXXXX[2] = letters[v % 62]; - v /= 62; - XXXXXX[3] = letters[v % 62]; - v /= 62; - XXXXXX[4] = letters[v % 62]; - v /= 62; - XXXXXX[5] = letters[v % 62]; - - fd = open (tmpl, O_RDWR | O_CREAT | O_EXCL | O_BINARY, 0600); - - if (fd >= 0) - return fd; - else if (errno != EEXIST) - /* Any other error will apply also to other names we might - * try, and there are 2^32 or so of them, so give up now. - */ - return -1; - } - - /* We got out of the loop because we ran out of combinations to try. */ - return -1; -#endif -} diff --git a/glib/gutils.h b/glib/gutils.h index e70ec48..c4dcb1b 100644 --- a/glib/gutils.h +++ b/glib/gutils.h @@ -161,9 +161,6 @@ gchar* g_path_get_dirname (const gchar *file_name); /* Get the codeset for the current locale */ /* gchar * g_get_codeset (void); */ -/* Wrapper / workalike for mkstemp() */ -int g_mkstemp (char *tmpl); - /* return the environment string for the variable. The returned memory * must not be freed. */ gchar* g_getenv (const gchar *variable); diff --git a/gutils.c b/gutils.c index b7b786d..6cb9141 100644 --- a/gutils.c +++ b/gutils.c @@ -40,7 +40,6 @@ #include #include #include -#include #ifdef HAVE_PWD_H #include #endif @@ -969,78 +968,3 @@ g_get_codeset (void) #endif #endif } - -/** - * g_mkstemp: - * - * Open a temporary file - * - * The parameter is a string that should match the rules for mktemp, i.e. - * end in "XXXXXX". The X string will be modified to form the name - * of a file that didn't exist. - * - * Return value: A file handle (as from open()) to the file 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. - * - * From the GNU C library. - * Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc. - */ -int -g_mkstemp (char *tmpl) -{ -#ifdef HAVE_MKSTEMP - return mkstemp (tmpl); -#else - int len; - char *XXXXXX; - int count, fd; - static const char letters[] = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - glong value; - GTimeVal tv; - - len = strlen (tmpl); - if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX")) - return -1; - - /* This is where the Xs start. */ - XXXXXX = &tmpl[len - 6]; - - /* Get some more or less random data. */ - g_get_current_time (&tv); - value = tv.tv_usec ^ tv.tv_sec; - - for (count = 0; count < 100; value += 7777, ++count) - { - glong v = value; - - /* Fill in the random bits. */ - XXXXXX[0] = letters[v % 62]; - v /= 62; - XXXXXX[1] = letters[v % 62]; - v /= 62; - XXXXXX[2] = letters[v % 62]; - v /= 62; - XXXXXX[3] = letters[v % 62]; - v /= 62; - XXXXXX[4] = letters[v % 62]; - v /= 62; - XXXXXX[5] = letters[v % 62]; - - fd = open (tmpl, O_RDWR | O_CREAT | O_EXCL | O_BINARY, 0600); - - if (fd >= 0) - return fd; - else if (errno != EEXIST) - /* Any other error will apply also to other names we might - * try, and there are 2^32 or so of them, so give up now. - */ - return -1; - } - - /* We got out of the loop because we ran out of combinations to try. */ - return -1; -#endif -} diff --git a/gutils.h b/gutils.h index e70ec48..c4dcb1b 100644 --- a/gutils.h +++ b/gutils.h @@ -161,9 +161,6 @@ gchar* g_path_get_dirname (const gchar *file_name); /* Get the codeset for the current locale */ /* gchar * g_get_codeset (void); */ -/* Wrapper / workalike for mkstemp() */ -int g_mkstemp (char *tmpl); - /* return the environment string for the variable. The returned memory * must not be freed. */ gchar* g_getenv (const gchar *variable); -- 2.7.4