aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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
6 files changed, 21 insertions, 29 deletions
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 <time.h>
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 <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 ec7d1b79..00000000
--- 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 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 <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 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);
+ }
+}