gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r829 - in GNUnet: . src/include src/util


From: durner
Subject: [GNUnet-SVN] r829 - in GNUnet: . src/include src/util
Date: Mon, 30 May 2005 12:40:29 -0700 (PDT)

Author: durner
Date: 2005-05-30 12:40:10 -0700 (Mon, 30 May 2005)
New Revision: 829

Added:
   GNUnet/src/util/string.c
Modified:
   GNUnet/configure.ac
   GNUnet/src/include/gnunet_util.h
   GNUnet/src/util/Makefile.am
Log:
strlcpy & strlcat (taken from the Linux kernel)

Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2005-05-29 10:47:47 UTC (rev 828)
+++ GNUnet/configure.ac 2005-05-30 19:40:10 UTC (rev 829)
@@ -384,7 +384,7 @@
 AC_HEADER_SYS_WAIT
 AC_TYPE_OFF_T
 AC_TYPE_UID_T
-AC_CHECK_FUNCS([floor gethostname memmove rmdir strncasecmp strrchr strtol 
atoll dup2 fdatasync ftruncate gethostbyname gettimeofday memset mkdir mkfifo 
select socket strcasecmp strchr strdup strerror strstr clock_gettime getrusage 
rand uname setlocale getcwd mktime gmtime_r gmtime])
+AC_CHECK_FUNCS([floor gethostname memmove rmdir strncasecmp strrchr strtol 
atoll dup2 fdatasync ftruncate gethostbyname gettimeofday memset mkdir mkfifo 
select socket strcasecmp strchr strdup strerror strstr clock_gettime getrusage 
rand uname setlocale getcwd mktime gmtime_r gmtime strlcpy strlcat])
 
 # restore LIBS
 LIBS=$SAVE_LIBS

Modified: GNUnet/src/include/gnunet_util.h
===================================================================
--- GNUnet/src/include/gnunet_util.h    2005-05-29 10:47:47 UTC (rev 828)
+++ GNUnet/src/include/gnunet_util.h    2005-05-30 19:40:10 UTC (rev 829)
@@ -2307,6 +2307,16 @@
 int fileopen(const char *filename, int oflag, ...);
 
 /**
+ * String functions
+ */
+#if !HAVE_STRLCPY
+size_t strlcpy(char *dest, const char *src, size_t size);
+#endif
+#if !HAVE_STRLCAT
+size_t strlcat(char *dest, const char *src, size_t count);
+#endif
+
+/**
  * Helper functions
  */
 #ifdef WINDOWS

Modified: GNUnet/src/util/Makefile.am
===================================================================
--- GNUnet/src/util/Makefile.am 2005-05-29 10:47:47 UTC (rev 828)
+++ GNUnet/src/util/Makefile.am 2005-05-30 19:40:10 UTC (rev 829)
@@ -78,6 +78,7 @@
  state.c \
  statuscalls.c \
  storage.c \
+ string.c \
  symcipher_gcrypt.c \
  tcp_return.c \
  tcpio.c \

Added: GNUnet/src/util/string.c
===================================================================
--- GNUnet/src/util/string.c    2005-05-29 10:47:47 UTC (rev 828)
+++ GNUnet/src/util/string.c    2005-05-30 19:40:10 UTC (rev 829)
@@ -0,0 +1,83 @@
+/*
+     This file is part of GNUnet.
+     (C) 2005 Christian Grothoff (and other contributing authors)
+
+     GNUnet 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, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file util/string.c
+ * @brief string functions
+ * @author Nils Durner
+ */
+
+#include "gnunet_util.h"
+#include "platform.h"
+
+#if !HAVE_STRLCPY
+/**
+ * @brief Copy a %NUL terminated string into a sized buffer
+ * @author Linus Torvalds
+ * @param dest Where to copy the string to
+ * @param src Where to copy the string from
+ * @param size size of destination buffer
+ * @remarks Compatible with *BSD: the result is always a valid
+ *          NUL-terminated string that fits in the buffer (unless,
+ *          of course, the buffer size is zero). It does not pad
+ *          out the result like strncpy() does.
+ */
+size_t strlcpy(char *dest, const char *src, size_t size)
+{
+       size_t ret = strlen(src);
+
+       if (size) {
+               size_t len = (ret >= size) ? size-1 : ret;
+               memcpy(dest, src, len);
+               dest[len] = '\0';
+       }
+       return ret;
+}
+#endif
+
+#if !HAVE_STRLCAT
+/**
+ * @brief Append a length-limited, %NUL-terminated string to another
+ * @author Linus Torvalds
+ * @param dest The string to be appended to
+ * @param src The string to append to it
+ * @param count The size of the destination buffer.
+ */
+size_t strlcat(char *dest, const char *src, size_t count)
+{
+       size_t dsize = strlen(dest);
+       size_t len = strlen(src);
+       size_t res = dsize + len;
+
+       /* This would be a bug */
+       if(dsize >= count)
+               return 0;
+
+       dest += dsize;
+       count -= dsize;
+       if (len >= count)
+               len = count-1;
+       memcpy(dest, src, len);
+       dest[len] = 0;
+       return res;
+}
+#endif
+
+/* end of string.c */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]