summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-03-29 18:11:00 -0500
committerRob Landley <rob@landley.net>2014-03-29 18:11:00 -0500
commit5b405827a2fa4c928c488f3e7b0197dfec60dcc2 (patch)
treee8bbf1f2f4b8f70bd7e0682e0440ac64735096a4
parentd4f01257d9d3b0d776114046a43d237a424fef77 (diff)
downloadtoybox-5b405827a2fa4c928c488f3e7b0197dfec60dcc2.tar.gz
toybox-5b405827a2fa4c928c488f3e7b0197dfec60dcc2.tar.bz2
toybox-5b405827a2fa4c928c488f3e7b0197dfec60dcc2.zip
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.
-rw-r--r--lib/lib.h2
-rw-r--r--lib/password.c1
-rw-r--r--lib/portability.h8
-rw-r--r--lib/xregcomp.c22
-rw-r--r--lib/xregcomp.h6
-rw-r--r--lib/xwrap.c11
-rw-r--r--toys.h33
-rw-r--r--toys/pending/mdev.c1
-rw-r--r--toys/pending/mkpasswd.c1
-rw-r--r--toys/pending/sed.c1
-rw-r--r--toys/posix/nl.c1
11 files changed, 38 insertions, 49 deletions
diff --git a/lib/lib.h b/lib/lib.h
index 56927b8..d5b3d3c 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 f2d010e..13a431a 100644
--- a/lib/password.c
+++ b/lib/password.c
@@ -4,7 +4,6 @@
*/
#include "toys.h"
-#include "xregcomp.h"
#include <time.h>
int get_salt(char *salt, char *algo)
diff --git a/lib/portability.h b/lib/portability.h
index 86484c7..3b1cdf7 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 <shadow.h>
+#include <sys/mount.h>
+#include <sys/swap.h>
+
// 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 ec7d1b7..0000000
--- a/lib/xregcomp.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* Call regcomp() and handle errors.
- *
- * Copyright 2007 Rob Landley <rob@landley.net>
- *
- * 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 fa929fa..0000000
--- a/lib/xregcomp.h
+++ /dev/null
@@ -1,6 +0,0 @@
-/* This is a separate file so libc doesn't always need regex support. */
-
-#include <sys/types.h>
-#include <regex.h>
-
-void xregcomp(regex_t *preg, char *rexec, int cflags);
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 51bd2b4..5310506 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 cd1755b..2f16596 100644
--- a/toys.h
+++ b/toys.h
@@ -3,10 +3,12 @@
* Copyright 2006 Rob Landley <rob@landley.net>
*/
-#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 <ctype.h>
#include <dirent.h>
#include <errno.h>
@@ -16,12 +18,10 @@
#include <limits.h>
#include <libgen.h>
#include <math.h>
-#include <pty.h>
#include <pwd.h>
+#include <regex.h>
#include <sched.h>
#include <setjmp.h>
-#include <sched.h>
-#include <shadow.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
@@ -29,15 +29,10 @@
#include <stdlib.h>
#include <string.h>
#include <strings.h>
-#include <sys/ioctl.h>
#include <sys/mman.h>
-#include <sys/mount.h>
#include <sys/resource.h>
#include <sys/stat.h>
-#include <sys/statfs.h>
#include <sys/statvfs.h>
-#include <sys/sysinfo.h>
-#include <sys/swap.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
@@ -49,13 +44,7 @@
#include <utime.h>
#include <utmpx.h>
-// Internationalization support
-
-#include <locale.h>
-#include <wchar.h>
-#include <wctype.h>
-
-// Networking stuff
+// Posix networking
#include <arpa/inet.h>
#include <netdb.h>
@@ -66,6 +55,18 @@
#include <sys/socket.h>
#include <sys/un.h>
+// Internationalization support (also in POSIX and LSB)
+
+#include <locale.h>
+#include <wchar.h>
+#include <wctype.h>
+
+// LSB 4.1 headers
+#include <pty.h>
+#include <sys/ioctl.h>
+#include <sys/statfs.h>
+#include <sys/sysinfo.h>
+
#include "lib/lib.h"
#include "toys/e2fs.h"
diff --git a/toys/pending/mdev.c b/toys/pending/mdev.c
index b89ac2c..2d98c25 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 87b239e..a46c514 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 0ce25ac..22e07c0 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 b462cdd..c7e7b92 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;