X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=glib%2Fgutils.c;h=526ccb22b71c7f25d7738f9d3324547b91a0eac4;hb=30ed5f53e205e6bfc35126a9d3c62dac8a9c5dad;hp=2d049b1ae9b524c961590b9a556dbe00e5a05d2b;hpb=c70b4978598a3b4e3d712e89cacf21b5369ed53e;p=platform%2Fupstream%2Fglib.git diff --git a/glib/gutils.c b/glib/gutils.c index 2d049b1..526ccb2 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -12,9 +12,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library; if not, see . */ /* @@ -29,10 +27,8 @@ */ #include "config.h" +#include "glibconfig.h" -#ifdef HAVE_UNISTD_H -#include -#endif #include #include #include @@ -42,8 +38,9 @@ #include #include #include -#ifdef HAVE_PWD_H +#ifdef G_OS_UNIX #include +#include #endif #include #ifdef HAVE_SYS_PARAM_H @@ -172,7 +169,6 @@ _glib_get_dll_directory (void) #endif -#if !defined (HAVE_MEMMOVE) && !defined (HAVE_WORKING_BCOPY) /** * g_memmove: * @dest: the destination address to copy the bytes to. @@ -182,37 +178,8 @@ _glib_get_dll_directory (void) * Copies a block of memory @len bytes long, from @src to @dest. * The source and destination areas may overlap. * - * In order to use this function, you must include - * string.h yourself, because this macro will - * typically simply resolve to memmove() and GLib does not include - * string.h for you. + * Deprecated:2.40: Just use memmove(). */ -void -g_memmove (gpointer dest, - gconstpointer src, - gulong len) -{ - gchar* destptr = dest; - const gchar* srcptr = src; - if (src + len < dest || dest + len < src) - { - bcopy (src, dest, len); - return; - } - else if (dest <= src) - { - while (len--) - *(destptr++) = *(srcptr++); - } - else - { - destptr += len; - srcptr += len; - while (len--) - *(--destptr) = *(--srcptr); - } -} -#endif /* !HAVE_MEMMOVE && !HAVE_WORKING_BCOPY */ #ifdef G_OS_WIN32 #undef g_atexit @@ -259,35 +226,13 @@ void g_atexit (GVoidFunc func) { gint result; - const gchar *error = NULL; - /* keep this in sync with glib.h */ - -#ifdef G_NATIVE_ATEXIT - result = ATEXIT (func); - if (result) - error = g_strerror (errno); -#elif defined (HAVE_ATEXIT) -# ifdef NeXT /* @#%@! NeXTStep */ - result = !atexit ((void (*)(void)) func); - if (result) - error = g_strerror (errno); -# else result = atexit ((void (*)(void)) func); if (result) - error = g_strerror (errno); -# endif /* NeXT */ -#elif defined (HAVE_ON_EXIT) - result = on_exit ((void (*)(int, void *)) func, NULL); - if (result) - error = g_strerror (errno); -#else - result = 0; - error = "no implementation"; -#endif /* G_NATIVE_ATEXIT */ - - if (error) - g_error ("Could not register atexit() function: %s", error); + { + g_error ("Could not register atexit() function: %s", + g_strerror (errno)); + } } /* Based on execvp() from GNU Libc. @@ -368,17 +313,17 @@ g_find_program_in_path (const gchar *program) * * On Windows, if @program does not have a file type suffix, tries * with the suffixes .exe, .cmd, .bat and .com, and the suffixes in - * the PATHEXT environment variable. + * the `PATHEXT` environment variable. * * On Windows, it looks for the file in the same way as CreateProcess() * would. This means first in the directory where the executing * program was loaded from, then in the current directory, then in the * Windows 32-bit system directory, then in the Windows directory, and - * finally in the directories in the PATH environment - * variable. If the program is found, the return value contains the - * full name including the type suffix. + * finally in the directories in the `PATH` environment variable. If + * the program is found, the return value contains the full name + * including the type suffix. * - * Return value: a newly-allocated string with the absolute path, or %NULL + * Returns: a newly-allocated string with the absolute path, or %NULL **/ #ifdef G_OS_WIN32 static gchar * @@ -421,12 +366,12 @@ g_find_program_in_path (const gchar *program) } path = g_getenv ("PATH"); -#if defined(G_OS_UNIX) || defined(G_OS_BEOS) +#if defined(G_OS_UNIX) if (path == NULL) { - /* There is no `PATH' in the environment. The default + /* There is no 'PATH' in the environment. The default * search path in GNU libc is the current directory followed by - * the path `confstr' returns for `_CS_PATH'. + * the path 'confstr' returns for '_CS_PATH'. */ /* In GLib we put . last, for security, and don't use the @@ -510,7 +455,7 @@ g_find_program_in_path (const gchar *program) if (p == path) /* Two adjacent colons, or a colon at the beginning or the end - * of `PATH' means to search the current directory. + * of 'PATH' means to search the current directory. */ startp = name + 1; else @@ -655,7 +600,7 @@ g_get_user_database_entry (void) { static UserDatabaseEntry e; -#ifdef HAVE_PWD_H +#ifdef G_OS_UNIX { struct passwd *pw = NULL; gpointer buffer = NULL; @@ -697,8 +642,7 @@ g_get_user_database_entry (void) } error = error < 0 ? errno : error; # else /* HAVE_NONPOSIX_GETPWUID_R */ - /* HPUX 11 falls into the HAVE_POSIX_GETPWUID_R case */ -# if defined(_AIX) || defined(__hpux) +# if defined(_AIX) error = getpwuid_r (getuid (), &pwd, buffer, bufsize); pw = error == 0 ? &pwd : NULL; # else /* !_AIX */ @@ -771,7 +715,7 @@ g_get_user_database_entry (void) g_free (buffer); } -#else /* !HAVE_PWD_H */ +#endif /* G_OS_UNIX */ #ifdef G_OS_WIN32 { @@ -786,12 +730,6 @@ g_get_user_database_entry (void) } #endif /* G_OS_WIN32 */ -#endif /* !HAVE_PWD_H */ - -#ifdef __EMX__ - /* change '\\' in %HOME% to '/' */ - g_strdelimit (e.home_dir, "\\",'/'); -#endif if (!e.user_name) e.user_name = g_strdup ("somebody"); if (!e.real_name) @@ -826,10 +764,10 @@ g_get_user_name (void) /** * g_get_real_name: * - * Gets the real name of the user. This usually comes from the user's entry - * in the passwd file. The encoding of the returned - * string is system-defined. (On Windows, it is, however, always UTF-8.) - * If the real user name cannot be determined, the string "Unknown" is + * Gets the real name of the user. This usually comes from the user's + * entry in the `passwd` file. The encoding of the returned string is + * system-defined. (On Windows, it is, however, always UTF-8.) If the + * real user name cannot be determined, the string "Unknown" is * returned. * * Returns: the user's real name. @@ -850,28 +788,23 @@ g_get_real_name (void) * Gets the current user's home directory. * * As with most UNIX tools, this function will return the value of the - * HOME environment variable if it is set to an existing - * absolute path name, falling back to the passwd - * file in the case that it is unset. - * - * If the path given in HOME is non-absolute, does not - * exist, or is not a directory, the result is undefined. - * - * - * Before version 2.36 this function would ignore the - * HOME environment variable, taking the value from the - * passwd database instead. This was changed to - * increase the compatibility of GLib with other programs (and the XDG - * basedir specification) and to increase testability of programs - * based on GLib (by making it easier to run them from test - * frameworks). - * - * If your program has a strong requirement for either the new or the - * old behaviour (and if you don't wish to increase your GLib - * dependency to ensure that the new behaviour is in effect) then you - * should either directly check the HOME environment - * variable yourself or unset it before calling any functions in GLib. - * + * `HOME` environment variable if it is set to an existing absolute path + * name, falling back to the `passwd` file in the case that it is unset. + * + * If the path given in `HOME` is non-absolute, does not exist, or is + * not a directory, the result is undefined. + * + * Before version 2.36 this function would ignore the `HOME` environment + * variable, taking the value from the `passwd` database instead. This was + * changed to increase the compatibility of GLib with other programs (and + * the XDG basedir specification) and to increase testability of programs + * based on GLib (by making it easier to run them from test frameworks). + * + * If your program has a strong requirement for either the new or the + * old behaviour (and if you don't wish to increase your GLib + * dependency to ensure that the new behaviour is in effect) then you + * should either directly check the `HOME` environment variable yourself + * or unset it before calling any functions in GLib. * * Returns: the current user's home directory */ @@ -954,12 +887,20 @@ g_get_home_dir (void) /** * g_get_tmp_dir: * - * Gets the directory to use for temporary files. This is found from - * inspecting the environment variables TMPDIR, - * TMP, and TEMP in that order. If none - * of those are defined "/tmp" is returned on UNIX and "C:\" on Windows. - * The encoding of the returned string is system-defined. On Windows, - * it is always UTF-8. The return value is never %NULL or the empty string. + * Gets the directory to use for temporary files. + * + * On UNIX, this is taken from the `TMPDIR` environment variable. + * If the variable is not set, `P_tmpdir` is + * used, as defined by the system C library. Failing that, a + * hard-coded default of "/tmp" is returned. + * + * On Windows, the `TEMP` environment variable is used, with the + * root directory of the Windows installation (eg: "C:\") used + * as a default. + * + * The encoding of the returned string is system-defined. On Windows, + * it is always UTF-8. The return value is never %NULL or the empty + * string. * * Returns: the directory to use for temporary files. */ @@ -972,27 +913,16 @@ g_get_tmp_dir (void) { gchar *tmp; - tmp = g_strdup (g_getenv ("TMPDIR")); - - if (tmp == NULL || *tmp == '\0') - { - g_free (tmp); - tmp = g_strdup (g_getenv ("TMP")); - } - - if (tmp == NULL || *tmp == '\0') - { - g_free (tmp); - tmp = g_strdup (g_getenv ("TEMP")); - } - #ifdef G_OS_WIN32 + tmp = g_strdup (g_getenv ("TEMP")); + if (tmp == NULL || *tmp == '\0') { g_free (tmp); tmp = get_windows_directory_root (); } -#else +#else /* G_OS_WIN32 */ + tmp = g_strdup (g_getenv ("TMPDIR")); #ifdef P_tmpdir if (tmp == NULL || *tmp == '\0') @@ -1004,7 +934,7 @@ g_get_tmp_dir (void) if (k > 1 && G_IS_DIR_SEPARATOR (tmp[k - 1])) tmp[k - 1] = '\0'; } -#endif +#endif /* P_tmpdir */ if (tmp == NULL || *tmp == '\0') { @@ -1068,14 +998,15 @@ static gchar *g_prgname = NULL; /** * g_get_prgname: * - * Gets the name of the program. This name should not - * be localized, contrast with g_get_application_name(). - * (If you are using GDK or GTK+ the program name is set in gdk_init(), + * Gets the name of the program. This name should not be localized, + * in contrast to g_get_application_name(). + * + * If you are using GDK or GTK+ the program name is set in gdk_init(), * which is called by gtk_init(). The program name is found by taking - * the last component of argv[0].) + * the last component of @argv[0]. * * Returns: the name of the program. The returned string belongs - * to GLib and must not be modified or freed. + * to GLib and must not be modified or freed. */ const gchar* g_get_prgname (void) @@ -1116,9 +1047,10 @@ g_get_prgname (void) * g_set_prgname: * @prgname: the name of the program. * - * Sets the name of the program. This name should not - * be localized, contrast with g_set_application_name(). Note that for - * thread-safety reasons this function can only be called once. + * Sets the name of the program. This name should not be localized, + * in contrast to g_set_application_name(). + * + * Note that for thread-safety reasons this function can only be called once. */ void g_set_prgname (const gchar *prgname) @@ -1143,7 +1075,7 @@ static gchar *g_application_name = NULL; * g_get_prgname() (which may be %NULL if g_set_prgname() has also not * been called). * - * Return value: human-readable application name. may return %NULL + * Returns: human-readable application name. may return %NULL * * Since: 2.2 **/ @@ -1202,17 +1134,17 @@ g_set_application_name (const gchar *application_name) * Returns a base directory in which to access application data such * as icons that is customized for a particular user. * - * On UNIX platforms this is determined using the mechanisms described in - * the - * XDG Base Directory Specification. - * In this case the directory retrieved will be XDG_DATA_HOME. + * On UNIX platforms this is determined using the mechanisms described + * in the + * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec). + * In this case the directory retrieved will be `XDG_DATA_HOME`. * * On Windows this is the folder to use for local (as opposed to * roaming) application data. See documentation for * CSIDL_LOCAL_APPDATA. Note that on Windows it thus is the same as * what g_get_user_config_dir() returns. * - * Return value: a string owned by GLib that must not be modified + * Returns: a string owned by GLib that must not be modified * or freed. * Since: 2.6 **/ @@ -1288,17 +1220,17 @@ g_init_user_config_dir (void) * Returns a base directory in which to store user-specific application * configuration information such as user preferences and settings. * - * On UNIX platforms this is determined using the mechanisms described in - * the - * XDG Base Directory Specification. - * In this case the directory retrieved will be XDG_CONFIG_HOME. + * On UNIX platforms this is determined using the mechanisms described + * in the + * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec). + * In this case the directory retrieved will be `XDG_CONFIG_HOME`. * * On Windows this is the folder to use for local (as opposed to * roaming) application data. See documentation for * CSIDL_LOCAL_APPDATA. Note that on Windows it thus is the same as * what g_get_user_data_dir() returns. * - * Return value: a string owned by GLib that must not be modified + * Returns: a string owned by GLib that must not be modified * or freed. * Since: 2.6 **/ @@ -1320,9 +1252,9 @@ g_get_user_config_dir (void) * Returns a base directory in which to store non-essential, cached * data specific to particular user. * - * On UNIX platforms this is determined using the mechanisms described in - * the - * XDG Base Directory Specification. + * On UNIX platforms this is determined using the mechanisms described + * in the + * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec). * In this case the directory retrieved will be XDG_CACHE_HOME. * * On Windows is the directory that serves as a common repository for @@ -1330,7 +1262,7 @@ g_get_user_config_dir (void) * C:\Documents and Settings\username\Local Settings\Temporary Internet Files. * See documentation for CSIDL_INTERNET_CACHE. * - * Return value: a string owned by GLib that must not be modified + * Returns: a string owned by GLib that must not be modified * or freed. * Since: 2.6 **/ @@ -1376,10 +1308,11 @@ g_get_user_cache_dir (void) * Returns a directory that is unique to the current user on the local * system. * - * On UNIX platforms this is determined using the mechanisms described in - * the - * XDG Base Directory Specification. This is the directory - * specified in the XDG_RUNTIME_DIR environment variable. + * On UNIX platforms this is determined using the mechanisms described + * in the + * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec). + * This is the directory + * specified in the `XDG_RUNTIME_DIR` environment variable. * In the case that this variable is not set, GLib will issue a warning * message to stderr and return the value of g_get_user_cache_dir(). * @@ -1541,7 +1474,6 @@ load_user_special_dirs (void) } #endif /* G_OS_WIN32 */ -static void g_init_user_config_dir (void); #if defined(G_OS_UNIX) && !defined(HAVE_CARBON) @@ -1763,16 +1695,16 @@ g_reload_user_special_dirs_cache (void) * * Returns the full path of a special directory using its logical id. * - * On Unix this is done using the XDG special user directories. + * On UNIX this is done using the XDG special user directories. * For compatibility with existing practise, %G_USER_DIRECTORY_DESKTOP - * falls back to $HOME/Desktop when XDG special - * user directories have not been set up. + * falls back to `$HOME/Desktop` when XDG special user directories have + * not been set up. * * Depending on the platform, the user might be able to change the path * of the special directory without requiring the session to restart; GLib * will not reflect any change once the special directories are loaded. * - * Return value: the path to the specified special directory, or %NULL + * Returns: the path to the specified special directory, or %NULL * if the logical id was not found. The returned string is owned by * GLib and should not be modified or freed. * @@ -1962,9 +1894,9 @@ g_win32_get_system_data_dirs_for_module (void (*address_of_function)(void)) * Returns an ordered list of base directories in which to access * system-wide application data. * - * On UNIX platforms this is determined using the mechanisms described in - * the - * XDG Base Directory Specification + * On UNIX platforms this is determined using the mechanisms described + * in the + * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec) * In this case the list of directories retrieved will be XDG_DATA_DIRS. * * On Windows the first elements in the list are the Application Data @@ -1989,7 +1921,7 @@ g_win32_get_system_data_dirs_for_module (void (*address_of_function)(void)) * Note that on Windows the returned list can vary depending on where * this function is called. * - * Return value: (array zero-terminated=1) (transfer none): a %NULL-terminated array of strings owned by GLib that must + * Returns: (array zero-terminated=1) (transfer none): a %NULL-terminated array of strings owned by GLib that must * not be modified or freed. * Since: 2.6 **/ @@ -2029,10 +1961,10 @@ g_get_system_data_dirs (void) * Returns an ordered list of base directories in which to access * system-wide configuration information. * - * On UNIX platforms this is determined using the mechanisms described in - * the - * XDG Base Directory Specification. - * In this case the list of directories retrieved will be XDG_CONFIG_DIRS. + * On UNIX platforms this is determined using the mechanisms described + * in the + * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec). + * In this case the list of directories retrieved will be `XDG_CONFIG_DIRS`. * * On Windows is the directory that contains application data for all users. * A typical path is C:\Documents and Settings\All Users\Application Data. @@ -2041,7 +1973,7 @@ g_get_system_data_dirs (void) * of clip art, or a log file in the CSIDL_COMMON_APPDATA folder. * This information will not roam and is available to anyone using the computer. * - * Return value: (array zero-terminated=1) (transfer none): a %NULL-terminated array of strings owned by GLib that must + * Returns: (array zero-terminated=1) (transfer none): a %NULL-terminated array of strings owned by GLib that must * not be modified or freed. * Since: 2.6 **/ @@ -2152,6 +2084,9 @@ g_format_size (guint64 size) * Flags to modify the format of the string returned by g_format_size_full(). */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" + /** * g_format_size_full: * @size: a size in bytes @@ -2285,6 +2220,8 @@ g_format_size_full (guint64 size, return g_string_free (string, FALSE); } +#pragma GCC diagnostic pop + /** * g_format_size_for_display: * @size: a size in bytes