summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-05-05 12:50:24 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-05-05 12:50:24 +0000
commit7d06701bfaad445e48832ba4fd189ffc36e34387 (patch)
treec3d0d5da0d9328d950a4da4cc3a4f9d84a3e7033
parent73ebb5709dc2a5aaee1e676a3c1b0bb7cebcd392 (diff)
downloadskalibs-7d06701bfaad445e48832ba4fd189ffc36e34387.tar.xz
- add stat_at
- make case_diff* work as a function is more cases - make sig_number case-insensitive - make child signal unblocking work in child_spawn*
-rw-r--r--package/deps.mak9
-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
10 files changed, 123 insertions, 17 deletions
diff --git a/package/deps.mak b/package/deps.mak
index 2d06861..15c012f 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -229,7 +229,7 @@ src/libstddjb/buffer_0small.o src/libstddjb/buffer_0small.lo: src/libstddjb/buff
src/libstddjb/buffer_1.o src/libstddjb/buffer_1.lo: src/libstddjb/buffer_1.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h
src/libstddjb/buffer_1small.o src/libstddjb/buffer_1small.lo: src/libstddjb/buffer_1small.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h
src/libstddjb/buffer_2.o src/libstddjb/buffer_2.lo: src/libstddjb/buffer_2.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h
-src/libstddjb/buffer_fill.o src/libstddjb/buffer_fill.lo: src/libstddjb/buffer_fill.c src/include/skalibs/buffer.h src/include/skalibs/cbuffer.h
+src/libstddjb/buffer_fill.o src/libstddjb/buffer_fill.lo: src/libstddjb/buffer_fill.c src/include/skalibs/buffer.h
src/libstddjb/buffer_flush.o src/libstddjb/buffer_flush.lo: src/libstddjb/buffer_flush.c src/include/skalibs/buffer.h src/include/skalibs/cbuffer.h src/include/skalibs/siovec.h
src/libstddjb/buffer_flush1read.o src/libstddjb/buffer_flush1read.lo: src/libstddjb/buffer_flush1read.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/siovec.h
src/libstddjb/buffer_get.o src/libstddjb/buffer_get.lo: src/libstddjb/buffer_get.c src/include/skalibs/buffer.h
@@ -257,8 +257,8 @@ src/libstddjb/byte_diff.o src/libstddjb/byte_diff.lo: src/libstddjb/byte_diff.c
src/libstddjb/byte_in.o src/libstddjb/byte_in.lo: src/libstddjb/byte_in.c src/include/skalibs/bytestr.h
src/libstddjb/byte_rchr.o src/libstddjb/byte_rchr.lo: src/libstddjb/byte_rchr.c src/include/skalibs/bytestr.h
src/libstddjb/byte_zero.o src/libstddjb/byte_zero.lo: src/libstddjb/byte_zero.c src/include/skalibs/bytestr.h src/include/skalibs/config.h
-src/libstddjb/case_diffb.o src/libstddjb/case_diffb.lo: src/libstddjb/case_diffb.c src/include/skalibs/bytestr.h
-src/libstddjb/case_diffs.o src/libstddjb/case_diffs.lo: src/libstddjb/case_diffs.c src/include/skalibs/bytestr.h
+src/libstddjb/case_diffb.o src/libstddjb/case_diffb.lo: src/libstddjb/case_diffb.c src/include/skalibs/bytestr.h src/include/skalibs/config.h
+src/libstddjb/case_diffs.o src/libstddjb/case_diffs.lo: src/libstddjb/case_diffs.c src/include/skalibs/bytestr.h src/include/skalibs/config.h
src/libstddjb/case_lowerb.o src/libstddjb/case_lowerb.lo: src/libstddjb/case_lowerb.c src/include/skalibs/bytestr.h
src/libstddjb/case_lowers.o src/libstddjb/case_lowers.lo: src/libstddjb/case_lowers.c src/include/skalibs/bytestr.h
src/libstddjb/case_startb.o src/libstddjb/case_startb.lo: src/libstddjb/case_startb.c src/include/skalibs/bytestr.h
@@ -287,7 +287,7 @@ src/libstddjb/cdb_read.o src/libstddjb/cdb_read.lo: src/libstddjb/cdb_read.c src
src/libstddjb/cdb_successor.o src/libstddjb/cdb_successor.lo: src/libstddjb/cdb_successor.c src/include/skalibs/cdb.h src/include/skalibs/uint32.h
src/libstddjb/cdb_zero.o src/libstddjb/cdb_zero.lo: src/libstddjb/cdb_zero.c src/include/skalibs/cdb.h
src/libstddjb/child_spawn.o src/libstddjb/child_spawn.lo: src/libstddjb/child_spawn.c src/include/skalibs/allreadwrite.h src/include/skalibs/bytestr.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h src/include/skalibs/uint.h
-src/libstddjb/child_spawn0.o src/libstddjb/child_spawn0.lo: src/libstddjb/child_spawn0.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/sysdeps.h
+src/libstddjb/child_spawn0.o src/libstddjb/child_spawn0.lo: src/libstddjb/child_spawn0.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/sig.h src/include/skalibs/sysdeps.h
src/libstddjb/child_spawn1_internal.o src/libstddjb/child_spawn1_internal.lo: src/libstddjb/child_spawn1_internal.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/sig.h src/include/skalibs/sysdeps.h
src/libstddjb/child_spawn1_pipe.o src/libstddjb/child_spawn1_pipe.lo: src/libstddjb/child_spawn1_pipe.c src/libstddjb/djbunix-internal.h src/include/skalibs/djbunix.h
src/libstddjb/child_spawn1_socket.o src/libstddjb/child_spawn1_socket.lo: src/libstddjb/child_spawn1_socket.c src/libstddjb/djbunix-internal.h src/include/skalibs/djbunix.h src/include/skalibs/webipc.h
@@ -760,6 +760,7 @@ src/libunixonacid/skaclient_startf.o src/libunixonacid/skaclient_startf.lo: src/
src/libunixonacid/skaclient_startf_async.o src/libunixonacid/skaclient_startf_async.lo: src/libunixonacid/skaclient_startf_async.c src/include/skalibs/djbunix.h src/include/skalibs/kolbak.h src/libunixonacid/skaclient-internal.h src/include/skalibs/skaclient.h src/include/skalibs/uint32.h
src/libunixonacid/skaclient_syncify.o src/libunixonacid/skaclient_syncify.lo: src/libunixonacid/skaclient_syncify.c src/include/skalibs/skaclient.h src/include/skalibs/tai.h
src/libunixonacid/skaclient_zero.o src/libunixonacid/skaclient_zero.lo: src/libunixonacid/skaclient_zero.c src/include/skalibs/skaclient.h
+src/libunixonacid/stat_at.o src/libunixonacid/stat_at.lo: src/libunixonacid/stat_at.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/unix-transactional.h
src/libunixonacid/timed_flush.o src/libunixonacid/timed_flush.lo: src/libunixonacid/timed_flush.c src/include/skalibs/bufalloc.h src/include/skalibs/error.h src/include/skalibs/functypes.h src/include/skalibs/iopause.h src/include/skalibs/tai.h src/include/skalibs/unix-timed.h
src/libunixonacid/timed_get.o src/libunixonacid/timed_get.lo: src/libunixonacid/timed_get.c src/include/skalibs/allreadwrite.h src/include/skalibs/functypes.h src/include/skalibs/iopause.h src/include/skalibs/tai.h src/include/skalibs/unix-timed.h
src/libunixonacid/timed_getln.o src/libunixonacid/timed_getln.lo: src/libunixonacid/timed_getln.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/skamisc.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h src/include/skalibs/unix-timed.h
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