]> err.no Git - util-linux/commitdiff
lib: [strutils] general purpose string handling functions
authorDavidlohr Bueso <dave@gnu.org>
Tue, 16 Nov 2010 13:47:35 +0000 (10:47 -0300)
committerKarel Zak <kzak@redhat.com>
Tue, 23 Nov 2010 20:06:49 +0000 (21:06 +0100)
This patch replaces a few functions used throughout the source:
* Renames getnum (from schedutils) to strtol_or_err
* Moves strtosize (from lib/strtosize.c)
* Moves xstrncpy (from include/xstrncpy.h)
* Adds strnlen, strnchr and strndup if not available (remove it from libmount utils)

A few Makefile.am files were modified to compile accordingly along with trivial renaming
in schedutils source code.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
35 files changed:
disk-utils/mkswap.c
disk-utils/swaplabel.c
fdisk/cfdisk.c
include/Makefile.am
include/strtosize.h [deleted file]
include/strutils.h [new file with mode: 0644]
include/xstrncpy.h [deleted file]
lib/Makefile.am
lib/strutils.c [moved from lib/strtosize.c with 64% similarity]
login-utils/agetty.c
login-utils/checktty.c
login-utils/chfn.c
login-utils/login.c
login-utils/shutdown.c
login-utils/simpleinit.c
login-utils/vipw.c
login-utils/wall.c
misc-utils/Makefile.am
misc-utils/blkid.c
misc-utils/wipefs.c
mount/Makefile.am
mount/lomount.c
mount/mount.c
mount/umount.c
schedutils/Makefile.am
schedutils/chrt.c
schedutils/ionice.c
schedutils/schedutils.c [deleted file]
schedutils/schedutils.h [deleted file]
schedutils/taskset.c
shlibs/mount/src/mountP.h
shlibs/mount/src/utils.c
sys-utils/Makefile.am
sys-utils/fallocate.c
text-utils/more.c

index 246b8dd7fd61beb26d717bf398a54d4870fa0363..3d14a42e5e9580135d476854b08192481061bb7e 100644 (file)
@@ -48,7 +48,7 @@
 
 #include "linux_version.h"
 #include "swapheader.h"
-#include "xstrncpy.h"
+#include "strutils.h"
 #include "nls.h"
 #include "blkdev.h"
 #include "pathnames.h"
index 634197226554842176d32084e10779a32c7f8da7..9dc20b49e887361e7f53a7a9e3f4680a0cd45ac1 100644 (file)
@@ -33,7 +33,7 @@
 #include "c.h"
 #include "writeall.h"
 #include "swapheader.h"
-#include "xstrncpy.h"
+#include "strutils.h"
 #include "nls.h"
 
 #define SWAP_UUID_OFFSET       (offsetof(struct swap_header_v1_2, uuid))
index 149a616657af289c6ee0b68bb2da4d4be62ae59c..1e078a9fe515b7e70345a49c6200fad8a7d10a9a 100644 (file)
@@ -99,7 +99,7 @@
 
 #include "nls.h"
 #include "blkdev.h"
-#include "xstrncpy.h"
+#include "strutils.h"
 #include "common.h"
 #include "gpt.h"
 #include "mbsalign.h"
index 3b93acd071a3222975a0853c2ec536678e692830..c7b3c20df6ed79c20e16b36051462c1407f2df1c 100644 (file)
@@ -20,11 +20,10 @@ dist_noinst_HEADERS = \
        nls.h \
        pathnames.h \
        setproctitle.h \
-       strtosize.h \
+       strutils.h \
        swapheader.h \
        tt.h \
        usleep.h \
        wholedisk.h \
        widechar.h \
