From 88bf1f4d2397a18a9983013a390261e5a2b45959 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sat, 16 Aug 2003 08:55:33 +0000 Subject: [PATCH] silc_gets to MT safe. --- lib/silcutil/silcutil.c | 26 +++++++++++++------------- lib/silcutil/silcutil.h | 11 ++++++----- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/silcutil/silcutil.c b/lib/silcutil/silcutil.c index 8c906489..e903eb9f 100644 --- a/lib/silcutil/silcutil.c +++ b/lib/silcutil/silcutil.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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 @@ -28,22 +28,20 @@ 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) || diff --git a/lib/silcutil/silcutil.h b/lib/silcutil/silcutil.h index 57c5b1db..2d569528 100644 --- a/lib/silcutil/silcutil.h +++ b/lib/silcutil/silcutil.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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 -- 2.24.0