Welcome to little lamb

Code » qmdoc » commit 1b1d2e1

Move openat* and such files out (to limb)

author Olivier Brunel
2022-12-27 12:39:51 UTC
committer Olivier Brunel
2022-12-27 12:39:51 UTC
parent c26d44be213e878cfc8c5c6282e6be209a6be76f

Move openat* and such files out (to limb)

Makefile +3 -8
djbunix2.h +0 -15
main.c +2 -2
openat3.c +0 -11
openat4.c +0 -11
openat_append.c +0 -8
openat_create.c +0 -8
openat_excl.c +0 -8
openat_read.c +0 -8
openat_readb.c +0 -15
openat_trunc.c +0 -8
openat_write.c +0 -8
openatb_read.c +0 -8
output.c +0 -27
output.h +0 -24

diff --git a/Makefile b/Makefile
index d970d9e..25d1422 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,9 @@
-SRCS = main.c output.c md4c.c
-
-SRCS += openat3.c openat4.c openat_append.c openatb_read.c openat_create.c \
-		openat_excl.c openat_readb.c openat_read.c openat_trunc.c openat_write.c
-
+SRCS = main.c md4c.c
 OBJS = $(SRCS:.c=.o)
 DEPS = $(SRCS:.c=.d)
 
-CFLAGS = -g -O3 -Wall
-LDFLAGS = -L/lib/skalibs -lskarnet
-
+CFLAGS = -g -O3 -Wall -I./limb/include
+LDFLAGS = -L./limb -llimb -L/lib/skalibs -lskarnet
 all: qmdoc
 
 qmdoc: $(OBJS)
diff --git a/djbunix2.h b/djbunix2.h
deleted file mode 100644
index 9c38ab3..0000000
--- a/djbunix2.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef DJBUNIX2_H
-#define DJBUNIX2_H
-
-int openat3(int fd, const char *file, unsigned int flags);
-int openat4(int fd, const char *file, unsigned int flags, unsigned int mode);
-int openat_read(int fd, const char *file);
-int openatb_read(int fd, const char *file);
-int openat_readb(int fd, const char *file);
-int openat_excl(int fd, const char *file);
-int openat_append(int fd, const char *file);
-int openat_create(int fd, const char *file);
-int openat_trunc(int fd, const char *file);
-int openat_write(int fd, const char *file);
-
-#endif /* DJBUNIX2_H */
diff --git a/main.c b/main.c
index f1be0fa..223895d 100644
--- a/main.c
+++ b/main.c
@@ -12,10 +12,10 @@
 #include <skalibs/buffer.h>
 #include <skalibs/djbunix.h>
 #include <skalibs/uint32.h>
+#include <limb/output.h>
+#include <limb/djbunix2.h>
 #include <err.h>
 #include "qmdoc.h"
-#include "output.h"
-#include "djbunix2.h"
 #include "md4c.h"
 
 const char *PROG = "qmdoc";
