changeset 1235:63db77909fc8

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.
author Rob Landley <rob@landley.net>
date Sat, 29 Mar 2014 18:11:00 -0500
parents c99c215b4604
children 1f4a56212c83
files lib/lib.h lib/password.c lib/portability.h lib/xregcomp.c lib/xregcomp.h lib/xwrap.c toys.h toys/pending/mdev.c toys/pending/mkpasswd.c toys/pending/sed.c toys/posix/nl.c
diffstat 11 files changed, 38 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/lib/lib.h	Sat Mar 29 15:25:23 2014 -0500
+++ b/lib/lib.h	Sat Mar 29 18:11:00 2014 -0500
@@ -117,6 +117,7 @@
 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 @@
 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"
--- a/lib/password.c	Sat Mar 29 15:25:23 2014 -0500
+++ b/lib/password.c	Sat Mar 29 18:11:00 2014 -0500
@@ -4,7 +4,6 @@
  */
 
 #include "toys.h"
-#include "xregcomp.h"
 #include <time.h>
 
 int get_salt(char *salt, char *algo)
--- a/lib/portability.h	Sat Mar 29 15:25:23 2014 -0500
+++ b/lib/portability.h	Sat Mar 29 18:11:00 2014 -0500
@@ -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 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"
--- a/lib/xregcomp.c	Sat Mar 29 15:25:23 2014 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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);
-  }
-}
--- a/lib/xregcomp.h	Sat Mar 29 15:25:23 2014 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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);
--- a/lib/xwrap.c	Sat Mar 29 15:25:23 2014 -0500
+++ b/lib/xwrap.c	Sat Mar 29 18:11:00 2014 -0500
@@ -514,3 +514,14 @@
 
   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);
+  }
+}
--- a/toys.h	Sat Mar 29 15:25:23 2014 -0500
+++ b/toys.h	Sat Mar 29 18:11:00 2014 -0500
@@ -3,10 +3,12 @@
  * Copyright 2006 Rob Landley <rob@landley.net>
  */
 
+// 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"
 
--- a/toys/pending/mdev.c	Sat Mar 29 15:25:23 2014 -0500
+++ b/toys/pending/mdev.c	Sat Mar 29 18:11:00 2014 -0500
@@ -30,7 +30,6 @@
 */
 
 #include "toys.h"
-#include "lib/xregcomp.h"
 
 // todo, open() block devices to trigger partition scanning.
 
--- a/toys/pending/mkpasswd.c	Sat Mar 29 15:25:23 2014 -0500
+++ b/toys/pending/mkpasswd.c	Sat Mar 29 18:11:00 2014 -0500
@@ -22,7 +22,6 @@
 
 #define FOR_mkpasswd
 #include "toys.h"
-#include "lib/xregcomp.h"
 
 GLOBALS(
   long pfd;
--- a/toys/pending/sed.c	Sat Mar 29 15:25:23 2014 -0500
+++ b/toys/pending/sed.c	Sat Mar 29 18:11:00 2014 -0500
@@ -23,7 +23,6 @@
 
 #define FOR_sed
 #include "toys.h"
-#include "lib/xregcomp.h"
 
 GLOBALS(
   struct arg_list *files;
--- a/toys/posix/nl.c	Sat Mar 29 15:25:23 2014 -0500
+++ b/toys/posix/nl.c	Sat Mar 29 18:11:00 2014 -0500
@@ -27,7 +27,6 @@
 
 #define FOR_nl
 #include "toys.h"
-#include "lib/xregcomp.h"
 
 GLOBALS(
   long w;