util.c: move strlcat and strlcpy into a separate "util.c" object
authorJeff Layton <jlayton@redhat.com>
Sun, 7 Feb 2010 21:23:23 +0000 (16:23 -0500)
committerJeff Layton <jlayton@redhat.com>
Sun, 7 Feb 2010 21:23:23 +0000 (16:23 -0500)
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Makefile.am
mount.cifs.c
util.c [new file with mode: 0644]
util.h [new file with mode: 0644]

index 648758e8162579765efc87186e9be0a0d3a9b670..31acef80985dcaf77e54209643501da06a2032d4 100644 (file)
@@ -1,7 +1,7 @@
 root_sbindir = "/sbin"
 root_sbin_PROGRAMS = mount.cifs
-mount_cifs_SOURCES = mount.cifs.c mtab.c
+mount_cifs_SOURCES = mount.cifs.c mtab.c util.c
 
 sbin_PROGRAMS = cifs.upcall
-cifs_upcall_SOURCES = cifs.upcall.c data_blob.c asn1.c spnego.c
+cifs_upcall_SOURCES = cifs.upcall.c data_blob.c asn1.c spnego.c util.c
 cifs_upcall_LDADD = -ltalloc -lkrb5
index d307f4f012037c0e02cdf77bac51e120253bc5fc..b1e84799b9871daebf7619166bfb357398f5ce10 100644 (file)
@@ -41,6 +41,7 @@
 #include <limits.h>
 #include <fstab.h>
 #include "mount.h"
+#include "util.h"
 
 #define MOUNT_CIFS_VERSION_MAJOR "1"
 #define MOUNT_CIFS_VERSION_MINOR "14"
@@ -134,50 +135,6 @@ char * domain_name = NULL;
 char * prefixpath = NULL;
 const char *cifs_fstype = "cifs";
 
-/* glibc doesn't have strlcpy, strlcat. Ensure we do. JRA. We
- * don't link to libreplace so need them here. */
-
-/* like strncpy but does not 0 fill the buffer and always null
- *    terminates. bufsize is the size of the destination buffer */
-
-#ifndef HAVE_STRLCPY
-static size_t strlcpy(char *d, const char *s, size_t bufsize)
-{
-       size_t len = strlen(s);
-       size_t ret = len;
-       if (bufsize <= 0) return 0;
-       if (len >= bufsize) len = bufsize-1;
-       memcpy(d, s, len);
-       d[len] = 0;
-       return ret;
-}
-#endif
-
-/* like strncat but does not 0 fill the buffer and always null
- *    terminates. bufsize is the length of the buffer, which should
- *       be one more than the maximum resulting string length */
-
-#ifndef HAVE_STRLCAT
-static size_t strlcat(char *d, const char *s, size_t bufsize)
-{
-       size_t len1 = strlen(d);
-       size_t len2 = strlen(s);
-       size_t ret = len1 + len2;
-
-       if (len1+len2 >= bufsize) {
-               if (bufsize < (len1+1)) {
-                       return ret;
-               }
-               len2 = bufsize - (len1+1);
-       }
-       if (len2 > 0) {
-               memcpy(d+len1, s, len2);
-               d[len1+len2] = 0;
-       }
-       return ret;
-}
-#endif
-
 /*
  * If an unprivileged user is doing the mounting then we need to ensure
  * that the entry is in /etc/fstab.
diff --git a/util.c b/util.c
new file mode 100644 (file)
index 0000000..00e0cc5
--- /dev/null
+++ b/util.c
@@ -0,0 +1,47 @@
+#include <sys/types.h>
+#include <string.h>
+
+/* glibc doesn't have strlcpy, strlcat. Ensure we do. JRA. We
+ * don't link to libreplace so need them here. */
+
+/* like strncpy but does not 0 fill the buffer and always null
+ *    terminates. bufsize is the size of the destination buffer */
+
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char *d, const char *s, size_t bufsize)
+{
+       size_t len = strlen(s);
+       size_t ret = len;
+       if (bufsize <= 0) return 0;
+       if (len >= bufsize) len = bufsize-1;
+       memcpy(d, s, len);
+       d[len] = 0;
+       return ret;
+}
+#endif
+
+/* like strncat but does not 0 fill the buffer and always null
+ *    terminates. bufsize is the length of the buffer, which should
+ *       be one more than the maximum resulting string length */
+
+#ifndef HAVE_STRLCAT
+size_t strlcat(char *d, const char *s, size_t bufsize)
+{
+       size_t len1 = strlen(d);
+       size_t len2 = strlen(s);
+       size_t ret = len1 + len2;
+
+       if (len1+len2 >= bufsize) {
+               if (bufsize < (len1+1)) {
+                       return ret;
+               }
+               len2 = bufsize - (len1+1);
+       }
+       if (len2 > 0) {
+               memcpy(d+len1, s, len2);
+               d[len1+len2] = 0;
+       }
+       return ret;
+}
+#endif
+
diff --git a/util.h b/util.h
new file mode 100644 (file)
index 0000000..2a227f6
--- /dev/null
+++ b/util.h
@@ -0,0 +1,8 @@
+#ifndef _LIBUTIL_H
+#define _LIBUTIL_H
+
+size_t strlcpy(char *d, const char *s, size_t bufsize);
+size_t strlcat(char *d, const char *s, size_t bufsize);
+
+#endif /* _LIBUTIL_H */
+