Merged silc_1_0_branch to trunk.
[silc.git] / lib / silcutil / unix / silcunixutil.c
index 3dddce37eb49bb17088b03f24b6819204d6d924b..75a6adcabf7c262471f89179e6fdd20d99dc8f3e 100644 (file)
@@ -4,12 +4,11 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2001 Pekka Riikonen
+  Copyright (C) 1997 - 2005 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
+  the Free Software Foundation; version 2 of the License.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -38,30 +37,32 @@ char *silc_string_regexify(const char *string)
 
   len = strlen(string);
   count = 4;
-  for (i = 0; i < len; i++)
+  for (i = 0; i < len; i++) {
     if (string[i] == '*' || string[i] == '?')
-      count++;
+      count++;                 /* Will add '.' */
+    if (string[i] == ',')
+      count += 2;              /* Will add '|' and '^' */
+  }
 
-  regex = silc_calloc(len + count, sizeof(*regex));
+  regex = silc_calloc(len + count + 1, sizeof(*regex));
 
   count = 0;
-  regex[count] = '(';
-  count++;
+  regex[count++] = '(';
+  regex[count++] = '^';
 
   for (i = 0; i < len; i++) {
     if (string[i] == '*' || string[i] == '?') {
       regex[count] = '.';
       count++;
     } else if (string[i] == ',') {
-      if (i + 1 == len)
+      if (i + 2 == len)
        continue;
-      regex[count] = '|';
-      count++;
+      regex[count++] = '|';
+      regex[count++] = '^';
       continue;
     }
 
-    regex[count] = string[i];
-    count++;
+    regex[count++] = string[i];
   }
 
   regex[count++] = ')';
@@ -116,6 +117,9 @@ int silc_string_match(const char *string1, const char *string2)
   char *s1;
   int ret = FALSE;
 
+  if (!string1 || !string2)
+    return ret;
+
   s1 = silc_string_regexify(string1);
   ret = silc_string_regex_match(s1, string2);
   silc_free(s1);
@@ -137,17 +141,15 @@ char *silc_get_username()
       struct passwd *pw;
 
       pw = getpwuid(getuid());
-      if (!pw) {
-       fprintf(stderr, "silc_get_username: %s\n", strerror(errno));
-       return NULL;
-      }
-      
+      if (!pw)
+       return strdup("foo");
+
       logname = pw->pw_name;
     }
   }
   
   return strdup(logname);
-}                          
+}
 
 /* Returns the real name of ther user. */
 
@@ -157,10 +159,8 @@ char *silc_get_real_name()
   struct passwd *pw;
     
   pw = getpwuid(getuid());
-  if (!pw) {
-    fprintf(stderr, "silc_get_username: %s\n", strerror(errno));
-    return NULL;
-  }
+  if (!pw)
+     return strdup("Foo T. Bar");
 
   if (strchr(pw->pw_gecos, ','))
     *strchr(pw->pw_gecos, ',') = 0;