New files, used to generate corresponding non-.in files when making a
[platform/upstream/glib.git] / gstrfuncs.c
index e154c56..f24fdcb 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-/* 
+/*
+ * Modified by the GLib Team and others 1997-1999.  See the AUTHORS
+ * file for a list of people on the GLib Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
+/*
  * MT safe
  */
 
@@ -31,6 +38,9 @@
 #include <string.h>
 #include <locale.h>
 #include <ctype.h>             /* For tolower() */
+#if !defined (HAVE_STRSIGNAL) || !defined(NO_SYS_SIGLIST_DECL)
+#include <signal.h>
+#endif
 #include "glib.h"
 /* do not include <unistd.h> in this place since it
  * inteferes with g_strsignal() on some OSes
@@ -40,7 +50,7 @@ gchar*
 g_strdup (const gchar *str)
 {
   gchar *new_str;
-  
+
   if (str)
     {
       new_str = g_new (char, strlen (str) + 1);
@@ -48,7 +58,7 @@ g_strdup (const gchar *str)
     }
   else
     new_str = NULL;
-  
+
   return new_str;
 }
 
@@ -141,9 +151,9 @@ g_strconcat (const gchar *string1, ...)
   va_list args;
   gchar          *s;
   gchar          *concat;
-  
+
   g_return_val_if_fail (string1 != NULL, NULL);
-  
+
   l = 1 + strlen (string1);
   va_start (args, string1);
   s = va_arg (args, gchar*);
@@ -153,10 +163,10 @@ g_strconcat (const gchar *string1, ...)
       s = va_arg (args, gchar*);
     }
   va_end (args);
-  
+
   concat = g_new (gchar, l);
   concat[0] = 0;
-  
+
   strcat (concat, string1);
   va_start (args, string1);
   s = va_arg (args, gchar*);
@@ -166,7 +176,7 @@ g_strconcat (const gchar *string1, ...)
       s = va_arg (args, gchar*);
     }
   va_end (args);
-  
+
   return concat;
 }
 
@@ -178,23 +188,23 @@ g_strtod (const gchar *nptr,
   gchar *fail_pos_2;
   gdouble val_1;
   gdouble val_2 = 0;
-  
+
   g_return_val_if_fail (nptr != NULL, 0);
-  
+
   fail_pos_1 = NULL;
   fail_pos_2 = NULL;
-  
+
   val_1 = strtod (nptr, &fail_pos_1);
-  
+
   if (fail_pos_1 && fail_pos_1[0] != 0)
     {
       gchar *old_locale;
-      
+
       old_locale = setlocale (LC_NUMERIC, "C");
       val_2 = strtod (nptr, &fail_pos_2);
       setlocale (LC_NUMERIC, old_locale);
     }
-  
+
   if (!fail_pos_1 || fail_pos_1[0] == 0 || fail_pos_1 >= fail_pos_2)
     {
       if (endptr)
@@ -212,9 +222,9 @@ g_strtod (const gchar *nptr,
 gchar*
 g_strerror (gint errnum)
 {
-  static GStaticPrivate msg_private = G_STATIC_PRIVATE_INIT; 
+  static GStaticPrivate msg_private = G_STATIC_PRIVATE_INIT;
   char *msg;
-  
+
 #ifdef HAVE_STRERROR
   return strerror (errnum);
 #elif NO_SYS_ERRLIST
@@ -635,28 +645,29 @@ g_strerror (gint errnum)
 #else /* NO_SYS_ERRLIST */
   extern int sys_nerr;
   extern char *sys_errlist[];
-  
+
   if ((errnum > 0) && (errnum <= sys_nerr))
     return sys_errlist [errnum];
 #endif /* NO_SYS_ERRLIST */
 
   msg = g_static_private_get (&msg_private);
-  if( !msg )
+  if (!msg)
     {
-      msg = g_new( gchar, 64 );
+      msg = g_new (gchar, 64);
       g_static_private_set (&msg_private, msg, g_free);
     }
 
   sprintf (msg, "unknown error (%d)", errnum);
+
   return msg;
 }
 
 gchar*
 g_strsignal (gint signum)
 {
-  static GStaticPrivate msg_private = G_STATIC_PRIVATE_INIT; 
+  static GStaticPrivate msg_private = G_STATIC_PRIVATE_INIT;
   char *msg;
-  
+
 #ifdef HAVE_STRSIGNAL
   extern char *strsignal (int sig);
   return strsignal (signum);
@@ -758,18 +769,23 @@ g_strsignal (gint signum)
 #endif
     }
 #else /* NO_SYS_SIGLIST */