-       writeall.h \
-       xstrncpy.h
+       writeall.h
diff --git a/include/strtosize.h b/include/strtosize.h
deleted file mode 100644 (file)
index c789df9..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef UTIL_LINUX_STRTOSIZE
-#define UTIL_LINUX_STRTOSIZE
-
-#include <inttypes.h>
-
-extern int strtosize(const char *str, uintmax_t *res);
-
-#endif /* UTIL_LINUX_STRING_TO_NUMBE */
diff --git a/include/strutils.h b/include/strutils.h
new file mode 100644 (file)
index 0000000..e24496d
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef UTIL_LINUX_STRUTILS
+#define UTIL_LINUX_STRUTILS
+
+#include <inttypes.h>
+#include <string.h>
+
+extern int strtosize(const char *str, uintmax_t *res);
+extern long strtol_or_err(const char *str, const char *errmesg);
+
+#ifndef HAVE_STRNLEN
+extern size_t strnlen(const char *s, size_t maxlen);
+#endif
+#ifndef HAVE_STRNDUP
+extern char *strndup(const char *s, size_t n);
+#endif
+#ifndef HAVE_STRNCHR
+extern char *strnchr(const char *s, size_t maxlen, int c);
+#endif
+
+/* caller guarantees n > 0 */
+static inline void xstrncpy(char *dest, const char *src, size_t n)
+{
+       strncpy(dest, src, n-1);
+       dest[n-1] = 0;
+}
+#endif
diff --git a/include/xstrncpy.h b/include/xstrncpy.h
deleted file mode 100644 (file)
index 7ed4109..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-/* NUL-terminated version of strncpy() */
-#include <string.h>
-
-/* caller guarantees n > 0 */
-static inline void xstrncpy(char *dest, const char *src, size_t n) {
-       strncpy(dest, src, n-1);
-       dest[n-1] = 0;
-}
index 45d319d34a1008ff75143d917fb4d0543a1c4e47..9a3bf35bdfa5fb1fcba9d8ff8e73f70c0d79c961 100644 (file)
@@ -3,7 +3,7 @@ include $(top_srcdir)/config/include-Makefile.am
 AM_CPPFLAGS += -DTEST_PROGRAM
 
 noinst_PROGRAMS = test_blkdev test_ismounted test_wholedisk test_mangle \
-                 test_strtosize test_tt test_canonicalize
+                 test_tt test_canonicalize
 if LINUX
 if HAVE_CPU_SET_T
 noinst_PROGRAMS += test_cpuset
@@ -14,7 +14,6 @@ test_blkdev_SOURCES = blkdev.c
 test_ismounted_SOURCES = ismounted.c
 test_wholedisk_SOURCES = wholedisk.c
 test_mangle_SOURCES = mangle.c
-test_strtosize_SOURCES = strtosize.c
 if LINUX
 test_cpuset_SOURCES = cpuset.c
 endif
similarity index 64%
rename from lib/strtosize.c
rename to lib/strutils.c
index 068c5429ad00acfc7e5f2d377a136c09d9f4e88d..f394800de943816e4914fef3dc8018d39986900d 100644 (file)
@@ -1,3 +1,24 @@
+/*
+ * Copyright (C) 2010 Karel Zak <kzak@redhat.com>
+ * Copyright (C) 2010 Davidlohr Bueso <dave@gnu.org>
+ */
+
+#include <stdlib.h>
+#include <inttypes.h>
+#include <ctype.h>
+#include <errno.h>
+#include <err.h>
+
+static int do_scale_by_power (uintmax_t *x, int base, int power)
+{
+       while (power--) {
+               if (UINTMAX_MAX / base < *x)
+                       return -2;
+               *x *= base;
+       }
+       return 0;
+}
+
 /*
  * strtosize() - convert string to size (uintmax_t).
  *
  *
  * Note that the function does not accept numbers with '-' (negative sign)
  * prefix.
- *
- * Returns 0 on success, -1 in case of error, -2 in case of overflow.
- *
- * Copyright (C) 2010 Karel Zak <kzak@redhat.com>
  */
