diff options
Diffstat (limited to 'src/libposixplz')
-rw-r--r-- | src/libposixplz/mkLtemp.c | 10 | ||||
-rw-r--r-- | src/libposixplz/mkbtemp.c | 21 | ||||
-rw-r--r-- | src/libposixplz/mkctemp.c | 21 | ||||
-rw-r--r-- | src/libposixplz/mkfiletemp.c | 22 | ||||
-rw-r--r-- | src/libposixplz/mklinktemp.c | 21 | ||||
-rw-r--r-- | src/libposixplz/mkltemp.c | 10 | ||||
-rw-r--r-- | src/libposixplz/mkptemp.c | 20 | ||||
-rw-r--r-- | src/libposixplz/posixplz-internal.h | 7 |
8 files changed, 132 insertions, 0 deletions
diff --git a/src/libposixplz/mkLtemp.c b/src/libposixplz/mkLtemp.c new file mode 100644 index 0000000..5c9ccb0 --- /dev/null +++ b/src/libposixplz/mkLtemp.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include <unistd.h> + +#include <skalibs/posixplz.h> + +int mkLtemp (char const *src, char *dst) +{ + return mklinktemp(src, dst, &link) ; +} diff --git a/src/libposixplz/mkbtemp.c b/src/libposixplz/mkbtemp.c new file mode 100644 index 0000000..c4c62df --- /dev/null +++ b/src/libposixplz/mkbtemp.c @@ -0,0 +1,21 @@ +/* ISC license. */ + +#include <sys/stat.h> + +#include <skalibs/djbunix.h> +#include <skalibs/posixplz.h> + +static int f (char const *fn, mode_t mode, void *data) +{ + dev_t *devp = data ; + int r = mknod(fn, (mode & 00777) | S_IFBLK, *devp) ; + if (r == -1) return -1 ; + r = open_readb(fn) ; + if (r == -1) unlink_void(fn) ; + return r ; +} + +int mkbtemp (char *s, mode_t mode, dev_t dev) +{ + return mkfiletemp(s, &f, mode, &dev) ; +} diff --git a/src/libposixplz/mkctemp.c b/src/libposixplz/mkctemp.c new file mode 100644 index 0000000..69035fb --- /dev/null +++ b/src/libposixplz/mkctemp.c @@ -0,0 +1,21 @@ +/* ISC license. */ + +#include <sys/stat.h> + +#include <skalibs/djbunix.h> +#include <skalibs/posixplz.h> + +static int f (char const *fn, mode_t mode, void *data) +{ + dev_t *devp = data ; + int r = mknod(fn, (mode & 00777) | S_IFCHR, *devp) ; + if (r == -1) return -1 ; + r = open_readb(fn) ; + if (r == -1) unlink_void(fn) ; + return r ; +} + +int mkctemp (char *s, mode_t mode, dev_t dev) +{ + return mkfiletemp(s, &f, mode, &dev) ; +} diff --git a/src/libposixplz/mkfiletemp.c b/src/libposixplz/mkfiletemp.c new file mode 100644 index 0000000..4eaf151 --- /dev/null +++ b/src/libposixplz/mkfiletemp.c @@ -0,0 +1,22 @@ +/* ISC license. */ + +#include <string.h> +#include <errno.h> + +#include <skalibs/surf.h> +#include <skalibs/posixplz.h> + +int mkfiletemp (char *s, createfunc_t_ref f, mode_t mode, void *data) +{ + size_t len = strlen(s) ; + size_t xlen = 0 ; + int r ; + for (; xlen < len ; xlen++) if (s[len - 1 - xlen] != 'X') break ; + if (xlen < 6) return (errno = EINVAL, -1) ; + do + { + autosurf_name(s + len - xlen, xlen) ; + r = (*f)(s, mode, data) ; + } while (r == -1 && errno == EEXIST) ; + return r ; +} diff --git a/src/libposixplz/mklinktemp.c b/src/libposixplz/mklinktemp.c new file mode 100644 index 0000000..d1bee4b --- /dev/null +++ b/src/libposixplz/mklinktemp.c @@ -0,0 +1,21 @@ +/* ISC license. */ + +#include <unistd.h> + +#include <skalibs/djbunix.h> +#include <skalibs/posixplz.h> + +#include "posixplz-internal.h" + +static int f (char const *dst, mode_t mode, void *data) +{ + linkarg_t *la = data ; + (void)mode ; + return (*la->lf)(la->src, dst) ; +} + +int mklinktemp (char const *src, char *dst, linkfunc_t_ref lf) +{ + linkarg_t la = { .lf = lf, .src = src } ; + return mkfiletemp(dst, &f, 0600, &la) ; +} diff --git a/src/libposixplz/mkltemp.c b/src/libposixplz/mkltemp.c new file mode 100644 index 0000000..2edec8e --- /dev/null +++ b/src/libposixplz/mkltemp.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include <unistd.h> + +#include <skalibs/posixplz.h> + +int mkltemp (char const *src, char *dst) +{ + return mklinktemp(src, dst, &symlink) ; +} diff --git a/src/libposixplz/mkptemp.c b/src/libposixplz/mkptemp.c new file mode 100644 index 0000000..42bc715 --- /dev/null +++ b/src/libposixplz/mkptemp.c @@ -0,0 +1,20 @@ +/* ISC license. */ + +#include <sys/stat.h> + +#include <skalibs/djbunix.h> +#include <skalibs/posixplz.h> + +static int f (char const *fn, mode_t mode, void *data) +{ + int r = mkfifo(fn, mode) ; + if (r == -1) return -1 ; + r = open_readb(fn) ; + if (r == -1) unlink_void(fn) ; + return r ; +} + +int mkptemp (char *s) +{ + return mkfiletemp(s, &f, 0600, 0) ; +} diff --git a/src/libposixplz/posixplz-internal.h b/src/libposixplz/posixplz-internal.h index c3da73a..544b020 100644 --- a/src/libposixplz/posixplz-internal.h +++ b/src/libposixplz/posixplz-internal.h @@ -3,6 +3,13 @@ #ifndef POSIXPLZ_INTERNAL_H #define POSIXPLZ_INTERNAL_H +typedef struct linkarg_s linkarg_t, *linkarg_t_ref ; +struct linkarg_s +{ + linkfunc_t_ref lf ; + char const *src ; +} ; + extern void execvep_internal (char const *, char const *const *, char const *const *, char const *) ; #endif |