-  extern char *sys_siglist[];
-  return sys_siglist [signum];
+
+#ifdef NO_SYS_SIGLIST_DECL
+  extern char *sys_siglist[];  /*(see Tue Jan 19 00:44:24 1999 in changelog)*/
+#endif
+
+  return (char*) /* this function should return const --josh */ sys_siglist [signum];
 #endif /* NO_SYS_SIGLIST */
 
   msg = g_static_private_get (&msg_private);
-  if( !msg )
+  if (!msg)
     {
-      msg = g_new( gchar, 64 );
+      msg = g_new (gchar, 64);
       g_static_private_set (&msg_private, msg, g_free);
     }
-  
+
   sprintf (msg, "unknown signal (%d)", signum);
+
   return msg;
 }
 
@@ -778,25 +794,25 @@ g_printf_string_upper_bound (const gchar* format,
                             va_list      args)
 {
   guint len = 1;
-  
+
   while (*format)
     {
       gboolean long_int = FALSE;
       gboolean extra_long = FALSE;
       gchar c;
-      
+
       c = *format++;
-      
+
       if (c == '%')
        {
          gboolean done = FALSE;
-         
+
          while (*format && !done)
            {
              switch (*format++)
                {
                  gchar *string_arg;
-                 
+
                case '*':
                  len += va_arg (args, int);
                  break;
@@ -906,7 +922,7 @@ g_printf_string_upper_bound (const gchar* format,
       else
        len += 1;
     }
-  
+
   return len;
 }
 
@@ -914,11 +930,11 @@ void
 g_strdown (gchar  *string)
 {
   register gchar *s;
-  
+
   g_return_if_fail (string != NULL);
-  
+
   s = string;
-  
+
   while (*s)
     {
       *s = tolower (*s);
@@ -930,11 +946,11 @@ void
 g_strup (gchar *string)
 {
   register gchar *s;
-  
+
   g_return_if_fail (string != NULL);
-  
+
   s = string;
-  
+
   while (*s)
     {
       *s = toupper (*s);
@@ -946,18 +962,18 @@ void
 g_strreverse (gchar      *string)
 {
   g_return_if_fail (string != NULL);
-  
+
   if (*string)
     {
       register gchar *h, *t;
-      
+
       h = string;
       t = string + strlen (string) - 1;
-      
+
       while (h < t)
        {
          register gchar c;
-         
+
          c = *h;
          *h = *t;
          h++;
@@ -975,7 +991,7 @@ g_strcasecmp (const gchar *s1,
   return strcasecmp (s1, s2);
 #else
   gint c1, c2;
-  
+
   g_return_val_if_fail (s1 != NULL, 0);
   g_return_val_if_fail (s2 != NULL, 0);
 
@@ -990,7 +1006,7 @@ g_strcasecmp (const gchar *s1,
        return (c1 - c2);
       s1++; s2++;
     }
-  
+
   return (((gint)(guchar) *s1) - ((gint)(guchar) *s2));
 #endif
 }
@@ -1004,7 +1020,7 @@ g_strncasecmp (const gchar *s1,
   return strncasecmp (s1, s2, n);
 #else
   gint c1, c2;
-  
+
   g_return_val_if_fail (s1 != NULL, 0);
   g_return_val_if_fail (s2 != NULL, 0);
 
@@ -1033,12 +1049,12 @@ g_strdelimit (gchar       *string,
              gchar        new_delim)
 {
   register gchar *c;
-  
+
   g_return_val_if_fail (string != NULL, NULL);
-  
+
   if (!delimiters)
     delimiters = G_STR_DELIMITERS;
-  
+
   for (c = string; *c; c++)
     {
       if (strchr (delimiters, *c))
@@ -1131,12 +1147,12 @@ g_strsplit (const gchar *string,
   if (s)
     {
       guint delimiter_len = strlen (delimiter);
-      
+
       do
        {
          guint len;
          gchar *new_string;
-         
+
          len = s - string;
          new_string = g_new (gchar, len + 1);
          strncpy (new_string, string, len);
@@ -1153,7 +1169,7 @@ g_strsplit (const gchar *string,
       n++;
       string_list = g_slist_prepend (string_list, g_strdup (string));
     }
-  
+
   str_array = g_new (gchar*, n);
 
   i = n - 1;
@@ -1186,7 +1202,7 @@ g_strjoinv (const gchar  *separator,
            gchar       **str_array)
 {
   gchar *string;
-  
+
   g_return_val_if_fail (str_array != NULL, NULL);
 
   if(separator == NULL)
@@ -1201,7 +1217,7 @@ g_strjoinv (const gchar  *separator,
       len = 1 + strlen (str_array[0]);
       for(i = 1; str_array[i] != NULL; i++)
        len += separator_len + strlen(str_array[i]);
-      
+
       string = g_new (gchar, len);
       *string = 0;
       strcat (string, *str_array);