-#include <stdio.h>
-#include <inttypes.h>
-#include <ctype.h>
-#include <errno.h>
-
-static int do_scale_by_power (uintmax_t *x, int base, int power)
-{
-       while (power--) {
-               if (UINTMAX_MAX / base < *x)
-                       return -2;
-               *x *= base;
-       }
-       return 0;
-}
-
 int strtosize(const char *str, uintmax_t *res)
 {
        char *p;
@@ -123,26 +125,62 @@ err:
        return -1;
 }
 
-#ifdef TEST_PROGRAM
+#ifndef HAVE_STRNLEN
+size_t strnlen(const char *s, size_t maxlen)
+{
+        int i;
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <err.h>
+        for (i = 0; i < maxlen; i++) {
+                if (s[i] == '\0')
+                        return i + 1;
+        }
+        return maxlen;
+}
+#endif
 
-int main(int argc, char *argv[])
+#ifndef HAVE_STRNCHR
+char *strnchr(const char *s, size_t maxlen, int c)
 {
-       uintmax_t size = 0;
+       for (; maxlen-- && *s != '\0'; ++s)
+               if (*s == (char)c)
+                       return (char *)s;
+       return NULL;
+}
+#endif
 
-       if (argc < 2) {
-               fprintf(stderr, "usage: %s <number>[suffix]\n", argv[0]);
-               exit(EXIT_FAILURE);
-       }
+#ifndef HAVE_STRNDUP
+char *strndup(const char *s, size_t n)
+{
+       size_t len = strnlen(s, n);
+       char *new = (char *) malloc((len + 1) * sizeof(char));
+       if (!new)
+               return NULL;
+       new[len] = '\0';
+       return (char *) memcpy(new, s, len);
+}
+#endif
 
-       if (strtosize(argv[1], &size))
-               errx(EXIT_FAILURE, "invalid size '%s' value", argv[1]);
+/*
+ * same as strtol(3) but exit on failure instead of returning crap
+ */
+long strtol_or_err(const char *str, const char *errmesg)
+{
+       long num;
+       char *end = NULL;
 
-       printf("%25s : %20ju\n", argv[1], size);
-       return EXIT_FAILURE;
-}
-#endif /* TEST_PROGRAM */
+       if (str == NULL || *str == '\0')
+               goto err;
+       errno = 0;
+       num = strtol(str, &end, 10);
 
+       if (errno || (end && *end))
+               goto err;
+
+       return num;
+err:
+       if (errno)
+               err(EXIT_FAILURE, "%s: '%s'", errmesg, str);
+       else
+               errx(EXIT_FAILURE, "%s: '%s'", errmesg, str);
+       return 0;
+}
index f048c3e48a2fd2efc1768820db27373615812bbf..b1cfa5a53cf03ce8938a4342ab292d24991c15f5 100644 (file)
@@ -32,7 +32,7 @@
 #include <sys/socket.h>
 #include <netdb.h>
 
-#include "xstrncpy.h"
+#include "strutils.h"
 #include "nls.h"
 #include "pathnames.h"
 
index c28ee833da1010f0baf0551171afe94605240cf3..92bebfb735b88ececf5a4af6894544c2c9d1faf0 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "pathnames.h"
 #include "login.h"
-#include "xstrncpy.h"
+#include "strutils.h"
 
 #ifndef TTY_MAJOR
 #define TTY_MAJOR 4
index 691c4f6f51126be891dc0a0ca5d5e8da8cb22e5d..ef0a746d5cf36dd847531f8f4e67452361a7e67a 100644 (file)
@@ -36,7 +36,7 @@
 #include "my_crypt.h"
 #include "islocal.h"
 #include "setpwnam.h"
-#include "xstrncpy.h"
+#include "strutils.h"
 #include "nls.h"
 #include "env.h"
 
index 1550388c4574207857ae6843041eeff3cba52d39..68eb84bc1d88b32d4e3a6f1e914e6ccfce864678 100644 (file)
 #include "pathnames.h"
 #include "my_crypt.h"
 #include "login.h"
-#include "xstrncpy.h"
+#include "strutils.h"
 #include "nls.h"
 
 
