diff options
Diffstat (limited to 'glib/gstrfuncs.c')
-rw-r--r-- | glib/gstrfuncs.c | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index 21ec0b578..391cf569b 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -352,12 +352,12 @@ get_C_locale (void) * Returns: a newly-allocated copy of @str */ gchar* -g_strdup (const gchar *str) +(g_strdup) (const gchar *str) { gchar *new_str; gsize length; - if (str) + if G_LIKELY (str) { length = strlen (str) + 1; new_str = g_new (char, length); @@ -495,12 +495,12 @@ g_strnfill (gsize length, * @dest: destination buffer. * @src: source string. * - * Copies a nul-terminated string into the dest buffer, include the - * trailing nul, and return a pointer to the trailing nul byte. - * This is useful for concatenating multiple strings together - * without having to repeatedly scan for the end. + * Copies a nul-terminated string into the destination buffer, including + * the trailing nul byte, and returns a pointer to the trailing nul byte + * in `dest`. The return value is useful for concatenating multiple + * strings without having to repeatedly scan for the end. * - * Returns: a pointer to trailing nul byte. + * Returns: a pointer to the trailing nul byte in `dest`. **/ gchar * g_stpcpy (gchar *dest, @@ -1313,7 +1313,7 @@ g_ascii_strtoll (const gchar *nptr, * ]| * * Returns: a UTF-8 string describing the error code. If the error code - * is unknown, it returns a string like "unknown error (<code>)". + * is unknown, it returns a string like "Unknown error: <code>". */ const gchar * g_strerror (gint errnum) @@ -1336,6 +1336,9 @@ g_strerror (gint errnum) { gchar buf[1024]; GError *error = NULL; +#if defined(HAVE_STRERROR_R) && !defined(STRERROR_R_CHAR_P) + int ret; +#endif #if defined(G_OS_WIN32) strerror_s (buf, sizeof (buf), errnum); @@ -1345,18 +1348,31 @@ g_strerror (gint errnum) # if defined(STRERROR_R_CHAR_P) msg = strerror_r (errnum, buf, sizeof (buf)); # else - (void) strerror_r (errnum, buf, sizeof (buf)); - msg = buf; + ret = strerror_r (errnum, buf, sizeof (buf)); + if (ret == 0 || ret == EINVAL) + msg = buf; # endif /* HAVE_STRERROR_R */ #else g_strlcpy (buf, strerror (errnum), sizeof (buf)); msg = buf; #endif + + if (!msg) + { + G_UNLOCK (errors); + + errno = saved_errno; + return NULL; + } + if (!g_get_console_charset (NULL)) { msg = g_locale_to_utf8 (msg, -1, NULL, NULL, &error); if (error) - g_print ("%s\n", error->message); + { + g_print ("%s\n", error->message); + g_error_free (error); + } } else if (msg == (const gchar *)buf) msg = g_strdup (buf); @@ -2412,9 +2428,15 @@ g_strsplit (const gchar *string, g_return_val_if_fail (delimiter[0] != '\0', NULL); if (max_tokens < 1) - max_tokens = G_MAXINT; + { + max_tokens = G_MAXINT; + string_list = g_ptr_array_new (); + } + else + { + string_list = g_ptr_array_new_full (max_tokens + 1, NULL); + } - string_list = g_ptr_array_new (); remainder = string; s = strstr (remainder, delimiter); if (s) @@ -2746,7 +2768,7 @@ g_strjoin (const gchar *separator, * * Searches the string @haystack for the first occurrence * of the string @needle, limiting the length of the search - * to @haystack_len. + * to @haystack_len or a nul terminator byte (whichever is reached first). * * Returns: a pointer to the found occurrence, or * %NULL if not found. @@ -2909,9 +2931,8 @@ g_strrstr_len (const gchar *haystack, * * Since: 2.2 */ -gboolean -g_str_has_suffix (const gchar *str, - const gchar *suffix) +gboolean (g_str_has_suffix) (const gchar *str, + const gchar *suffix) { gsize str_len; gsize suffix_len; @@ -2939,9 +2960,8 @@ g_str_has_suffix (const gchar *str, * * Since: 2.2 */ -gboolean -g_str_has_prefix (const gchar *str, - const gchar *prefix) +gboolean (g_str_has_prefix) (const gchar *str, + const gchar *prefix) { g_return_val_if_fail (str != NULL, FALSE); g_return_val_if_fail (prefix != NULL, FALSE); |