[hackers] [sbase] Add strlcpy()/strlcat() || sin

From: <git_AT_suckless.org>
Date: Thu, 30 Jan 2014 15:55:10 +0100

commit fb12183c5284ded7277d4af5b686826be4d99852
Author: sin <sin_AT_2f30.org>
Date: Thu Jan 30 12:37:35 2014 +0000

    Add strlcpy()/strlcat()
    
    Refactor recurse() routine in preparation to moving tar(1) over
    to use it instead of the ftw() interface.

diff --git a/Makefile b/Makefile
index 9fada0f..204e05c 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -22,7 +22,9 @@ LIB = \
         util/rm.o \
         util/sha1.o \
         util/sha256.o \
- util/sha512.o
+ util/sha512.o \
+ util/strlcat.o \
+ util/strlcpy.o
 
 SRC = \
         basename.c \
diff --git a/util.h b/util.h
index f7e8780..4856bb3 100644
--- a/util.h
+++ b/util.h
_AT_@ -1,5 +1,5 @@
 /* See LICENSE file for copyright and license details. */
-
+#include <stddef.h>
 #include "arg.h"
 
 #define UTF8_POINT(c) (((c) & 0xc0) != 0x80)
_AT_@ -20,4 +20,6 @@ long estrtol(const char *, int);
 void fnck(const char *, const char *, int (*)(const char *, const char *));
 void putword(const char *);
 void recurse(const char *, void (*)(const char *));
+size_t strlcat(char *, const char *, size_t);
+size_t strlcpy(char *, const char *, size_t);
 void weprintf(const char *, ...);
diff --git a/util/recurse.c b/util/recurse.c
index b3d1f8c..6ac235e 100644
--- a/util/recurse.c
+++ b/util/recurse.c
_AT_@ -1,17 +1,19 @@
 /* See LICENSE file for copyright and license details. */
 #include <dirent.h>
-#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #include "../util.h"
 
 void
 recurse(const char *path, void (*fn)(const char *))
 {
- char *cwd;
+ char buf[PATH_MAX], *p;
         struct dirent *d;
         struct stat st;
         DIR *dp;
_AT_@ -22,19 +24,19 @@ recurse(const char *path, void (*fn)(const char *))
                 eprintf("opendir %s:", path);
         }
 
- cwd = agetcwd();
- if(chdir(path) == -1)
- eprintf("chdir %s:", path);
-
         while((d = readdir(dp))) {
- if(strcmp(d->d_name, ".") && strcmp(d->d_name, ".."))
- fn(d->d_name);
+ if (strcmp(d->d_name, ".") == 0 ||
+ strcmp(d->d_name, "..") == 0)
+ continue;
+ strlcpy(buf, path, sizeof(buf));
+ p = strrchr(buf, '
Received on Thu Jan 30 2014 - 15:55:10 CET

This archive was generated by hypermail 2.3.0 : Thu Jan 30 2014 - 16:00:10 CET