summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/skalibs/bytestr.h11
-rw-r--r--src/include/skalibs/djbunix.h9
-rw-r--r--src/include/skalibs/environ.h7
-rw-r--r--src/include/skalibs/getpeereid.h9
-rw-r--r--src/include/skalibs/mininetstring.h5
-rw-r--r--src/include/skalibs/posixplz.h45
-rw-r--r--src/include/skalibs/setgroups.h12
-rw-r--r--src/include/skalibs/skalibs.h4
-rw-r--r--src/include/skalibs/skamisc.h1
-rw-r--r--src/include/skalibs/stddjb.h4
-rw-r--r--src/include/skalibs/textmessage.h96
-rw-r--r--src/include/skalibs/unixonacid.h1
-rw-r--r--src/include/skalibs/webipc.h2
13 files changed, 171 insertions, 35 deletions
diff --git a/src/include/skalibs/bytestr.h b/src/include/skalibs/bytestr.h
index 1f3942b..3a5c95e 100644
--- a/src/include/skalibs/bytestr.h
+++ b/src/include/skalibs/bytestr.h
@@ -3,27 +3,21 @@
#ifndef BYTESTR_H
#define BYTESTR_H
-#include <skalibs/config.h>
#include <skalibs/gccattributes.h>
/* for Alphas and other archs where char != 8bit */
#define T8(x) ((x) & 0xffU)
-#include <skalibs/sysdeps.h>
#include <string.h>
#include <strings.h>
+#include <skalibs/posixplz.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 strlen
-
-#ifdef SKALIBS_HASSTRNLEN
-# define str_nlen strnlen
-#else
-# define str_nlen(s, max) byte_chr(s, (max), 0)
-#endif
+#define str_nlen strnlen
#define str_diff strcmp
#define str_diffn strncmp
@@ -36,6 +30,7 @@ extern size_t byte_rchr (char const *, size_t, int) gccattr_pure ;
extern size_t byte_in (char const *, size_t, char const *, size_t) gccattr_pure ;
#define byte_equal(s, n, t) (!memcmp(s, (t), n))
extern size_t byte_count (char const *, size_t, char) gccattr_pure ;
+extern size_t byte_search (char const *, size_t, char const *, size_t) ;
#define str_diffb(a, n, b) strncmp(a, (b), n)
extern size_t str_chr (char const *, int) gccattr_pure ;
diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h
index 4dc534e..b095c82 100644
--- a/src/include/skalibs/djbunix.h
+++ b/src/include/skalibs/djbunix.h
@@ -9,7 +9,8 @@
#include <skalibs/gccattributes.h>
#include <skalibs/stralloc.h>
#include <skalibs/envalloc.h>
-#include <skalibs/env.h> /* compatibility */
+#include <skalibs/env.h> /* will disappear */
+#include <skalibs/posixplz.h>
#define DJBUNIX_FLAG_NB 0x01U
#define DJBUNIX_FLAG_COE 0x02U
@@ -56,7 +57,6 @@ extern int pathexec_env (char const *, char const *) ;
extern void pathexec_r (char const *const *, char const *const *, size_t, char const *, size_t) ;
extern void pathexec_r_name (char const *, char const *const *, char const *const *, size_t, char const *, size_t) ;
extern void pathexec_fromenv (char const *const *, char const *const *, size_t) ;
-extern void execvep (char const *, char const *const *, char const *const *, char const *) ;
extern void pathexec_run (char const *, char const *const *, char const *const *) ;
extern void pathexec0_run (char const *const *, char const *const *) ;
extern void pathexec (char const *const *) ;
@@ -89,11 +89,9 @@ extern unsigned int wait_reap (void) ;
extern int waitn (pid_t *, unsigned int) ;
extern int waitn_reap (pid_t *, unsigned int) ;
-extern pid_t doublefork (void) ;
-
extern int fd_chdir (int) ;
-#define absolutepath(sa, s) sarealpath(sa, s)
+#define absolutepath(sa, s) sarealpath(sa, s) /* will disappear */
extern int sarealpath (stralloc *, char const *) ;
extern int sarealpath_tmp (stralloc *, char const *, stralloc *) ;
extern int sabasename (stralloc *, char const *, size_t) ;
@@ -162,7 +160,6 @@ extern int rm_rf_in_tmp (stralloc *, size_t) ; /* caution ! */
extern int rmstar (char const *) ;
extern int rmstar_tmp (char const *, stralloc *) ;
-extern int touch (char const *) ;
extern int filecopy_unsafe (char const *, char const *, unsigned int) ;
extern int filecopy_suffix (char const *, char const *, unsigned int, char const *) ;
extern int hiercopy (char const *, char const *) ;
diff --git a/src/include/skalibs/environ.h b/src/include/skalibs/environ.h
index 6bf3041..0d4494b 100644
--- a/src/include/skalibs/environ.h
+++ b/src/include/skalibs/environ.h
@@ -1,8 +1,5 @@
/* ISC license. */
-#ifndef ENVIRON_H
-#define ENVIRON_H
+/* This header is being deprecated */
-extern char **environ ;
-
-#endif
+#include <skalibs/posixplz.h>
diff --git a/src/include/skalibs/getpeereid.h b/src/include/skalibs/getpeereid.h
index 4aa2898..0d4494b 100644
--- a/src/include/skalibs/getpeereid.h
+++ b/src/include/skalibs/getpeereid.h
@@ -1,10 +1,5 @@
/* ISC license. */
-#ifndef GETPEEREID_H
-#define GETPEEREID_H
+/* This header is being deprecated */
-#include <sys/types.h>
-
-extern int getpeereid (int, uid_t *, gid_t *) ;
-
-#endif
+#include <skalibs/posixplz.h>
diff --git a/src/include/skalibs/mininetstring.h b/src/include/skalibs/mininetstring.h
index 1997b18..9e88601 100644
--- a/src/include/skalibs/mininetstring.h
+++ b/src/include/skalibs/mininetstring.h
@@ -4,9 +4,10 @@
#define MININETSTRING_H
#include <stdint.h>
+#include <skalibs/gccattributes.h>
#include <skalibs/stralloc.h>
-extern int mininetstring_read (int, stralloc *, uint32_t *) ;
-extern int mininetstring_write (int, char const *, uint16_t, uint32_t *) ;
+extern int mininetstring_read (int, stralloc *, uint32_t *) gccattr_deprecated ;
+extern int mininetstring_write (int, char const *, uint16_t, uint32_t *) gccattr_deprecated ;
#endif
diff --git a/src/include/skalibs/posixplz.h b/src/include/skalibs/posixplz.h
new file mode 100644
index 0000000..72cffee
--- /dev/null
+++ b/src/include/skalibs/posixplz.h
@@ -0,0 +1,45 @@
+/* ISC license. */
+
+#ifndef SKALIBS_POSIXPLZ_H
+#define SKALIBS_POSIXPLZ_H
+
+#include <sys/types.h>
+#include <skalibs/gccattributes.h>
+
+
+ /*
+ Stuff that doesn't have its own POSIX header for some reason.
+ */
+
+extern char **environ ;
+
+
+ /*
+ Stuff that _is_ POSIX, but some OSes still don't have it.
+ openat() et al. should be here, but they're impossible to
+ emulate correctly, and I don't want an app using openat()
+ to think it has safe POSIX semantics when it doesn't :/
+ EPROTO et al. should be here, but ugh ifdef forests.
+ */
+
+extern size_t strnlen (char const *, size_t) gccattr_pure ;
+
+
+ /*
+ Non-POSIX functions that some OSes provide and others don't.
+ setgroups() isn't included because it's its own kind of broken.
+ */
+
+extern void *memmem (void const *, size_t, void const *, size_t) gccattr_pure ;
+extern int getpeereid (int, uid_t *, gid_t *) ;
+
+
+ /*
+ Functions that aren't standard at all, but honestly could be. :P
+ */
+
+extern void execvep (char const *, char const *const *, char const *const *, char const *) ;
+extern pid_t doublefork (void) ;
+extern int touch (char const *) ;
+
+#endif
diff --git a/src/include/skalibs/setgroups.h b/src/include/skalibs/setgroups.h
index 98998e0..19421e0 100644
--- a/src/include/skalibs/setgroups.h
+++ b/src/include/skalibs/setgroups.h
@@ -7,6 +7,13 @@
#ifdef SKALIBS_HASSETGROUPS
+ /*
+ setgroups() is defined by a lot of OSes.
+ However, they don't agree on what it should do:
+ some change the primary gid, others don't, etc. It's a mess.
+ Never use setgroups(). Use the functions below instead.
+ */
+
#include <unistd.h>
extern int setgroups_and_gid (gid_t, size_t, gid_t const *) ;
@@ -15,8 +22,11 @@ extern int skalibs_setgroups (size_t, gid_t const *) ;
#else
+ /* No setgroups() at all? not much we can do. */
+
#include <errno.h>
-#define setgroups(n, tab) (errno = ENOSYS, -1)
+
+#define setgroups_and_gid(g, n, tab) (errno = ENOSYS, -1)
#define setgroups_with_egid(n, tab) (errno = ENOSYS, -1)
#define skalibs_setgroups(n, tab) (errno = ENOSYS, -1)
diff --git a/src/include/skalibs/skalibs.h b/src/include/skalibs/skalibs.h
index e889461..2924e1c 100644
--- a/src/include/skalibs/skalibs.h
+++ b/src/include/skalibs/skalibs.h
@@ -4,11 +4,11 @@
#define SKALIBS_H
/*
- This header includes everything in skalibs,
- except skalibs/config.h and skalibs/sysdeps.h
+ This header includes everything in skalibs except skalibs/config.h
It's heavy!
*/
+#include <skalibs/posixplz.h>
#include <skalibs/stddjb.h>
#include <skalibs/stdcrypto.h>
#include <skalibs/random.h>
diff --git a/src/include/skalibs/skamisc.h b/src/include/skalibs/skamisc.h
index cf33ec2..15f7f02 100644
--- a/src/include/skalibs/skamisc.h
+++ b/src/include/skalibs/skamisc.h
@@ -12,6 +12,7 @@ extern stralloc satmp ;
extern int skagetln (buffer *, stralloc *, char) ;
extern int skagetln_nofill (buffer *, stralloc *, char) ;
extern int skagetlnsep (buffer *, stralloc *, char const *, size_t) ;
+extern int skagetlnmaxsep (buffer *, stralloc *, size_t, char const *, size_t) ;
extern int getlnmax (buffer *, char *, size_t, size_t *, char) ;
extern int getlnmaxsep (buffer *, char *, size_t, size_t *, char const *, size_t) ;
diff --git a/src/include/skalibs/stddjb.h b/src/include/skalibs/stddjb.h
index 50e07c5..87f72d0 100644
--- a/src/include/skalibs/stddjb.h
+++ b/src/include/skalibs/stddjb.h
@@ -29,17 +29,15 @@
#include <skalibs/djbunix.h>
#include <skalibs/envalloc.h>
#include <skalibs/env.h>
-#include <skalibs/environ.h>
#include <skalibs/fmtscan.h>
#include <skalibs/functypes.h>
#include <skalibs/gccattributes.h>
#include <skalibs/genalloc.h>
#include <skalibs/genwrite.h>
-#include <skalibs/getpeereid.h>
#include <skalibs/iobuffer.h>
#include <skalibs/iopause.h>
#include <skalibs/lolstdio.h>
-#include <skalibs/mininetstring.h>
+#include <skalibs/mininetstring.h> /* will disappear */
#include <skalibs/netstring.h>
#include <skalibs/nsig.h>
#include <skalibs/segfault.h>
diff --git a/src/include/skalibs/textmessage.h b/src/include/skalibs/textmessage.h
new file mode 100644
index 0000000..9904534
--- /dev/null
+++ b/src/include/skalibs/textmessage.h
@@ -0,0 +1,96 @@
+/* ISC license. */
+
+#ifndef SKALIBS_TEXTMESSAGE_H
+#define SKALIBS_TEXTMESSAGE_H
+
+#include <sys/uio.h>
+#include <stdint.h>
+#include <skalibs/gccattributes.h>
+#include <skalibs/allreadwrite.h>
+#include <skalibs/bufalloc.h>
+#include <skalibs/buffer.h>
+#include <skalibs/stralloc.h>
+#include <skalibs/tai.h>
+
+#define TEXTMESSAGE_MAXREADS 128
+
+
+ /* Sender */
+
+typedef struct textmessage_sender_s textmessage_sender_t, *textmessage_sender_t_ref ;
+struct textmessage_sender_s
+{
+ bufalloc out ;
+} ;
+#define TEXTMESSAGE_SENDER_ZERO { .out = BUFALLOC_ZERO }
+extern textmessage_sender_t const textmessage_sender_zero ;
+#define TEXTMESSAGE_SENDER_INIT(fd) { .out = BUFALLOC_INIT(&fd_write, (fd)) }
+
+#define textmessage_sender_init(ts, fd) bufalloc_init(&(ts)->out, &fd_write, fd)
+#define textmessage_sender_free(ts) bufalloc_free(&(ts)->out)
+#define textmessage_sender_fd(ts) bufalloc_fd(&(ts)->out)
+extern int textmessage_sender_getfd (textmessage_sender_t const *) gccattr_pure ;
+#define textmessage_sender_isempty(ts) bufalloc_isempty(&(ts)->out)
+
+extern int textmessage_put (textmessage_sender_t *, char const *, size_t) ;
+extern int textmessage_putv (textmessage_sender_t *, struct iovec const *, unsigned int) ;
+
+extern int textmessage_sender_flush (textmessage_sender_t *) ;
+extern int unixmessage_sender_timed_flush (textmessage_sender_t *, tain_t const *, tain_t *) ;
+#define textmessage_sender_timed_flush_g(ts, deadline) textmessage_sender_timed_flush(ts, (deadline), &STAMP)
+
+#define textmessage_send(ts, s, len) (textmessage_put(ts, s, len) && textmessage_sender_flush(ts))
+#define textmessage_sendv(ts, v, n) (textmessage_putv(ts, v, n) && textmessage_sender_flush(ts))
+#define textmessage_timed_send(ts, s, len, deadline, stamp) (textmessage_put(ts, s, len) && texxtmessage_sender_timed_flush(ts, deadline, stamp))
+#define textmessage_timed_sendv(ts, v, n, deadline, stamp) (textmessage_putv(ts, v, n) && texxtmessage_sender_timed_flush(ts, deadline, stamp))
+#define textmessage_timed_send_g(ts, s, len, deadline) textmessage_timed_send(ts, s, len, (deadline), &STAMP)
+#define textmessage_timed_sendv_g(ts, v, n, deadline) textmessage_timed_sendv(ts, v, n, (deadline), &STAMP)
+
+
+ /* Receiver */
+
+typedef struct textmessage_receiver_s textmessage_receiver_t, *textmessage_receiver_t_ref ;
+struct textmessage_receiver_s
+{
+ buffer in ;
+ stralloc indata ;
+ uint32_t wanted ;
+ uint32_t max ;
+} ;
+#define TEXTMESSAGE_RECEIVER_ZERO { .in = BUFFER_ZERO, .indata = STRALLOC_ZERO, .wanted = 0, .max = 0 }
+extern textmessage_receiver_t const textmessage_receiver_zero ;
+#define TEXTMESSAGE_RECEIVER_INIT(fd, buf, len, n) { .in = BUFFER_INIT(&buffer_read, (fd), buf, len), .indata = STRALLOC_ZERO, .wanted = 0, .max = n }
+
+extern int textmessage_receiver_init (textmessage_receiver_t *, int, char *, size_t, uint32_t) ;
+extern void textmessage_receiver_free (textmessage_receiver_t *) ;
+#define textmessage_receiver_fd(tr) buffer_fd(&(tr)->in)
+#define textmessage_receiver_isempty(tr) buffer_isempty(&(tr)->in)
+#define textmessage_receiver_isfull(tr) buffer_isfull(&(tr)->in)
+
+extern int textmessage_receiver_hasmsginbuf (textmessage_receiver_t const *) gccattr_pure ;
+
+extern int textmessage_receive (textmessage_receiver_t *, struct iovec *) ;
+extern int textmessage_timed_receive (textmessage_receiver_t *, struct iovec *, tain_t const *, tain_t *) ;
+#define textmessage_timed_receive_g(tr, s, max, deadline) textmessage_timed_receive(tr, s, max, (deadline), &STAMP)
+
+typedef int textmessage_handler_func_t (struct iovec const *, void *) ;
+typedef textmessage_handler_func_t *textmessage_handler_func_t_ref ;
+
+extern int textmessage_handle (textmessage_receiver_t *, textmessage_handler_func_t_ref, void *) ;
+extern int textmessage_timed_handle (textmessage_receiver_t *, textmessage_handler_func_t_ref, void *, tain_t const *, tain_t *) ;
+#define textmessage_timed_handle_g(tr, f, p, deadline) unixmessage_timed_handle(tr, f, p, (deadline), &STAMP)
+
+
+
+ /* Globals */
+
+extern textmessage_receiver_t textmessage_receiver_0_ ;
+#define textmessage_receiver_0 (&textmessage_receiver_0_)
+
+extern textmessage_sender_t textmessage_sender_1_ ;
+#define textmessage_sender_1 (&textmessage_sender_1_)
+
+extern textmessage_sender_t textmessage_sender_x_ ;
+#define textmessage_sender_x (&textmessage_sender_x_)
+
+#endif
diff --git a/src/include/skalibs/unixonacid.h b/src/include/skalibs/unixonacid.h
index 9ec3fe8..43bd695 100644
--- a/src/include/skalibs/unixonacid.h
+++ b/src/include/skalibs/unixonacid.h
@@ -5,6 +5,7 @@
#include <skalibs/unix-transactional.h>
#include <skalibs/unix-timed.h>
+#include <skalibs/textmessage.h>
#include <skalibs/unixmessage.h>
#include <skalibs/unixconnection.h>
#include <skalibs/kolbak.h>
diff --git a/src/include/skalibs/webipc.h b/src/include/skalibs/webipc.h
index 0ddd084..eba6f6b 100644
--- a/src/include/skalibs/webipc.h
+++ b/src/include/skalibs/webipc.h
@@ -13,7 +13,7 @@
#define IPCPATH_MAX 107
#include <sys/types.h>
-#include <skalibs/getpeereid.h>
+#include <skalibs/posixplz.h>
#include <skalibs/tai.h>
#include <skalibs/djbunix.h>