From 8abcf2900297c6d53ead867c42f7c1688e8d52ca Mon Sep 17 00:00:00 2001 From: Davidlohr Bueso Date: Tue, 16 Nov 2010 10:47:35 -0300 Subject: [PATCH] lib: [strutils] general purpose string handling functions 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 --- disk-utils/mkswap.c | 2 +- disk-utils/swaplabel.c | 2 +- fdisk/cfdisk.c | 2 +- include/Makefile.am | 5 +- include/strtosize.h | 8 --- include/strutils.h | 26 ++++++++ include/xstrncpy.h | 8 --- lib/Makefile.am | 3 +- lib/{strtosize.c => strutils.c} | 108 +++++++++++++++++++++----------- login-utils/agetty.c | 2 +- login-utils/checktty.c | 2 +- login-utils/chfn.c | 2 +- login-utils/login.c | 2 +- login-utils/shutdown.c | 2 +- login-utils/simpleinit.c | 2 +- login-utils/vipw.c | 2 +- login-utils/wall.c | 2 +- misc-utils/Makefile.am | 4 +- misc-utils/blkid.c | 2 +- misc-utils/wipefs.c | 2 +- mount/Makefile.am | 6 +- mount/lomount.c | 4 +- mount/mount.c | 2 +- mount/umount.c | 2 +- schedutils/Makefile.am | 2 +- schedutils/chrt.c | 6 +- schedutils/ionice.c | 12 ++-- schedutils/schedutils.c | 34 ---------- schedutils/schedutils.h | 7 --- schedutils/taskset.c | 4 +- shlibs/mount/src/mountP.h | 9 --- shlibs/mount/src/utils.c | 39 ------------ sys-utils/Makefile.am | 2 +- sys-utils/fallocate.c | 2 +- text-utils/more.c | 2 +- 35 files changed, 139 insertions(+), 182 deletions(-) delete mode 100644 include/strtosize.h create mode 100644 include/strutils.h delete mode 100644 include/xstrncpy.h rename lib/{strtosize.c => strutils.c} (64%) delete mode 100644 schedutils/schedutils.c delete mode 100644 schedutils/schedutils.h diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index 246b8dd7fd..3d14a42e5e 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -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" diff --git a/disk-utils/swaplabel.c b/disk-utils/swaplabel.c index 6341972265..9dc20b49e8 100644 --- a/disk-utils/swaplabel.c +++ b/disk-utils/swaplabel.c @@ -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)) diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c index 149a616657..1e078a9fe5 100644 --- a/fdisk/cfdisk.c +++ b/fdisk/cfdisk.c @@ -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" diff --git a/include/Makefile.am b/include/Makefile.am index 3b93acd071..c7b3c20df6 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -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 index c789df93d2..0000000000 --- a/include/strtosize.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef UTIL_LINUX_STRTOSIZE -#define UTIL_LINUX_STRTOSIZE - -#include - -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 index 0000000000..e24496d3c2 --- /dev/null +++ b/include/strutils.h @@ -0,0 +1,26 @@ +#ifndef UTIL_LINUX_STRUTILS +#define UTIL_LINUX_STRUTILS + +#include +#include + +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 index 7ed4109d67..0000000000 --- a/include/xstrncpy.h +++ /dev/null @@ -1,8 +0,0 @@ -/* NUL-terminated version of strncpy() */ -#include - -/* 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; -} diff --git a/lib/Makefile.am b/lib/Makefile.am index 45d319d34a..9a3bf35bdf 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -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 diff --git a/lib/strtosize.c b/lib/strutils.c similarity index 64% rename from lib/strtosize.c rename to lib/strutils.c index 068c5429ad..f394800de9 100644 --- a/lib/strtosize.c +++ b/lib/strutils.c @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2010 Karel Zak + * Copyright (C) 2010 Davidlohr Bueso + */ + +#include +#include +#include +#include +#include + +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). * @@ -17,26 +38,7 @@ * * 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 */ -#include -#include -#include -#include - -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 -#include -#include + 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 [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; +} diff --git a/login-utils/agetty.c b/login-utils/agetty.c index f048c3e48a..b1cfa5a53c 100644 --- a/login-utils/agetty.c +++ b/login-utils/agetty.c @@ -32,7 +32,7 @@ #include #include -#include "xstrncpy.h" +#include "strutils.h" #include "nls.h" #include "pathnames.h" diff --git a/login-utils/checktty.c b/login-utils/checktty.c index c28ee833da..92bebfb735 100644 --- a/login-utils/checktty.c +++ b/login-utils/checktty.c @@ -31,7 +31,7 @@ #include "pathnames.h" #include "login.h" -#include "xstrncpy.h" +#include "strutils.h" #ifndef TTY_MAJOR #define TTY_MAJOR 4 diff --git a/login-utils/chfn.c b/login-utils/chfn.c index 691c4f6f51..ef0a746d5c 100644 --- a/login-utils/chfn.c +++ b/login-utils/chfn.c @@ -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" diff --git a/login-utils/login.c b/login-utils/login.c index 1550388c45..68eb84bc1d 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -113,7 +113,7 @@ #include "pathnames.h" #include "my_crypt.h" #include "login.h" -#include "xstrncpy.h" +#include "strutils.h" #include "nls.h" diff --git a/login-utils/shutdown.c b/login-utils/shutdown.c index 0078df2d64..172113c76e 100644 --- a/login-utils/shutdown.c +++ b/login-utils/shutdown.c @@ -74,7 +74,7 @@ #include #include "linux_reboot.h" #include "pathnames.h" -#include "xstrncpy.h" +#include "strutils.h" #include "nls.h" #include "usleep.h" diff --git a/login-utils/simpleinit.c b/login-utils/simpleinit.c index 8cff848cf6..9277a3cc47 100644 --- a/login-utils/simpleinit.c +++ b/login-utils/simpleinit.c @@ -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" diff --git a/login-utils/vipw.c b/login-utils/vipw.c index b3972f3b31..e7247e42c8 100644 --- a/login-utils/vipw.c +++ b/login-utils/vipw.c @@ -64,7 +64,7 @@ static char version_string[] = "vipw 1.4"; #include #include "setpwnam.h" -#include "xstrncpy.h" +#include "strutils.h" #include "nls.h" #ifdef HAVE_LIBSELINUX diff --git a/login-utils/wall.c b/login-utils/wall.c index 7b5f6718f1..38c544266e 100644 --- a/login-utils/wall.c +++ b/login-utils/wall.c @@ -58,7 +58,7 @@ #include #include "nls.h" -#include "xstrncpy.h" +#include "strutils.h" #include "ttymsg.h" #include "pathnames.h" #include "carefulputc.h" diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am index aed8bac8d9..76b69fa4a2 100644 --- a/misc-utils/Makefile.am +++ b/misc-utils/Makefile.am @@ -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 diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index f94df06a1b..2f7860fd23 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -41,7 +41,7 @@ extern int optind; #include #include "ismounted.h" -#include "strtosize.h" +#include "strutils.h" const char *progname = "blkid"; diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c index dbfabc4a16..2f223f0c23 100644 --- a/misc-utils/wipefs.c +++ b/misc-utils/wipefs.c @@ -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 */ diff --git a/mount/Makefile.am b/mount/Makefile.am index 235cceb06e..36b06e3279 100644 --- a/mount/Makefile.am +++ b/mount/Makefile.am @@ -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 = diff --git a/mount/lomount.c b/mount/lomount.c index 03aae4b2aa..d6556fc71d 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -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 #include -#include "strtosize.h" +#include "strutils.h" static void usage(FILE *f) { diff --git a/mount/mount.c b/mount/mount.c index c0023f3947..9faa6a5b6f 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -41,7 +41,7 @@ #include "env.h" #include "nls.h" #include "blkdev.h" -#include "strtosize.h" +#include "strutils.h" #define DO_PS_FIDDLING diff --git a/mount/umount.c b/mount/umount.c index b5ff8a1770..6e24779b45 100644 --- a/mount/umount.c +++ b/mount/umount.c @@ -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 diff --git a/schedutils/Makefile.am b/schedutils/Makefile.am index c83e5eaff7..dc33175376 100644 --- a/schedutils/Makefile.am +++ b/schedutils/Makefile.am @@ -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 diff --git a/schedutils/chrt.c b/schedutils/chrt.c index 811eb200e0..bd7070cca5 100644 --- a/schedutils/chrt.c +++ b/schedutils/chrt.c @@ -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 */ diff --git a/schedutils/ionice.c b/schedutils/ionice.c index 34132f071d..78c9f0d3ca 100644 --- a/schedutils/ionice.c +++ b/schedutils/ionice.c @@ -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 index 9d6051ba10..0000000000 --- a/schedutils/schedutils.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2010 Karel Zak - * - * Released under the terms of the GNU General Public License version 2 - * - */ -#include -#include -#include -#include - -#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 index 80e4f7bfe2..0000000000 --- a/schedutils/schedutils.h +++ /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 - diff --git a/schedutils/taskset.c b/schedutils/taskset.c index 201fc1589f..5a7557c3a0 100644 --- a/schedutils/taskset.c +++ b/schedutils/taskset.c @@ -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; diff --git a/shlibs/mount/src/mountP.h b/shlibs/mount/src/mountP.h index 6145b730fc..4a99bb4e63 100644 --- a/shlibs/mount/src/mountP.h +++ b/shlibs/mount/src/mountP.h @@ -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); /* diff --git a/shlibs/mount/src/utils.c b/shlibs/mount/src/utils.c index 6133cdd772..a1ab50c083 100644 --- a/shlibs/mount/src/utils.c +++ b/shlibs/mount/src/utils.c @@ -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 diff --git a/sys-utils/Makefile.am b/sys-utils/Makefile.am index d2b85685f8..a45978e35b 100644 --- a/sys-utils/Makefile.am +++ b/sys-utils/Makefile.am @@ -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 diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c index fd4d2a9add..9598cf109b 100644 --- a/sys-utils/fallocate.c +++ b/sys-utils/fallocate.c @@ -44,7 +44,7 @@ #endif #include "nls.h" -#include "strtosize.h" +#include "strutils.h" static void __attribute__((__noreturn__)) usage(FILE *out) diff --git a/text-utils/more.c b/text-utils/more.c index 3752059849..49df52e25b 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -56,7 +56,7 @@ #include #include #include -#include "xstrncpy.h" +#include "strutils.h" #include "nls.h" #include "xalloc.h" -- 2.47.3