* safestrncpy counts the copied string anyway, and nobody needs the returned pointer
authorWilfried Göesgens <willi@citadel.org>
Wed, 27 Feb 2008 23:06:49 +0000 (23:06 +0000)
committerWilfried Göesgens <willi@citadel.org>
Wed, 27 Feb 2008 23:06:49 +0000 (23:06 +0000)
 -> return a long
 -> return the number of copied bytes.
 -> return negative values if we hit the boundary.

libcitadel/debian/files
libcitadel/lib/libcitadel.h
libcitadel/lib/tools.c

index 525ce5997072491f2e33e54cf19921dc72318ed7..86dbb72dd2aae3746a5b15c5149f140ca27b5e44 100644 (file)
@@ -1,3 +1,3 @@
-libcitadel1_1.05-4_i386.deb libs optional
-libcitadel1-dbg_1.05-4_i386.deb libdevel optional
-libcitadel-dev_1.05-4_i386.deb libdevel optional
+libcitadel1_1.06-7_i386.deb libs optional
+libcitadel1-dbg_1.06-7_i386.deb libdevel optional
+libcitadel-dev_1.06-7_i386.deb libdevel optional
index 7dac9e97146dfbe2c577bde3c0c86ccb29334e06..5d80409505835388f0c31fe0785e8a891cb999d1 100644 (file)
@@ -188,7 +188,7 @@ void ShutDownLibCitadel(void);
 
 
 
-char *safestrncpy(char *dest, const char *src, size_t n);
+int safestrncpy(char *dest, const char *src, size_t n);
 int num_tokens (const char *source, char tok);
 long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
 long grab_token(char **dest, const char *source, int parmnum, char separator);
index 17981796e041b619c4969d33539668e74bac632d..c056fe94d8ea4a4b1ecf50c81dfac15a77c79ddc 100644 (file)
@@ -73,8 +73,14 @@ const byte dtable[256] = {
        128, 128, 0
 };
 
-
-char *safestrncpy(char *dest, const char *src, size_t n)
+/**
+ * \brief copy a string into a buffer of a known size. abort if we exceed the limits
+ * \param dest the targetbuffer
+ * \param src the source string
+ * \param n the size od dest
+ * \returns the number of characters copied if dest is big enough, -n if not.
+ */
+int safestrncpy(char *dest, const char *src, size_t n)
 {
        int i = 0;
 
@@ -85,11 +91,11 @@ char *safestrncpy(char *dest, const char *src, size_t n)
 
        do {
                dest[i] = src[i];
-               if (dest[i] == 0) return(dest);
+               if (dest[i] == 0) return i;
                ++i;
        } while (i<n);
        dest[n - 1] = 0;
-       return dest;
+       return -i;
 }