diff options
author | Davidlohr Bueso | 2010-11-16 14:47:35 +0100 |
---|---|---|
committer | Karel Zak | 2010-11-23 21:06:49 +0100 |
commit | 8abcf2900297c6d53ead867c42f7c1688e8d52ca (patch) | |
tree | 77e2d666cd76d9d4c37e1c1864415c1e52d37926 /include | |
parent | libblkid: cache is incorrectly revalidated (diff) | |
download | kernel-qcow2-util-linux-8abcf2900297c6d53ead867c42f7c1688e8d52ca.tar.gz kernel-qcow2-util-linux-8abcf2900297c6d53ead867c42f7c1688e8d52ca.tar.xz kernel-qcow2-util-linux-8abcf2900297c6d53ead867c42f7c1688e8d52ca.zip |
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 <dave@gnu.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/Makefile.am | 5 | ||||
-rw-r--r-- | include/strtosize.h | 8 | ||||
-rw-r--r-- | include/strutils.h | 26 | ||||
-rw-r--r-- | include/xstrncpy.h | 8 |
4 files changed, 28 insertions, 19 deletions
diff --git a/include/Makefile.am b/include/Makefile.am index 3b93acd07..c7b3c20df 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 c789df93d..000000000 --- a/include/strtosize.h +++ /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 index 000000000..e24496d3c --- /dev/null +++ b/include/strutils.h @@ -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 index 7ed4109d6..000000000 --- a/include/xstrncpy.h +++ /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; -} |