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 +++++++++++ toys.h | 33 +++++++++++++++++---------------- toys/pending/mdev.c | 1 - toys/pending/mkpasswd.c | 1 - toys/pending/sed.c | 1 - toys/posix/nl.c | 1 - 11 files changed, 38 insertions(+), 49 deletions(-) delete mode 100644 lib/xregcomp.c delete mode 100644 lib/xregcomp.h 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); + } +} diff --git a/toys.h b/toys.h index cd1755b6..2f165967 100644 --- a/toys.h +++ b/toys.h @@ -3,10 +3,12 @@ * Copyright 2006 Rob Landley */ -#include "generated/config.h" +// Stuff that needs to go before the standard headers +#include "generated/config.h" #include "lib/portability.h" +// General posix-2008 headers #include #include #include @@ -16,12 +18,10 @@ #include #include #include -#include #include +#include #include #include -#include -#include #include #include #include @@ -29,15 +29,10 @@ #include #include #include -#include #include -#include #include #include -#include #include -#include -#include #include #include #include @@ -49,13 +44,7 @@ #include #include -// Internationalization support - -#include -#include -#include - -// Networking stuff +// Posix networking #include #include @@ -66,6 +55,18 @@ #include #include +// Internationalization support (also in POSIX and LSB) + +#include +#include +#include + +// LSB 4.1 headers +#include +#include +#include +#include + #include "lib/lib.h" #include "toys/e2fs.h" diff --git a/toys/pending/mdev.c b/toys/pending/mdev.c index b89ac2ca..2d98c257 100644 --- a/toys/pending/mdev.c +++ b/toys/pending/mdev.c @@ -30,7 +30,6 @@ config MDEV_CONF */ #include "toys.h" -#include "lib/xregcomp.h" // todo, open() block devices to trigger partition scanning. diff --git a/toys/pending/mkpasswd.c b/toys/pending/mkpasswd.c index 87b239e0..a46c514c 100644 --- a/toys/pending/mkpasswd.c +++ b/toys/pending/mkpasswd.c @@ -22,7 +22,6 @@ config MKPASSWD #define FOR_mkpasswd #include "toys.h" -#include "lib/xregcomp.h" GLOBALS( long pfd; diff --git a/toys/pending/sed.c b/toys/pending/sed.c index 0ce25aca..22e07c07 100644 --- a/toys/pending/sed.c +++ b/toys/pending/sed.c @@ -23,7 +23,6 @@ config SED #define FOR_sed #include "toys.h" -#include "lib/xregcomp.h" GLOBALS( struct arg_list *files; diff --git a/toys/posix/nl.c b/toys/posix/nl.c index b462cddd..c7e7b92c 100644 --- a/toys/posix/nl.c +++ b/toys/posix/nl.c @@ -27,7 +27,6 @@ config NL #define FOR_nl #include "toys.h" -#include "lib/xregcomp.h" GLOBALS( long w; -- cgit v1.2.3