index 0078df2d646db3d1dfe5f9cada7cd77363e92ae8..172113c76ea2c8531a37ec9fb968d6e0a2a9982d 100644 (file)
@@ -74,7 +74,7 @@
 #include <sys/utsname.h>
 #include "linux_reboot.h"
 #include "pathnames.h"
-#include "xstrncpy.h"
+#include "strutils.h"
 #include "nls.h"
 #include "usleep.h"
 
index 8cff848cf653dd38e3da628f8513e0ca1582eac7..9277a3cc47eae5ebc4d64de67df595d7832b264e 100644 (file)
@@ -45,7 +45,7 @@
 #include "my_crypt.h"
 #include "pathnames.h"
 #include "linux_reboot.h"
-#include "xstrncpy.h"
+#include "strutils.h"
 #include "nls.h"
 #include "simpleinit.h"
 
index b3972f3b31136e96cba93ea907849fe02cd7c99a..e7247e42c86cd9812e6f1fa75d960d59b9f2b2e0 100644 (file)
@@ -64,7 +64,7 @@ static char version_string[] = "vipw 1.4";
 #include <unistd.h>
 
 #include "setpwnam.h"
-#include "xstrncpy.h"
+#include "strutils.h"
 #include "nls.h"
 
 #ifdef HAVE_LIBSELINUX
index 7b5f6718f196e5d3890beb099f539f779560b94a..38c544266eb63567b33f024bff98d8b508fbacac 100644 (file)
@@ -58,7 +58,7 @@
 #include <utmp.h>
 
 #include "nls.h"
-#include "xstrncpy.h"
+#include "strutils.h"
 #include "ttymsg.h"
 #include "pathnames.h"
 #include "carefulputc.h"
index aed8bac8d9771eee2a1f077a440a61c7b84d2ad6..76b69fa4a295d45048e89e52dc73cb948bc4e23c 100644 (file)
@@ -37,12 +37,12 @@ if BUILD_LIBBLKID
 sbin_PROGRAMS += blkid findfs wipefs
 dist_man_MANS += blkid.8 findfs.8 wipefs.8
 blkid_SOURCES = blkid.c $(top_srcdir)/lib/ismounted.c \
-               $(top_srcdir)/lib/strtosize.c
+               $(top_srcdir)/lib/strutils.c
 blkid_LDADD = $(ul_libblkid_la)
 blkid_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
 findfs_LDADD = $(ul_libblkid_la)
 findfs_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
-wipefs_SOURCES = wipefs.c $(top_srcdir)/lib/strtosize.c
+wipefs_SOURCES = wipefs.c $(top_srcdir)/lib/strutils.c
 wipefs_LDADD = $(ul_libblkid_la)
 wipefs_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
 if HAVE_STATIC_BLKID
index f94df06a1b2534436fe3155013f0339f09def8c5..2f7860fd230bab5dece0e68566ecea714c8f43a5 100644 (file)
@@ -41,7 +41,7 @@ extern int optind;
 #include <blkid.h>
 
 #include "ismounted.h"
-#include "strtosize.h"
+#include "strutils.h"
 
 const char *progname = "blkid";
 
index dbfabc4a16c0c0a682585e3cbf605b83f1faada7..2f223f0c23ddbd5e31a7b450bce2b8352e38b6b6 100644 (file)
@@ -35,7 +35,7 @@
 
 #include "nls.h"
 #include "xalloc.h"
