aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Groffen <grobian@gentoo.org>2019-03-11 21:54:41 +0100
committerFabian Groffen <grobian@gentoo.org>2019-03-11 21:54:41 +0100
commitae82b2f1cfeefa5bfb25344c7b30284b3063e020 (patch)
tree9f7e199b306fd2a774141d8b3c31586d4ec8ead1
parentset: fix signedness warnings (diff)
downloadportage-utils-ae82b2f1.tar.gz
portage-utils-ae82b2f1.tar.bz2
portage-utils-ae82b2f1.zip
build: shuffle some code around
Preparation of cleanup, try and move some code to better suiting places. Signed-off-by: Fabian Groffen <grobian@gentoo.org>
-rw-r--r--.depend2
-rw-r--r--Makefile.am1
-rw-r--r--libq/Makefile9
-rw-r--r--libq/atom_explode.c12
-rw-r--r--libq/basename.c4
-rw-r--r--libq/colors.c8
-rw-r--r--libq/compat.c35
-rw-r--r--libq/copy_file.c33
-rw-r--r--libq/libq.c12
-rw-r--r--libq/safe_io.c37
-rw-r--r--porting.h55
-rw-r--r--tests/copy_file/test.c1
12 files changed, 107 insertions, 102 deletions
diff --git a/.depend b/.depend
index d5d2228..3f941ba 100644
--- a/.depend
+++ b/.depend
@@ -1,6 +1,6 @@
main.o: main.c porting.h main.h libq/libq.c libq/busybox.h libq/i18n.h \
libq/libq.h libq/colors.c libq/xmalloc.c libq/xasprintf.c libq/hash_fd.c \
- libq/md5_sha1_sum.c libq/human_readable.c libq/rmspace.c libq/compat.c \
+ libq/md5_sha1_sum.c libq/human_readable.c libq/rmspace.c \
libq/copy_file.c libq/safe_io.c libq/xchdir.c libq/xmkdir.c \
libq/xregex.c libq/xsystem.c libq/xarray.c libq/atom_explode.c \
libq/atom_compare.c libq/basename.c libq/scandirat.c libq/prelink.c \
diff --git a/Makefile.am b/Makefile.am
index 2e6f985..8252f61 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -106,7 +106,6 @@ EXTRA_DIST += \
libq/basename.c \
libq/busybox.h \
libq/colors.c \
- libq/compat.c \
libq/copy_file.c \
libq/hash_fd.c \
libq/human_readable.c \
diff --git a/libq/Makefile b/libq/Makefile
deleted file mode 100644
index c1f3f62..0000000
--- a/libq/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-all:
-
-libq:
- $(CC) -shared -fPIC $(CFLAGS) -o libq.so.0 libq.c -Dargv0=\"libq\" -D_LIB_Q
-
-%:
- $(MAKE) -C .. $@
-
-.PHONY: all libq
diff --git a/libq/atom_explode.c b/libq/atom_explode.c
index de42103..8b4ff4a 100644
--- a/libq/atom_explode.c
+++ b/libq/atom_explode.c
@@ -7,15 +7,21 @@
* Copyright 2018- Fabian Groffen - <grobian@gentoo.org>
*/
-typedef enum { VER_ALPHA=0, VER_BETA, VER_PRE, VER_RC, VER_NORM, VER_P } atom_suffixes;
-const char * const atom_suffixes_str[] = { "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p" };
+typedef enum {
+ VER_ALPHA=0, VER_BETA, VER_PRE, VER_RC, VER_NORM, VER_P
+} atom_suffixes;
+const char * const atom_suffixes_str[] = {
+ "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p"
+};
typedef struct {
atom_suffixes suffix;
uint64_t sint;
} atom_suffix;
-const char * const atom_op_str[] = { "", ">", ">=", "=", "<=", "<", "~", "!", "!!", "*" };
+const char * const atom_op_str[] = {
+ "", ">", ">=", "=", "<=", "<", "~", "!", "!!", "*"
+};
typedef enum {
/* */ ATOM_OP_NONE = 0,
/* > */ ATOM_OP_NEWER,
diff --git a/libq/basename.c b/libq/basename.c
index 2a3b2e6..4836fd7 100644
--- a/libq/basename.c
+++ b/libq/basename.c
@@ -1,6 +1,8 @@
/*
- * Copyright 2014-2019 Gentoo Foundation
+ * Copyright 2010-2019 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
+ *
+ * Copyright 2010-2014 Mike Frysinger - <vapier@gentoo.org>
*/
/* our own basename which does not modify its input */
diff --git a/libq/colors.c b/libq/colors.c
index 5f252b6..620e9da 100644
--- a/libq/colors.c
+++ b/libq/colors.c
@@ -1,3 +1,11 @@
+/*
+ * Copyright 2005-2019 Gentoo Foundation
+ * Distributed under the terms of the GNU General Public License v2
+ *
+ * Copyright 2005-2010 Ned Ludd - <solar@gentoo.org>
+ * Copyright 2005-2014 Mike Frysinger - <vapier@gentoo.org>
+ * Copyright 2019- Fabian Groffen - <grobian@gentoo.org>
+ */
/* color constants */
#ifdef OPTIMIZE_FOR_SIZE
diff --git a/libq/compat.c b/libq/compat.c
deleted file mode 100644
index 95cb7a7..0000000
--- a/libq/compat.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Solaris compatible code */
-#ifdef __sun__
-
-#include <sys/dklabel.h>
-
-#define S_BLKSIZE DK_DEVID_BLKSIZE
-
-#elif defined(__hpux__) || defined(__MINT__)
- /* must not include both dir.h and dirent.h on hpux11..11 & FreeMiNT */
-#elif defined(__linux__)
- /* Linux systems do not need sys/dir.h as they are generally POSIX sane */
-#else /* __sun__ */
-# include <sys/dir.h>
-#endif
-
-/* AIX */
-#ifdef _AIX
-# include <sys/stat.h>
-# define S_BLKSIZE DEV_BSIZE
-#endif
-
-/* Windows Interix */
-#ifdef __INTERIX
-# define S_BLKSIZE S_BLOCK_SIZE
-#endif
-
-/* HP-UX */
-#ifdef __hpux
-# define S_BLKSIZE st.st_blksize
-#endif
-
-/* Everyone else */
-#ifndef S_BLKSIZE
-# define S_BLKSIZE 512
-#endif
diff --git a/libq/copy_file.c b/libq/copy_file.c
index 4230b73..bf934f6 100644
--- a/libq/copy_file.c
+++ b/libq/copy_file.c
@@ -1,36 +1,3 @@
-static ssize_t safe_read(int fd, void *buf, size_t len)
-{
- ssize_t ret;
-
- while (1) {
- ret = read(fd, buf, len);
- if (ret >= 0)
- break;
- else if (errno != EINTR)
- break;
- }
-
- return ret;
-}
-
-static ssize_t safe_write(int fd, const void *buf, size_t len)
-{
- ssize_t ret;
-
- while (len) {
- ret = write(fd, buf, len);
- if (ret < 0) {
- if (errno == EINTR)
- continue;
- return -1;
- }
- buf += ret;
- len -= ret;
- }
-
- return ret;
-}
-
static int copy_file_fd(int fd_src, int fd_dst)
{
ssize_t rcnt, wcnt;
diff --git a/libq/libq.c b/libq/libq.c
index a9e5b6a..1861fad 100644
--- a/libq/libq.c
+++ b/libq/libq.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2005-2018 Gentoo Foundation
+ * Copyright 2005-2019 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
*
* Copyright 2005-2008 Ned Ludd - <solar@gentoo.org>
@@ -7,13 +7,6 @@
* Copyright 2018- Fabian Groffen - <grobian@gentoo.org>
*/
-#if defined(__linux__)
-# include <endian.h>
-# include <byteswap.h>
-#elif defined(__FreeBSD__)
-# include <sys/endian.h>
-#endif
-
/* busybox imports */
#include "busybox.h"
#include "i18n.h"
@@ -25,10 +18,9 @@
#include "md5_sha1_sum.c"
#include "human_readable.c"
#include "rmspace.c"
-#include "compat.c"
-#include "copy_file.c"
#include "safe_io.c"
+#include "copy_file.c"
#include "xchdir.c"
#include "xmkdir.c"
#include "xregex.c"
diff --git a/libq/safe_io.c b/libq/safe_io.c
index da5d695..3f234d6 100644
--- a/libq/safe_io.c
+++ b/libq/safe_io.c
@@ -1,7 +1,7 @@
/*
- * utility funcs
+ * "safe" versions of read/write, dealing with interrupts
*
- * Copyright 2005-2018 Gentoo Foundation
+ * Copyright 2005-2019 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
*/
@@ -34,3 +34,36 @@ safe_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
return ret;
}
#define fwrite safe_fwrite
+
+static ssize_t safe_read(int fd, void *buf, size_t len)
+{
+ ssize_t ret;
+
+ while (1) {
+ ret = read(fd, buf, len);
+ if (ret >= 0)
+ break;
+ else if (errno != EINTR)
+ break;
+ }
+
+ return ret;
+}
+
+static ssize_t safe_write(int fd, const void *buf, size_t len)
+{
+ ssize_t ret;
+
+ while (len) {
+ ret = write(fd, buf, len);
+ if (ret < 0) {
+ if (errno == EINTR)
+ continue;
+ return -1;
+ }
+ buf += ret;
+ len -= ret;
+ }
+
+ return ret;
+}
diff --git a/porting.h b/porting.h
index 9239897..97a45c7 100644
--- a/porting.h
+++ b/porting.h
@@ -1,9 +1,10 @@
/*
- * Copyright 2005-2018 Gentoo Foundation
+ * Copyright 2005-2019 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
*
* Copyright 2005-2008 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2014 Mike Frysinger - <vapier@gentoo.org>
+ * Copyright 2018- Fabian Groffen - <grobian@gentoo.org>
*
* All the junk in one trunk!
*/
@@ -55,6 +56,46 @@
#include <libproc.h>
#endif
+#if defined(__linux__)
+# include <endian.h>
+# include <byteswap.h>
+#elif defined(__FreeBSD__)
+# include <sys/endian.h>
+#endif
+
+/* Solaris */
+#if defined(__sun) && defined(__SVR4)
+# include <sys/dklabel.h>
+# define S_BLKSIZE DK_DEVID_BLKSIZE
+#elif defined(__hpux__) || defined(__MINT__)
+/* must not include both dir.h and dirent.h on hpux11..11 & FreeMiNT */
+#elif defined(__linux__)
+/* Linux systems do not need sys/dir.h as they are generally POSIX sane */
+#else
+# include <sys/dir.h>
+#endif
+
+/* AIX */
+#ifdef _AIX
+# include <sys/stat.h>
+# define S_BLKSIZE DEV_BSIZE
+#endif
+
+/* Windows Interix */
+#ifdef __INTERIX
+# define S_BLKSIZE S_BLOCK_SIZE
+#endif
+
+/* HP-UX */
+#ifdef __hpux
+# define S_BLKSIZE st.st_blksize
+#endif
+
+/* Everyone else */
+#ifndef S_BLKSIZE
+# define S_BLKSIZE 512
+#endif
+
#if defined(__sun) && defined(__SVR4)
/* workaround non-const defined name in option struct, such that we
* don't get a zillion of warnings */
@@ -70,7 +111,7 @@ struct option {
extern int getopt_long(int, char * const *, const char *,
const struct option *, int *);
#else
-#include <getopt.h>
+# include <getopt.h>
#endif
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr)))
@@ -80,22 +121,22 @@ extern int getopt_long(int, char * const *, const char *,
#endif
#ifndef MIN
-#define MIN(x, y) ((x) < (y) ? (x) : (y))
+# define MIN(x, y) ((x) < (y) ? (x) : (y))
#endif
#ifndef MAX
-#define MAX(x, y) ((x) < (y) ? (y) : (x))
+# define MAX(x, y) ((x) < (y) ? (y) : (x))
#endif
/* Easy enough to glue to older versions */
#ifndef O_CLOEXEC
-#define O_CLOEXEC 0
+# define O_CLOEXEC 0
#endif
#ifndef O_PATH
-#define O_PATH 0
+# define O_PATH 0
#endif
#ifndef CONFIG_EPREFIX
-#define CONFIG_EPREFIX "/"
+# define CONFIG_EPREFIX "/"
#endif
#define likely(x) __builtin_expect((x), 1)
diff --git a/tests/copy_file/test.c b/tests/copy_file/test.c
index 72b1c77..d0f164d 100644
--- a/tests/copy_file/test.c
+++ b/tests/copy_file/test.c
@@ -5,6 +5,7 @@
#include "tests/tests.h"
+#include "libq/safe_io.c"
#include "libq/copy_file.c"
static int src_fd, dst_fd;