diff --git a/openat3.c b/openat3.c
deleted file mode 100644
index d54b385..0000000
--- a/openat3.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <fcntl.h>
-#include <errno.h>
-
-int
-openat3(int fd, const char *file, unsigned int flags)
-{
-    int r;
-    do r = openat(fd, file, flags);
-    while ((r < 0 && errno == EINTR));
-    return r;
-}
diff --git a/openat4.c b/openat4.c
deleted file mode 100644
index 61c5100..0000000
--- a/openat4.c
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <fcntl.h>
-#include <errno.h>
-
-int
-openat4(int fd, const char *file, unsigned int flags, unsigned int mode)
-{
-    int r;
-    do r = openat(fd, file, flags, mode);
-    while ((r < 0 && errno == EINTR));
-    return r;
-}
diff --git a/openat_append.c b/openat_append.c
deleted file mode 100644
index 5ea9cab..0000000
--- a/openat_append.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <fcntl.h>
-#include "djbunix2.h"
-
-int
-openat_append(int fd, const char *file)
-{
-    return openat4(fd, file, O_WRONLY | O_CREAT | O_APPEND | O_NONBLOCK, 0666);
-}
diff --git a/openat_create.c b/openat_create.c
deleted file mode 100644
index 09a75e1..0000000
--- a/openat_create.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <fcntl.h>
-#include "djbunix2.h"
-
-int
-openat_create(int fd, const char *file)
-{
-    return openat4(fd, file, O_WRONLY | O_CREAT | O_NONBLOCK, 0666);
-}
diff --git a/openat_excl.c b/openat_excl.c
deleted file mode 100644
index 32ecfb5..0000000
--- a/openat_excl.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <fcntl.h>
-#include "djbunix2.h"
-
-int
-openat_excl(int fd, const char *file)
-{
-    return openat4(fd, file, O_WRONLY | O_CREAT | O_EXCL | O_NONBLOCK, 0666);
-}
diff --git a/openat_read.c b/openat_read.c
deleted file mode 100644
index 528a38b..0000000
--- a/openat_read.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <fcntl.h>
-#include "djbunix2.h"
-
-int
-openat_read(int fd, const char *file)
-{
-    return openat3(fd, file, O_RDONLY | O_NONBLOCK);
-}
diff --git a/openat_readb.c b/openat_readb.c
deleted file mode 100644
index 45539ea..0000000
--- a/openat_readb.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <skalibs/djbunix.h>
-#include <fcntl.h>
-#include "djbunix2.h"
-
-int
-openat_readb(int fd, const char *file)
-{
-    int ffd = openat_read(fd, file);
-    if (ffd < 0) return -1;
-    if (ndelay_off(ffd) < 0) {
-        fd_close(ffd);
-        return -1;
-    }
-    return ffd;
-}
diff --git a/openat_trunc.c b/openat_trunc.c
deleted file mode 100644
index 8efc820..0000000
--- a/openat_trunc.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <fcntl.h>
-#include "djbunix2.h"
-
-int
-openat_trunc(int fd, const char *file)
-{
-    return openat4(fd, file, O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, 0666);
-}
diff --git a/openat_write.c b/openat_write.c
deleted file mode 100644
index df6ae80..0000000
--- a/openat_write.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <fcntl.h>
-#include "djbunix2.h"
-
-int
-openat_write(int fd, const char *file)
-{
-    return openat3(fd, file, O_WRONLY | O_NONBLOCK);
-}
diff --git a/openatb_read.c b/openatb_read.c
deleted file mode 100644
index ce8d5a5..0000000
--- a/openatb_read.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <fcntl.h>
-#include "djbunix2.h"
-
-int
-openatb_read(int fd, const char *file)
-{
-    return openat3(fd, file, O_RDONLY);
-}
diff --git a/output.c b/output.c
deleted file mode 100644
index 8aca0ac..0000000
--- a/output.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include <skalibs/buffer.h>
-#include <skalibs/strerr2.h>
-#include <unistd.h> /* _exit() */
-#include "qmdoc.h" /* ERR_* */
-#include "output.h"
-
-void
-putb(int opts, const char *str, size_t len)
-{
-    buffer_t *b = (opts & PUT_ERR) ? buffer_2 : buffer_1;
-    if (buffer_put(b, str, len) < 0)
-        strerr_dief2x(ERR_MISC, "cannot print to ", (opts & PUT_ERR) ? "stderr" : "stdout");
-    if ((opts & PUT_NEWLINE) && buffer_put(b, "\n", 1) < 0)
-        strerr_dief2x(ERR_MISC, "cannot print to ", (opts & PUT_ERR) ? "stderr" : "stdout");
-    if ((opts & PUT_FLUSH) && !buffer_flush(b))
-        strerr_dief2x(ERR_MISC, "cannot flush to ", (opts & PUT_ERR) ? "stderr" : "stdout");
-}
-
-void
-outh(const char *help)
-{
-    outs("usage: ");
-    outs(PROG);
-    outs(" [OPTION..] FILE...\n\n");
-    outse(help);
-    _exit(ERR_NONE);
-}
diff --git a/output.h b/output.h
deleted file mode 100644
index a640a01..0000000
--- a/output.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef OUTPUT_H
-#define OUTPUT_H
-
-enum {
-    PUT_OUT     =  0, /* implied default else PUT_ERR is set */
-    PUT_ERR     = (1 << 0),
-    PUT_FLUSH   = (1 << 1),
-    PUT_NEWLINE = (1 << 2),
-};
-
-void putb(int opts, const char *str, size_t len);
-
-#define outb(s,l)       putb(PUT_OUT, s, l)
-#define outs(s)         outb(s, strlen(s))
-#define outbe(s,l)      putb(PUT_OUT | PUT_FLUSH | PUT_NEWLINE, s, l)
-#define outse(s)        outbe(s, strlen(s))
-void outh(const char *help);
-
-#define errb(s,l)       putb(PUT_ERR, s, l)
-#define errs(s)         errb(s, strlen(s))
-#define errbe(s,l)      putb(PUT_ERR | PUT_FLUSH | PUT_NEWLINE, s, l)
-#define errse(s)        errbe(s, strlen(s))
-
-#endif /* OUTPUT_H */