silc_gets to MT safe.
authorPekka Riikonen <priikone@silcnet.org>
Sat, 16 Aug 2003 08:55:33 +0000 (08:55 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sat, 16 Aug 2003 08:55:33 +0000 (08:55 +0000)
lib/silcutil/silcutil.c
lib/silcutil/silcutil.h

index 8c9064891527f6199d346681f9d3a38cf3cb0d53..e903eb9f8f3b46916de66bbddeb72f850c57e5ba 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2002 Pekka Riikonen
+  Copyright (C) 1997 - 2003 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
    This doesn't remove the newline sign from the destination buffer. The
    argument begin is returned and should be passed again for the function. */
 
-int silc_gets(char *dest, int destlen, const char *src, int srclen, int begin)
+int silc_gets(char *dest, int destlen, const char *src, int srclen,
+             int *begin)
 {
-  static int start = 0;
+  int off = *begin;
   int i;
 
   memset(dest, 0, destlen);
 
-  if (begin != start)
-    start = 0;
-
   i = 0;
-  for ( ; start <= srclen; i++, start++) {
+  for ( ; off <= srclen; i++) {
     if (i > destlen)
       return -1;
 
-    dest[i] = src[start];
+    dest[i] = src[off++];
 
     if (dest[i] == EOF)
       return EOF;
@@ -51,9 +49,11 @@ int silc_gets(char *dest, int destlen, const char *src, int srclen, int begin)
     if (dest[i] == '\n')
       break;
   }
-  start++;
+  *begin = off;
+  if (off + 1 >= srclen)
+    return EOF;
 
-  return start;
+  return off;
 }
 
 /* Checks line for illegal characters. Return -1 when illegal character
@@ -657,10 +657,10 @@ char *silc_client_chmode(SilcUInt32 mode, const char *cipher, const char *hmac)
 
   if (mode & SILC_CHANNEL_MODE_SILENCE_OPERS)
     strncat(string, "M", 1);
-  
+
   if (mode & SILC_CHANNEL_MODE_CIPHER)
     strncat(string, "c", 1);
-  
+
   if (mode & SILC_CHANNEL_MODE_HMAC)
     strncat(string, "h", 1);
 
@@ -1155,7 +1155,7 @@ const char *silc_get_command_name(unsigned char command)
 
 /* Return TRUE if `smaller' is smaller than `bigger'. */
 
-bool silc_compare_timeval(struct timeval *smaller, 
+bool silc_compare_timeval(struct timeval *smaller,
                          struct timeval *bigger)
 {
   if ((smaller->tv_sec < bigger->tv_sec) ||
index 57c5b1db9434d3013ab603097fa1dfbafd241995..2d569528d376b6884418e41f42aaf8f9fd56cea0 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2002 Pekka Riikonen
+  Copyright (C) 1997 - 2003 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
@@ -33,7 +33,7 @@
  * SYNOPSIS
  *
  *    int silc_gets(char *dest, int destlen, const char *src, int srclen,
- *                  int begin);
+ *                  int *begin);
  *
  * DESCRIPTION
  *
@@ -42,7 +42,8 @@
  *    argument begin is returned and should be passed again for the function.
  *
  ***/
-int silc_gets(char *dest, int destlen, const char *src, int srclen, int begin);
+int silc_gets(char *dest, int destlen, const char *src, int srclen,
+             int *begin);
 
 /****f* silcutil/SilcUtilAPI/silc_check_line
  *
@@ -482,7 +483,7 @@ int silc_gettimeofday(struct timeval *p);
  *
  * SYNOPSIS
  *
- *    bool silc_compare_timeval(struct timeval *smaller, 
+ *    bool silc_compare_timeval(struct timeval *smaller,
  *                              struct timeval *bigger)
  *
  * DESCRIPTION
@@ -491,7 +492,7 @@ int silc_gettimeofday(struct timeval *p);
  *    time value is smaller than the second time value.
  *
  ***/
-bool silc_compare_timeval(struct timeval *smaller, 
+bool silc_compare_timeval(struct timeval *smaller,
                          struct timeval *bigger);
 
 /****f* silcutil/SilcUtilAPI/silc_string_regexify