updates.
[silc.git] / lib / silcutil / unix / silcunixutil.c
index 2dc40e142a62b8eff70a7a53baaf4edd483616ac..42b6edace41826d5857a2355067cc547d682899e 100644 (file)
@@ -2,7 +2,7 @@
 
   silcunixutil.c
 
-  Author: Pekka Riikonen <priikone@sillcnet.org>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
   Copyright (C) 1997 - 2001 Pekka Riikonen
 
@@ -53,6 +53,8 @@ char *silc_string_regexify(const char *string)
       regex[count] = '.';
       count++;
     } else if (string[i] == ',') {
+      if (i + 1 == len)
+       continue;
       regex[count] = '|';
       count++;
       continue;
@@ -62,7 +64,7 @@ char *silc_string_regexify(const char *string)
     count++;
   }
 
-  regex[count - 1] = ')';
+  regex[count++] = ')';
   regex[count] = '$';
 
   return regex;
@@ -114,6 +116,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);
@@ -135,17 +140,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. */
 
@@ -155,10 +158,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;
@@ -167,3 +168,10 @@ char *silc_get_real_name()
 
   return realname;
 }
+
+/* Return current time to struct timeval. */
+
+int silc_gettimeofday(struct timeval *p)
+{
+  return gettimeofday(p, NULL);
+}