From 5b405827a2fa4c928c488f3e7b0197dfec60dcc2 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 29 Mar 2014 18:11:00 -0500 Subject: Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix. --- lib/lib.h | 2 ++ lib/password.c | 1 - lib/portability.h | 8 ++++++++ lib/xregcomp.c | 22 ---------------------- lib/xregcomp.h | 6 ------ lib/xwrap.c | 11 +++++++++++ 6 files changed, 21 insertions(+), 29 deletions(-) delete mode 100644 lib/xregcomp.c delete mode 100644 lib/xregcomp.h (limited to 'lib') diff --git a/lib/lib.h b/lib/lib.h index 56927b8b..d5b3d3ce 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -117,6 +117,7 @@ void xsetuser(struct passwd *pwd); char *xreadlink(char *name); long xparsetime(char *arg, long units, long *fraction); void xpidfile(char *name); +void xregcomp(regex_t *preg, char *rexec, int cflags); // lib.c void verror_msg(char *msg, int err, va_list va); @@ -178,4 +179,5 @@ mode_t string_to_mode(char *mode_str, mode_t base); void mode_to_string(mode_t mode, char *buf); void names_to_pid(char **names, int (*callback)(pid_t pid, char *name)); +// Functions in need of further review/cleanup #include "lib/pending.h" diff --git a/lib/password.c b/lib/password.c index f2d010ec..13a431ac 100644 --- a/lib/password.c +++ b/lib/password.c @@ -4,7 +4,6 @@ */ #include "toys.h" -#include "xregcomp.h" #include int get_salt(char *salt, char *algo) diff --git a/lib/portability.h b/lib/portability.h index 86484c7f..3b1cdf70 100644 --- a/lib/portability.h +++ b/lib/portability.h @@ -13,6 +13,9 @@ #undef _FORTIFY_SOURCE +// For musl +#define _ALL_SOURCE + // Test for gcc (using compiler builtin #define) #ifdef __GNUC__ @@ -150,5 +153,10 @@ ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream); ssize_t getline(char **lineptr, size_t *n, FILE *stream); #endif +// Linux headers not listed by POSIX or LSB +#include +#include +#include + // compile time probes for stuff libc didn't provide #include "generated/portability.h" diff --git a/lib/xregcomp.c b/lib/xregcomp.c deleted file mode 100644 index ec7d1b79..00000000 --- a/lib/xregcomp.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Call regcomp() and handle errors. - * - * Copyright 2007 Rob Landley - * - * This is a separate file so environments that haven't got regular expression - * support can configure this out and avoid a build break. - */ - -#include "toys.h" -#include "xregcomp.h" - -void xregcomp(regex_t *preg, char *regex, int cflags) -{ - int rc = regcomp(preg, regex, cflags); - - if (rc) { - char msg[256]; - regerror(rc, preg, msg, 255); - msg[255]=0; - error_exit("xregcomp: %s", msg); - } -} diff --git a/lib/xregcomp.h b/lib/xregcomp.h deleted file mode 100644 index fa929fa3..00000000 --- a/lib/xregcomp.h +++ /dev/null @@ -1,6 +0,0 @@ -/* This is a separate file so libc doesn't always need regex support. */ - -#include -#include - -void xregcomp(regex_t *preg, char *rexec, int cflags); diff --git a/lib/xwrap.c b/lib/xwrap.c index 51bd2b43..5310506c 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -514,3 +514,14 @@ long xparsetime(char *arg, long units, long *fraction) return l; } + +// Compile a regular expression into a regex_t +void xregcomp(regex_t *preg, char *regex, int cflags) +{ + int rc = regcomp(preg, regex, cflags); + + if (rc) { + regerror(rc, preg, libbuf, sizeof(libbuf)); + error_exit("xregcomp: %s", libbuf); + } +} -- cgit v1.2.3