summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-03-25 19:25:41 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-03-25 19:25:41 +0000
commit9f1bd74b09810565502451047b06b6eca7e47f7f (patch)
treea82551e9129f988c83fb55a2d5357340ae30ee22 /src
parentad75aac62374e74a9829dc2f43939f4f8148a0f4 (diff)
Added implementation of strlcpy and strlcat for systems that dont have it
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@905 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/Makefile2
-rw-r--r--src/channels.cpp1
-rw-r--r--src/commands.cpp1
-rw-r--r--src/connection.cpp1
-rw-r--r--src/dynamic.cpp3
-rw-r--r--src/inspircd.cpp1
-rw-r--r--src/inspircd_io.cpp1
-rw-r--r--src/inspircd_util.cpp1
-rw-r--r--src/inspstring.cpp89
-rw-r--r--src/message.cpp1
-rw-r--r--src/mode.cpp1
-rw-r--r--src/modules.cpp1
-rw-r--r--src/servers.cpp1
-rw-r--r--src/users.cpp1
-rw-r--r--src/wildcard.cpp1
-rw-r--r--src/xline.cpp1
16 files changed, 104 insertions, 3 deletions
diff --git a/src/Makefile b/src/Makefile
index 03c795c62..47b7c99bf 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -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)
diff --git a/src/channels.cpp b/src/channels.cpp
index 7cc6506f8..379339c47 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -50,6 +50,7 @@
#include "message.h"
#include "mode.h"
#include "xline.h"
+#include "inspstring.h"
#ifdef GCC3
#define nspace __gnu_cxx
diff --git a/src/commands.cpp b/src/commands.cpp
index 0173f9113..dbb7a43a4 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -50,6 +50,7 @@
#include "message.h"
#include "mode.h"
#include "xline.h"
+#include "inspstring.h"
#ifdef GCC3
#define nspace __gnu_cxx
diff --git a/src/connection.cpp b/src/connection.cpp
index d60da90ac..475e9ade5 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -25,6 +25,7 @@
#include <deque>
#include "inspircd.h"
#include "modules.h"
+#include "inspstring.h"
using namespace std;
diff --git a/src/dynamic.cpp b/src/dynamic.cpp
index c97420820..9cc68fc5f 100644
--- a/src/dynamic.cpp
+++ b/src/dynamic.cpp
@@ -17,8 +17,7 @@
#include "globals.h"
#include <dlfcn.h>
#include "dynamic.h"
-
-
+#include "inspstring.h"
DLLManager::DLLManager(const char *fname)
{
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index ecfbd6b0f..c39389f88 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -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
diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp
index 2e9a350f1..d412cee93 100644
--- a/src/inspircd_io.cpp
+++ b/src/inspircd_io.cpp
@@ -25,6 +25,7 @@
#include "inspircd.h"
#include "inspircd_io.h"
#include "inspircd_util.h"
+#include "inspstring.h"
using namespace std;
diff --git a/src/inspircd_util.cpp b/src/inspircd_util.cpp
index a0a7e9f0f..fd1cc5249 100644
--- a/src/inspircd_util.cpp
+++ b/src/inspircd_util.cpp
@@ -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
index 000000000..7b9624fcf
--- /dev/null
+++ b/src/inspstring.cpp
@@ -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
diff --git a/src/message.cpp b/src/message.cpp
index bb27ceff4..6c09096d2 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -48,6 +48,7 @@
#include "dynamic.h"
#include "wildcard.h"
#include "message.h"
+#include "inspstring.h"
using namespace std;
diff --git a/src/mode.cpp b/src/mode.cpp
index d2a119895..eaee04f75 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -50,6 +50,7 @@
#include "message.h"
#include "commands.h"
#include "xline.h"
+#include "inspstring.h"
using namespace std;
diff --git a/src/modules.cpp b/src/modules.cpp
index 7f3603fb7..ac47544c0 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -51,6 +51,7 @@
#include "mode.h"
#include "xline.h"
#include "commands.h"
+#include "inspstring.h"
#ifdef GCC3
#define nspace __gnu_cxx
diff --git a/src/servers.cpp b/src/servers.cpp
index 5bf694183..1ea20a5c2 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -19,6 +19,7 @@
#include "inspircd.h"
#include <stdio.h>
#include <map>
+#include "inspstring.h"
serverrec::serverrec()
{
diff --git a/src/users.cpp b/src/users.cpp
index b940bd6af..46dfb35d7 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -19,6 +19,7 @@
#include "users.h"
#include "inspircd.h"
#include <stdio.h>
+#include "inspstring.h"
extern std::stringstream config_f;
diff --git a/src/wildcard.cpp b/src/wildcard.cpp
index ce4d7d314..8b4190539 100644
--- a/src/wildcard.cpp
+++ b/src/wildcard.cpp
@@ -17,6 +17,7 @@
#include <string>
#include "inspircd_config.h"
#include "inspircd.h"
+#include "inspstring.h"
void Delete(char* str,int pos)
{
diff --git a/src/xline.cpp b/src/xline.cpp
index 5559390e7..15032b32a 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -50,6 +50,7 @@
#include "message.h"
#include "commands.h"
#include "xline.h"
+#include "inspstring.h"
#ifdef GCC3
#define nspace __gnu_cxx