summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/skalibs/bytestr.h15
-rw-r--r--src/include/skalibs/unix-transactional.h5
-rw-r--r--src/libstddjb/case_diffb.c15
-rw-r--r--src/libstddjb/case_diffs.c6
-rw-r--r--src/libstddjb/child_spawn.c3
-rw-r--r--src/libstddjb/child_spawn0.c5
-rw-r--r--src/libstddjb/child_spawn1_internal.c3
-rw-r--r--src/libstddjb/sig_number.c2
-rw-r--r--src/libunixonacid/stat_at.c77
9 files changed, 118 insertions, 13 deletions
diff --git a/src/include/skalibs/bytestr.h b/src/include/skalibs/bytestr.h
index ff2851c..fd602e0 100644
--- a/src/include/skalibs/bytestr.h
+++ b/src/include/skalibs/bytestr.h
@@ -13,16 +13,19 @@
#include <sys/types.h>
#include <string.h>
+#include <strings.h>
#define byte_copy(to, n, from) memmove(to, (from), n)
#define byte_copyr(to, n, from) memmove(to, (from), n)
#define byte_diff(a, n, b) memcmp(a, (b), n)
#define byte_zero(p, n) memset(p, 0, n)
-#define str_len(s) strlen(s)
-#define str_nlen(s, max) strnlen(s, max)
-#define str_diff(a, b) strcmp(a, b)
-#define str_diffn(a, b, n) strncmp(a, b, n)
+#define str_len strlen
+#define str_nlen strnlen
+#define str_diff strcmp
+#define str_diffn strncmp
#define str_copy(to, from) strlen(strcpy(to, from))
+#define case_diffs strcasecmp
+#define case_diffb(a, n, b) strncasecmp(a, (b), n)
#else
@@ -35,6 +38,8 @@ extern unsigned int str_len (char const *) gccattr_pure ;
extern int str_diff (char const *, char const *) gccattr_pure ;
extern int str_diffn (char const *, char const *, unsigned int) gccattr_pure ;
extern unsigned int str_copy (char *, char const *) ;
+extern int case_diffs (char const *, char const *) gccattr_pure ;
+extern int case_diffb (char const *, unsigned int, char const *) gccattr_pure ;
#endif
@@ -58,8 +63,6 @@ extern void case_uppers (char *) ;
extern void case_upperb (char *, unsigned int) ;
#define case_equals(a, b) (!case_diffs(a, b))
#define case_equalb(a, n, b) (!case_diffb(a, n, b))
-extern int case_diffs (char const *, char const *) gccattr_pure ;
-extern int case_diffb (char const *, unsigned int, char const *) gccattr_pure ;
#define case_starts(s, t) case_startb(s, str_len(s), t)
extern int case_startb (char const *, unsigned int, char const *) gccattr_pure ;
extern unsigned int case_str (char const *, char const *) gccattr_pure ;
diff --git a/src/include/skalibs/unix-transactional.h b/src/include/skalibs/unix-transactional.h
index b811c99..13129f1 100644
--- a/src/include/skalibs/unix-transactional.h
+++ b/src/include/skalibs/unix-transactional.h
@@ -3,6 +3,8 @@
#ifndef UNIX_TRANSACTIONAL_H
#define UNIX_TRANSACTIONAL_H
+#include <sys/types.h>
+#include <sys/stat.h>
#include <skalibs/uint64.h>
#include <skalibs/stralloc.h>
@@ -22,6 +24,9 @@ extern int open_truncatb (int, char const *) ;
extern int open_appendat (int, char const *) ;
extern int open_appendatb (int, char const *) ;
+extern int stat_at (int, char const *, struct stat *) ;
+extern int lstat_at (int, char const *, struct stat *) ;
+
extern unsigned int openreadnclose_at (int, char const *, char *, unsigned int) ;
extern int openslurpclose_at (int, char const *, stralloc *) ;
extern int opengetlnclose_at (int, char const *, stralloc *, int) ;
diff --git a/src/libstddjb/case_diffb.c b/src/libstddjb/case_diffb.c
index 1931c0f..f267756 100644
--- a/src/libstddjb/case_diffb.c
+++ b/src/libstddjb/case_diffb.c
@@ -1,7 +1,11 @@
/* ISC license. */
+#include <skalibs/config.h>
#include <skalibs/bytestr.h>
+#ifdef SKALIBS_FLAG_REPLACE_LIBC
+
+
int case_diffb (char const *s, unsigned int len, char const *t)
{
register unsigned char x = 0, y = 0 ;
@@ -16,3 +20,14 @@ int case_diffb (char const *s, unsigned int len, char const *t)
}
return (int)(x - y) ;
}
+
+else
+
+#include <strings.h>
+
+int case_diffb (char const *s, unsigned int len, char const *t)
+{
+ return strncasecmp(s, t, len) ;
+}
+
+#endif
diff --git a/src/libstddjb/case_diffs.c b/src/libstddjb/case_diffs.c
index 2731408..bf72472 100644
--- a/src/libstddjb/case_diffs.c
+++ b/src/libstddjb/case_diffs.c
@@ -1,7 +1,11 @@
/* ISC license. */
+#include <skalibs/config.h>
#include <skalibs/bytestr.h>
+#ifdef SKALIBS_FLAG_REPLACE_LIBC
+
+
int case_diffs (char const *s, char const *t)
{
register unsigned char x = 1, y = 1 ;
@@ -16,3 +20,5 @@ int case_diffs (char const *s, char const *t)
}
return (int)(x - y) ;
}
+
+#endif
diff --git a/src/libstddjb/child_spawn.c b/src/libstddjb/child_spawn.c
index 922c777..18cee96 100644
--- a/src/libstddjb/child_spawn.c
+++ b/src/libstddjb/child_spawn.c
@@ -75,8 +75,7 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const
sigemptyset(&set) ;
e = posix_spawnattr_setsigmask(&attr, &set) ;
if (e) goto errattr ;
- sigfillset(&set) ;
- e = posix_spawnattr_setsigdefault(&attr, &set) ;
+ e = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK) ;
if (e) goto errattr ;
}
e = posix_spawn_file_actions_init(&actions) ;
diff --git a/src/libstddjb/child_spawn0.c b/src/libstddjb/child_spawn0.c
index 7129515..bb8b29e 100644
--- a/src/libstddjb/child_spawn0.c
+++ b/src/libstddjb/child_spawn0.c
@@ -25,8 +25,7 @@ pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const
sigemptyset(&set) ;
e = posix_spawnattr_setsigmask(&attr, &set) ;
if (e) goto errattr ;
- sigfillset(&set) ;
- e = posix_spawnattr_setsigdefault(&attr, &set) ;
+ e = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK) ;
if (e) goto errattr ;
}
if (!haspath && (setenv("PATH", SKALIBS_DEFAULTPATH, 0) < 0)) { e = errno ; goto errattr ; }
@@ -47,6 +46,7 @@ pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const
#include <unistd.h>
#include <skalibs/allreadwrite.h>
+#include <skalibs/sig.h>
#include <skalibs/djbunix.h>
pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const *envp)
@@ -67,6 +67,7 @@ pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const
if (pid)
{
fd_close(p[0]) ;
+ sig_blocknone() ;
pathexec_run(prog, argv, envp) ;
e = errno ;
fd_write(p[1], (char *)&e, sizeof(e)) ;
diff --git a/src/libstddjb/child_spawn1_internal.c b/src/libstddjb/child_spawn1_internal.c
index 8347f69..f833a15 100644
--- a/src/libstddjb/child_spawn1_internal.c
+++ b/src/libstddjb/child_spawn1_internal.c
@@ -29,8 +29,7 @@ pid_t child_spawn1_internal (char const *prog, char const *const *argv, char con
sigemptyset(&set) ;
e = posix_spawnattr_setsigmask(&attr, &set) ;
if (e) goto errattr ;
- sigfillset(&set) ;
- e = posix_spawnattr_setsigdefault(&attr, &set) ;
+ e = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK) ;
if (e) goto errattr ;
}
e = posix_spawn_file_actions_init(&actions) ;
diff --git a/src/libstddjb/sig_number.c b/src/libstddjb/sig_number.c
index 93d9b59..cbd897d 100644
--- a/src/libstddjb/sig_number.c
+++ b/src/libstddjb/sig_number.c
@@ -7,6 +7,6 @@
int sig_number (char const *name)
{
register sigtable_t const *p = skalibs_sigtable ;
- for (; p->name ; p++) if (!str_diff(name, p->name)) break ;
+ for (; p->name ; p++) if (!case_diffs(name, p->name)) break ;
return p->number ;
}
diff --git a/src/libunixonacid/stat_at.c b/src/libunixonacid/stat_at.c
new file mode 100644
index 0000000..e8b049f
--- /dev/null
+++ b/src/libunixonacid/stat_at.c
@@ -0,0 +1,77 @@
+/* ISC license. */
+
+#include <skalibs/sysdeps.h>
+
+#ifdef SKALIBS_HASOPENAT
+
+#ifndef _ATFILE_SOURCE
+#define _ATFILE_SOURCE
+#endif
+
+#include <skalibs/nonposix.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <skalibs/unix-transactional.h>
+
+int stat_at (int dirfd, char const *file, struct stat *st)
+{
+ return fstatat(dirfd, file, st, 0) ;
+}
+
+int lstat_at (int dirfd, char const *file, struct stat *st)
+{
+ return fstatat(dirfd, file, st, AT_SYMLINK_NOFOLLOW) ;
+}
+
+#else
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <skalibs/djbunix.h>
+#include <skalibs/unix-transactional.h>
+
+static int fstat_at (int dirfd, char const *file, struct stat *st, int (*dostat)(char const *, struct stat *))
+{
+ int r ;
+ int fdhere = open_read(".") ;
+ if (fdhere < 0) return -1 ;
+ if (fd_chdir(dirfd) < 0)
+ {
+ register int e = errno ;
+ fd_close(fdhere) ;
+ errno = e ;
+ return -1 ;
+ }
+ r = (*dostat)(file, st) ;
+ if (r < 0)
+ {
+ register int e = errno ;
+ fd_chdir(fdhere) ;
+ fd_close(fdhere) ;
+ errno = e ;
+ return -1 ;
+ }
+ if (fd_chdir(fdhere) < 0)
+ {
+ register int e = errno ;
+ fd_close(fdhere) ;
+ errno = e ;
+ return -1 ;
+ }
+ return r ;
+}
+
+int stat_at (int dirfd, char const *file, struct stat *st)
+{
+ return fstat_at(dirfd, file, st, &stat) ;
+}
+
+int lstat_at (int dirfd, char const *file, struct stat *st)
+{
+ return fstat_at(dirfd, file, st, &lstat) ;
+}
+
+#endif