]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Added implementation of strlcpy and strlcat for systems that dont have it
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 25 Mar 2005 19:25:41 +0000 (19:25 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 25 Mar 2005 19:25:41 +0000 (19:25 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@905 e03df62e-2008-0410-955e-edbf42e46eb7

18 files changed:
configure
include/inspstring.h [new file with mode: 0644]
src/Makefile
src/channels.cpp
src/commands.cpp
src/connection.cpp
src/dynamic.cpp
src/inspircd.cpp
src/inspircd_io.cpp
src/inspircd_util.cpp
src/inspstring.cpp [new file with mode: 0644]
src/message.cpp
src/mode.cpp
src/modules.cpp
src/servers.cpp
src/users.cpp
src/wildcard.cpp
src/xline.cpp

index 6f54c538698fe10f28636c94cc38c82742f1fc35..ecc48d7dc4c1a3c6ed525d495aa04843df7c9182 100755 (executable)
--- a/configure
+++ b/configure
@@ -100,6 +100,12 @@ exists () { # because some shells don't have test -e
     fi
 }
 
+echo "#include <string.h>">.test.cpp
+echo >"int main() { char a[10]; char b[10]; strlcpy(a,b,10); sprintf("999"); }" >>.test.cpp
+gcc -o .test .test.cpp
+$HAS_STRLCPY=`./.test`
+rm -f .test.cpp .test
+
 clear
 echo -e "'\033[1;33m####\033[0;37m:'\033[1;33m##\033[0;37m::: \033[1;33m##\033[0;37m::'\033[1;33m######\033[0;37m::'\033[1;33m########\033[0;37m::'\033[1;33m####\033[0;37m:'\033[1;33m########\033[0;37m:::'\033[1;33m######\033[0;37m::'\033[1;33m########\033[0;37m::"
 echo -e ". \033[1;33m##\033[0;37m:: \033[1;33m###\033[0;37m:: \033[1;33m##\033[0;37m:'\033[1;33m##\033[0;37m... \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m.... \033[1;33m##\033[0;37m:. \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m.... \033[1;33m##\033[0;37m:'\033[1;33m##\033[0;37m... \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m.... \033[1;33m##\033[0;37m:"
@@ -399,7 +405,7 @@ echo -e "\033[0;37mGCC Version Found:\033[1;32m\t\t$GCCVER.$GCC34"
 echo -e "\033[0;37mOptimatizaton Flag:\033[1;32m\t\t$OPTIMISATI"
 echo -e "\033[0;37m"
 
-echo "Writing cache file for future ./configures ..."
+yyecho "Writing cache file for future ./configures ..."
 
 if [ "$CONFIG_DIR" != "$ME/conf" ] ; then
     COPY_CONF=1
@@ -419,6 +425,7 @@ echo "MAXI_MODES=\"$MAXI_MODES\"" >> .config.cache
 echo "OPTIMITEMP=\"$OPTIMITEMP\"" >> .config.cache
 echo "OPTIMISATI=\"$OPTIMISATI\"" >> .config.cache
 echo "GCC34=\"$GCC34\"" >> .config.cache
+echo "HAS_STRLCPY=\"$HAS_STRLCPY\"" >> .config.cache
 echo "COPY_CONF=\"$COPY_CONF\"" >> .config.cache
 
 echo "Writing include/inspircd_config.h ..."
@@ -431,6 +438,9 @@ echo "#define GCC3" >>include/inspircd_config.h
                echo "#define GCC34" >>include/inspircd_config.h
        fi
 fi
+if [ "$HAS_STRLCPY" -eq "999" ] ; then
+       echo "#define HAS_STRLCPY" >>include/inspircd_config.h
+fi
 echo "#define SYSLOG_FACILITY LOG_DAEMON" >>include/inspircd_config.h
 echo "#define SYSLOG_LEVEL LOG_NOTICE" >>include/inspircd_config.h
 echo "#define CONFIG_FILE \"$CONFIG_DIR/inspircd.conf\"" >>include/inspircd_config.h
@@ -508,4 +518,3 @@ fi
 
 echo -e "*** \033[1;32mRemember to edit your configuration files!!!\033[0;37m ***"
 echo ""
-
diff --git a/include/inspstring.h b/include/inspstring.h
new file mode 100644 (file)
index 0000000..f13f098
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef __IN_INSPSTRING_H
+#define __IN_INSPSTRING_H
+
+#include "inspircd_config.h"
+
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char *dst, const char *src, size_t siz);
+size_t strlcat(char *dst, const char *src, size_t siz);
+#endif
+
+#endif
index 03c795c628caa3c5d51c1360cea1f699c4fe05e2..47b7c99bf17a9bbec7d0d33c7fb177647e166e74 100644 (file)
@@ -8,7 +8,7 @@
 CC = im a cheezeball
 
 SRC_1 = base.cpp inspircd.cpp inspircd_util.cpp inspircd_io.cpp connection.cpp message.cpp commands.cpp
-SRC_2 = dynamic.cpp users.cpp modules.cpp wildcard.cpp servers.cpp channels.cpp mode.cpp xline.cpp
+SRC_2 = dynamic.cpp users.cpp modules.cpp wildcard.cpp servers.cpp channels.cpp mode.cpp xline.cpp inspstring.cpp
 
 SRC = $(SRC_1) $(SRC_2)
 OBJS = $(SRC:.cpp=.o)
index 7cc6506f89918bc3eb8fb1c514c48aa1eb04eb56..379339c47c656c084cf9973b500d9ad51f51f4ee 100644 (file)
@@ -50,6 +50,7 @@
 #include "message.h"
 #include "mode.h"
 #include "xline.h"
+#include "inspstring.h"
 
 #ifdef GCC3
 #define nspace __gnu_cxx
index 0173f91130799cbd4e3153561983ae8fceddce66..dbb7a43a42d6f231c46144ff548623c39690e591 100644 (file)
@@ -50,6 +50,7 @@
 #include "message.h"
 #include "mode.h"
 #include "xline.h"
+#include "inspstring.h"
 
 #ifdef GCC3
 #define nspace __gnu_cxx
index d60da90aced4d9c08c77d8d5cef0e743be48a74c..475e9ade5356413104be21b89add2f45b4596527 100644 (file)
@@ -25,6 +25,7 @@
 #include <deque>
 #include "inspircd.h"
 #include "modules.h"
+#include "inspstring.h"
 
 using namespace std;
 
index c9742082047d07d93bd7229778294b101369bef9..9cc68fc5f3d36aa7a9169ca482e9eda102a16f33 100644 (file)
@@ -17,8 +17,7 @@
 #include "globals.h"
 #include <dlfcn.h>
 #include "dynamic.h"
-
-
+#include "inspstring.h"
 
 DLLManager::DLLManager(const char *fname)
 {
index ecfbd6b0fa0415eb4187b07798be3c43cd8efc7f..c39389f88cccdd6b6e62f9edd5cacd5442c21c30 100644 (file)
@@ -55,6 +55,7 @@ using namespace std;
 #include "mode.h"
 #include "commands.h"
 #include "xline.h"
+#include "inspstring.h"
 
 #ifdef GCC3
 #define nspace __gnu_cxx
index 2e9a350f11a24dbb696b5e1ba7e0851f2e820ad8..d412cee9320f22165a03c19c989090e63783ba99 100644 (file)
@@ -25,6 +25,7 @@
 #include "inspircd.h"
 #include "inspircd_io.h"
 #include "inspircd_util.h"
+#include "inspstring.h"
 
 using namespace std;
 
index a0a7e9f0f91a4ddd7804b8c40bfbd7697b261e95..fd1cc524995e94e388f01f31e18689e5e13b22ba 100644 (file)
@@ -17,6 +17,7 @@
 #include "inspircd.h" 
 #include "inspircd_io.h" 
 #include "inspircd_util.h" 
+#include "inspstring.h"
  
 char *SafeStrncpy (char *dest, const char *src, size_t size) 
 { 
diff --git a/src/inspstring.cpp b/src/inspstring.cpp
new file mode 100644 (file)
index 0000000..7b9624f
--- /dev/null
@@ -0,0 +1,89 @@
+#include "inspircd_config.h"
+#include "inspstring.h"
+
+/*
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright    
+ *    notice, this list of conditions and the following disclaimer in the  
+ *    documentation and/or other materials provided with the distribution. 
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef HAVE_STRLCPY
+size_t strlcat(char *dst, const char *src, size_t siz)
+{
+  char *d = dst;
+  const char *s = src;
+  size_t n = siz, dlen;
+
+  while (n-- != 0 && *d != '\0')
+    d++;
+
+  dlen = d - dst;
+  n    = siz - dlen;
+
+  if (n == 0)
+    return(dlen + strlen(s));
+
+  while (*s != '\0')
+  {
+    if (n != 1)
+    {
+      *d++ = *s;
+      n--;
+    }
+
+    s++;
+  }
+
+  *d = '\0';
+  return(dlen + (s - src)); /* count does not include NUL */
+}
+
+size_t strlcpy(char *dst, const char *src, size_t siz)
+{
+  char *d = dst;
+  const char *s = src;
+  size_t n = siz;
+
+  /* Copy as many bytes as will fit */
+  if (n != 0 && --n != 0)
+  {
+    do
+    {
+      if ((*d++ = *s++) == 0)
+        break;
+    } while (--n != 0);
+  }
+
+  /* Not enough room in dst, add NUL and traverse rest of src */
+  if (n == 0)
+  {
+    if (siz != 0)
+      *d = '\0'; /* NUL-terminate dst */
+    while (*s++)
+      ;
+  }
+
+  return(s - src - 1); /* count does not include NUL */
+}
+#endif
index bb27ceff4f8a14043fb83b8788af4dec6593b1e0..6c09096d24cc16a63cf27899ea5a40e5a1ccd33b 100644 (file)
@@ -48,6 +48,7 @@
 #include "dynamic.h"
 #include "wildcard.h"
 #include "message.h"
+#include "inspstring.h"
 
 using namespace std;
 
index d2a119895d7c85a42a44a7cee4ac4724ab8cb591..eaee04f75f23ab0ab5e5a631e31b481941a8c9c7 100644 (file)
@@ -50,6 +50,7 @@
 #include "message.h"
 #include "commands.h"
 #include "xline.h"
+#include "inspstring.h"
 
 using namespace std;
 
index 7f3603fb7ca1c0aaf1a6bd45e35b43382feecc75..ac47544c0c23525e44fed0734693d7f337150584 100644 (file)
@@ -51,6 +51,7 @@
 #include "mode.h"
 #include "xline.h"
 #include "commands.h"
+#include "inspstring.h"
 
 #ifdef GCC3
 #define nspace __gnu_cxx
index 5bf694183b1e647b101d9e89700066e6c7da770e..1ea20a5c21fd14befcceb91adf23dca30560b4aa 100644 (file)
@@ -19,6 +19,7 @@
 #include "inspircd.h"
 #include <stdio.h>
 #include <map>
+#include "inspstring.h"
 
 serverrec::serverrec()
 {
index b940bd6afc544268ec8e868ce5dde676b7cf8525..46dfb35d7219bc3713d4ca28443befef71293fb0 100644 (file)
@@ -19,6 +19,7 @@
 #include "users.h"
 #include "inspircd.h"
 #include <stdio.h>
+#include "inspstring.h"
 
 extern std::stringstream config_f;
 
index ce4d7d3147f549332dba73a512c837f5d2e6ab5d..8b4190539f9fb7a8287b7c0596e92cb0c9bd1bf7 100644 (file)
@@ -17,6 +17,7 @@
 #include <string>
 #include "inspircd_config.h"
 #include "inspircd.h"
+#include "inspstring.h"
 
 void Delete(char* str,int pos)
 {
index 5559390e73819c7442c4b259addc591ea6d08e05..15032b32a6a10621ef064159a27aab4f7f0dfeaf 100644 (file)
@@ -50,6 +50,7 @@
 #include "message.h"
 #include "commands.h"
 #include "xline.h"
+#include "inspstring.h"
 
 #ifdef GCC3
 #define nspace __gnu_cxx