-#include "strtosize.h"
+#include "strutils.h"
 
 struct wipe_desc {
        loff_t          offset;         /* magic string offset */
index 235cceb06e4de9d89b172d1282866d9afcc1754f..36b06e327952f4e418ae7b88106c71e78df3671e 100644 (file)
@@ -28,12 +28,12 @@ cflags_common = $(AM_CFLAGS)
 ldflags_static = -all-static
 
 mount_SOURCES = mount.c $(srcs_mount) $(top_srcdir)/lib/setproctitle.c \
-               $(top_srcdir)/lib/strtosize.c
+               $(top_srcdir)/lib/strutils.c
 mount_CFLAGS = $(SUID_CFLAGS) $(cflags_common)
 mount_LDFLAGS = $(SUID_LDFLAGS) $(AM_LDFLAGS)
 mount_LDADD = $(ldadd_common)
 
-umount_SOURCES = umount.c $(srcs_mount) $(top_srcdir)/lib/strtosize.c
+umount_SOURCES = umount.c $(srcs_mount) $(top_srcdir)/lib/strutils.c
 umount_CFLAGS = $(SUID_CFLAGS) $(cflags_common)
 umount_LDFLAGS = $(SUID_LDFLAGS) $(AM_LDFLAGS)
 umount_LDADD = $(ldadd_common)
@@ -45,7 +45,7 @@ swapon_CFLAGS = $(cflags_common)
 swapon_LDADD = $(ldadd_common)
 
 losetup_SOURCES = lomount.c $(srcs_common) loop.h lomount.h \
-               $(top_srcdir)/lib/strtosize.c
+               $(top_srcdir)/lib/strutils.c
 losetup_CPPFLAGS = -DMAIN $(AM_CPPFLAGS)
 
 mount_static_LDADD =
index 03aae4b2aa4539af0fb0164ac9081ac488767132..d6556fc71d1e10c8d5e1c665f85cbbda32c60120 100644 (file)
@@ -18,7 +18,7 @@
 
 #include "loop.h"
 #include "lomount.h"
-#include "xstrncpy.h"
+#include "strutils.h"
 #include "nls.h"
 #include "sundries.h"
 #include "xmalloc.h"
@@ -886,7 +886,7 @@ find_unused_loop_device (void) {
 #include <getopt.h>
 #include <stdarg.h>
 
-#include "strtosize.h"
+#include "strutils.h"
 
 static void
 usage(FILE *f) {
index c0023f3947b837aa1e9ec4eb1b1ec567142db3e3..9faa6a5b6fa67b1a72b993434aef9a44b7ddfe8b 100644 (file)
@@ -41,7 +41,7 @@
 #include "env.h"
 #include "nls.h"
 #include "blkdev.h"
-#include "strtosize.h"
+#include "strutils.h"
 
 #define DO_PS_FIDDLING
 
index b5ff8a17706b4fe02c2d1cc0552f5260649c5e27..6e24779b452cf3535de9b4a5a5b5a7b836ad9a4c 100644 (file)
@@ -20,7 +20,7 @@
 #include "fstab.h"
 #include "env.h"
 #include "nls.h"
-#include "strtosize.h"
+#include "strutils.h"
 
 #if defined(MNT_FORCE)
 /* Interesting ... it seems libc knows about MNT_FORCE and presumably
index c83e5eaff733386e642a83591f961b8d0383910f..dc33175376f688611b8432a70a5344ff9479e2da 100644 (file)
@@ -2,7 +2,7 @@ include $(top_srcdir)/config/include-Makefile.am
 
 if BUILD_SCHEDUTILS
 
-srcs_common = schedutils.c schedutils.h
+srcs_common = $(top_srcdir)/lib/strutils.c
 
 usrbin_exec_PROGRAMS = chrt
 dist_man_MANS = chrt.1
index 811eb200e0f0dee3899d3fd03e9235ffc9132b41..bd7070cca589714ac9c87dec96336b843abc797d 100644 (file)
@@ -32,7 +32,7 @@
 #include "c.h"
 #include "nls.h"
 
-#include "schedutils.h"
+#include "strutils.h"
 
 /* the SCHED_BATCH is supported since Linux 2.6.16
  *  -- temporary workaround for people with old glibc headers
@@ -240,7 +240,7 @@ int main(int argc, char *argv[])
                        break;
                case 'p':
                        errno = 0;
-                       pid = getnum(argv[argc - 1], _("failed to parse pid"));
+                       pid = strtol_or_err(argv[argc - 1], _("failed to parse pid"));
                        break;
                case 'r':
                        policy = SCHED_RR;
@@ -268,7 +268,7 @@ int main(int argc, char *argv[])
        }
 
        errno = 0;
-       priority = getnum(argv[optind], _("failed to parse priority"));
+       priority = strtol_or_err(argv[optind], _("failed to parse priority"));
 
 #ifdef SCHED_RESET_ON_FORK
        /* sanity check */
index 34132f071da5bf4211a8e9b11ddb73425dabd046..78c9f0d3ca7c35a4a26d0dbaa85f992e8e86334f 100644 (file)
@@ -18,7 +18,7 @@
 
 #include "nls.h"
 
-#include "schedutils.h"
+#include "strutils.h"
 
 static int tolerant;
 
@@ -105,15 +105,15 @@ int main(int argc, char *argv[])
        while ((c = getopt(argc, argv, "+n:c:p:th")) != EOF) {
                switch (c) {
                case 'n':
-                       ioprio = getnum(optarg, _("failed to parse class data"));
+                       ioprio = strtol_or_err(optarg, _("failed to parse class data"));
                        set |= 1;
                        break;
                case 'c':
-                       ioclass = getnum(optarg, _("failed to parse class"));
+                       ioclass = strtol_or_err(optarg, _("failed to parse class"));
                        set |= 2;
                        break;
                case 'p':
-                       pid = getnum(optarg, _("failed to parse pid"));
+                       pid = strtol_or_err(optarg, _("failed to parse pid"));
                        break;
                case 't':
                        tolerant = 1;
@@ -147,7 +147,7 @@ int main(int argc, char *argv[])
                ioprio_print(pid);
 
                for(; argv[optind]; ++optind) {
-                       pid = getnum(argv[optind], _("failed to parse pid"));
+                       pid = strtol_or_err(argv[optind], _("failed to parse pid"));
                        ioprio_print(pid);
                }
        } else {
@@ -156,7 +156,7 @@ int main(int argc, char *argv[])
 
                        for(; argv[optind]; ++optind)
                        {
-                               pid = getnum(argv[optind], _("failed to parse pid"));
+                               pid = strtol_or_err(argv[optind], _("failed to parse pid"));
                                ioprio_setpid(pid, ioprio, ioclass);
                        }
                }
diff --git a/schedutils/schedutils.c b/schedutils/schedutils.c
deleted file mode 100644 (file)
index 9d6051b..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2010 Karel Zak <kzak@redhat.com>
- *
- * Released under the terms of the GNU General Public License version 2
- *
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <err.h>
-
-#include "nls.h"
-
-long getnum(const char *str, const char *errmesg)
-{
-       long num;
-       char *end = NULL;
-
-       if (str == NULL || *str == '\0')
-               goto err;
-       errno = 0;
-       num = strtol(str, &end, 10);
-
-       if (errno || (end && *end))
-               goto err;
-
-       return num;
-err:
-       if (errno)
-               err(EXIT_FAILURE, "%s: '%s'", errmesg, str);
-       else
-               errx(EXIT_FAILURE, "%s: '%s'", errmesg, str);
-       return 0;
-}
diff --git a/schedutils/schedutils.h b/schedutils/schedutils.h
deleted file mode 100644 (file)
index 80e4f7b..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef UTIL_LINUX_SCHED_UTILS
-#define UTIL_LINUX_SCHED_UTILS
-
-extern long getnum(const char *str, const char *errmesg);
-
-#endif
-
index 201fc1589f2387c0af721715470e8bdd40d44600..5a7557c3a0bcc5a7ec42bfd047bdfc10a7a98eac 100644 (file)
@@ -32,7 +32,7 @@
 #include "cpuset.h"
 #include "nls.h"
 
-#include "schedutils.h"
+#include "strutils.h"
 
 static void __attribute__((__noreturn__)) usage(FILE *out)
 {
@@ -89,7 +89,7 @@ int main(int argc, char *argv[])
        while ((opt = getopt_long(argc, argv, "+pchV", longopts, NULL)) != -1) {
                switch (opt) {
                case 'p':
-                       pid = getnum(argv[argc - 1], _("failed to parse pid"));
+                       pid = strtol_or_err(argv[argc - 1], _("failed to parse pid"));
                        break;
                case 'c':
                        c_opt = 1;
index 6145b730fc62a285f283ddcebc92978efca3cf05..4a99bb4e632aefd60631d7e27c774895eb3c8b80 100644 (file)
@@ -60,15 +60,6 @@ extern int mnt_run_test(struct mtest *tests, int argc, char *argv[]);
 
 /* utils.c */
 extern char *mnt_getenv_safe(const char *arg);
-#ifndef HAVE_STRNLEN
-extern size_t strnlen(const char *s, size_t maxlen);
-#endif
-#ifndef HAVE_STRNDUP
-extern char *strndup(const char *s, size_t n);
-#endif
-#ifndef HAVE_STRNCHR
-extern char *strnchr(const char *s, size_t maxlen, int c);
-#endif
 extern char *mnt_get_username(const uid_t uid);
 
 /*
index 6133cdd772e5d89a4ec41fc776af004d3d020854..a1ab50c08381f01a52fd05ee077085c22e6b837a 100644 (file)
@@ -51,45 +51,6 @@ char *mnt_getenv_safe(const char *arg)
 #endif
 }
 
-/* TODO: move strn<...> functions to top-level lib/strn.c */
-#ifndef HAVE_STRNLEN
-size_t strnlen(const char *s, size_t maxlen)
-{
-       int i;
-
-       for (i = 0; i < maxlen; i++) {
-               if (s[i] == '\0')
-                       return i + 1;
-       }
-       return maxlen;
-}
-#endif
-
-#ifndef HAVE_STRNCHR
-char *strnchr(const char *s, size_t maxlen, int c)
-{
-       for (; maxlen-- && *s != '\0'; ++s)
-               if (*s == (char)c)
-                       return (char *)s;
-       return NULL;
-}
-#endif
-
-#ifndef HAVE_STRNDUP
-char *strndup(const char *s, size_t n)
-{
-  size_t len = strnlen (s, n);
-  char *new = (char *) malloc (len + 1);
-
-  if (new == NULL)
-    return NULL;
-
-  new[len] = '\0';
-  return (char *) memcpy (new, s, len);
-}
-#endif
-
-
 /**
  * mnt_fstype_is_pseudofs:
  * @type: filesystem name
index d2b85685f872435a3f6afb04f229d67ae5de5f5c..a45978e35bd1f657ac7f5f11aae26876a27cc0f9 100644 (file)
@@ -31,7 +31,7 @@ tunelp_SOURCES = tunelp.c lp.h
 
 if BUILD_FALLOCATE
 usrbin_exec_PROGRAMS += fallocate
-fallocate_SOURCES = fallocate.c $(top_srcdir)/lib/strtosize.c
+fallocate_SOURCES = fallocate.c $(top_srcdir)/lib/strutils.c
 dist_man_MANS += fallocate.1
 endif
 
index fd4d2a9addbb5f38b16eeea6016089df6acc5623..9598cf109b613223e0065260e9b54f21b0d57f34 100644 (file)
@@ -44,7 +44,7 @@
 #endif
 
 #include "nls.h"
-#include "strtosize.h"
+#include "strutils.h"
 
 
 static void __attribute__((__noreturn__)) usage(FILE *out)
index 37520598497defb1502cf8cc7803b59b39ba6fe1..49df52e25ba9ed90315512efdf73512099a5d716 100644 (file)
@@ -56,7 +56,7 @@
 #include <sys/stat.h>
 #include <sys/file.h>
 #include <sys/wait.h>
-#include "xstrncpy.h"
+#include "strutils.h"
 
 #include "nls.h"
 #include "xalloc.h"