1 |
commit: ae82b2f1cfeefa5bfb25344c7b30284b3063e020 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Mar 11 20:54:41 2019 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Mar 11 20:54:41 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=ae82b2f1 |
7 |
|
8 |
build: shuffle some code around |
9 |
|
10 |
Preparation of cleanup, try and move some code to better suiting places. |
11 |
|
12 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
13 |
|
14 |
.depend | 2 +- |
15 |
Makefile.am | 1 - |
16 |
libq/Makefile | 9 --------- |
17 |
libq/atom_explode.c | 12 ++++++++--- |
18 |
libq/basename.c | 4 +++- |
19 |
libq/colors.c | 8 ++++++++ |
20 |
libq/compat.c | 35 -------------------------------- |
21 |
libq/copy_file.c | 33 ------------------------------ |
22 |
libq/libq.c | 12 ++--------- |
23 |
libq/safe_io.c | 37 +++++++++++++++++++++++++++++++-- |
24 |
porting.h | 55 +++++++++++++++++++++++++++++++++++++++++++------- |
25 |
tests/copy_file/test.c | 1 + |
26 |
12 files changed, 107 insertions(+), 102 deletions(-) |
27 |
|
28 |
diff --git a/.depend b/.depend |
29 |
index d5d2228..3f941ba 100644 |
30 |
--- a/.depend |
31 |
+++ b/.depend |
32 |
@@ -1,6 +1,6 @@ |
33 |
main.o: main.c porting.h main.h libq/libq.c libq/busybox.h libq/i18n.h \ |
34 |
libq/libq.h libq/colors.c libq/xmalloc.c libq/xasprintf.c libq/hash_fd.c \ |
35 |
- libq/md5_sha1_sum.c libq/human_readable.c libq/rmspace.c libq/compat.c \ |
36 |
+ libq/md5_sha1_sum.c libq/human_readable.c libq/rmspace.c \ |
37 |
libq/copy_file.c libq/safe_io.c libq/xchdir.c libq/xmkdir.c \ |
38 |
libq/xregex.c libq/xsystem.c libq/xarray.c libq/atom_explode.c \ |
39 |
libq/atom_compare.c libq/basename.c libq/scandirat.c libq/prelink.c \ |
40 |
|
41 |
diff --git a/Makefile.am b/Makefile.am |
42 |
index 2e6f985..8252f61 100644 |
43 |
--- a/Makefile.am |
44 |
+++ b/Makefile.am |
45 |
@@ -106,7 +106,6 @@ EXTRA_DIST += \ |
46 |
libq/basename.c \ |
47 |
libq/busybox.h \ |
48 |
libq/colors.c \ |
49 |
- libq/compat.c \ |
50 |
libq/copy_file.c \ |
51 |
libq/hash_fd.c \ |
52 |
libq/human_readable.c \ |
53 |
|
54 |
diff --git a/libq/Makefile b/libq/Makefile |
55 |
deleted file mode 100644 |
56 |
index c1f3f62..0000000 |
57 |
--- a/libq/Makefile |
58 |
+++ /dev/null |
59 |
@@ -1,9 +0,0 @@ |
60 |
-all: |
61 |
- |
62 |
-libq: |
63 |
- $(CC) -shared -fPIC $(CFLAGS) -o libq.so.0 libq.c -Dargv0=\"libq\" -D_LIB_Q |
64 |
- |
65 |
-%: |
66 |
- $(MAKE) -C .. $@ |
67 |
- |
68 |
-.PHONY: all libq |
69 |
|
70 |
diff --git a/libq/atom_explode.c b/libq/atom_explode.c |
71 |
index de42103..8b4ff4a 100644 |
72 |
--- a/libq/atom_explode.c |
73 |
+++ b/libq/atom_explode.c |
74 |
@@ -7,15 +7,21 @@ |
75 |
* Copyright 2018- Fabian Groffen - <grobian@g.o> |
76 |
*/ |
77 |
|
78 |
-typedef enum { VER_ALPHA=0, VER_BETA, VER_PRE, VER_RC, VER_NORM, VER_P } atom_suffixes; |
79 |
-const char * const atom_suffixes_str[] = { "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p" }; |
80 |
+typedef enum { |
81 |
+ VER_ALPHA=0, VER_BETA, VER_PRE, VER_RC, VER_NORM, VER_P |
82 |
+} atom_suffixes; |
83 |
+const char * const atom_suffixes_str[] = { |
84 |
+ "_alpha", "_beta", "_pre", "_rc", "_/*bogus*/", "_p" |
85 |
+}; |
86 |
|
87 |
typedef struct { |
88 |
atom_suffixes suffix; |
89 |
uint64_t sint; |
90 |
} atom_suffix; |
91 |
|
92 |
-const char * const atom_op_str[] = { "", ">", ">=", "=", "<=", "<", "~", "!", "!!", "*" }; |
93 |
+const char * const atom_op_str[] = { |
94 |
+ "", ">", ">=", "=", "<=", "<", "~", "!", "!!", "*" |
95 |
+}; |
96 |
typedef enum { |
97 |
/* */ ATOM_OP_NONE = 0, |
98 |
/* > */ ATOM_OP_NEWER, |
99 |
|
100 |
diff --git a/libq/basename.c b/libq/basename.c |
101 |
index 2a3b2e6..4836fd7 100644 |
102 |
--- a/libq/basename.c |
103 |
+++ b/libq/basename.c |
104 |
@@ -1,6 +1,8 @@ |
105 |
/* |
106 |
- * Copyright 2014-2019 Gentoo Foundation |
107 |
+ * Copyright 2010-2019 Gentoo Foundation |
108 |
* Distributed under the terms of the GNU General Public License v2 |
109 |
+ * |
110 |
+ * Copyright 2010-2014 Mike Frysinger - <vapier@g.o> |
111 |
*/ |
112 |
|
113 |
/* our own basename which does not modify its input */ |
114 |
|
115 |
diff --git a/libq/colors.c b/libq/colors.c |
116 |
index 5f252b6..620e9da 100644 |
117 |
--- a/libq/colors.c |
118 |
+++ b/libq/colors.c |
119 |
@@ -1,3 +1,11 @@ |
120 |
+/* |
121 |
+ * Copyright 2005-2019 Gentoo Foundation |
122 |
+ * Distributed under the terms of the GNU General Public License v2 |
123 |
+ * |
124 |
+ * Copyright 2005-2010 Ned Ludd - <solar@g.o> |
125 |
+ * Copyright 2005-2014 Mike Frysinger - <vapier@g.o> |
126 |
+ * Copyright 2019- Fabian Groffen - <grobian@g.o> |
127 |
+ */ |
128 |
|
129 |
/* color constants */ |
130 |
#ifdef OPTIMIZE_FOR_SIZE |
131 |
|
132 |
diff --git a/libq/compat.c b/libq/compat.c |
133 |
deleted file mode 100644 |
134 |
index 95cb7a7..0000000 |
135 |
--- a/libq/compat.c |
136 |
+++ /dev/null |
137 |
@@ -1,35 +0,0 @@ |
138 |
-/* Solaris compatible code */ |
139 |
-#ifdef __sun__ |
140 |
- |
141 |
-#include <sys/dklabel.h> |
142 |
- |
143 |
-#define S_BLKSIZE DK_DEVID_BLKSIZE |
144 |
- |
145 |
-#elif defined(__hpux__) || defined(__MINT__) |
146 |
- /* must not include both dir.h and dirent.h on hpux11..11 & FreeMiNT */ |
147 |
-#elif defined(__linux__) |
148 |
- /* Linux systems do not need sys/dir.h as they are generally POSIX sane */ |
149 |
-#else /* __sun__ */ |
150 |
-# include <sys/dir.h> |
151 |
-#endif |
152 |
- |
153 |
-/* AIX */ |
154 |
-#ifdef _AIX |
155 |
-# include <sys/stat.h> |
156 |
-# define S_BLKSIZE DEV_BSIZE |
157 |
-#endif |
158 |
- |
159 |
-/* Windows Interix */ |
160 |
-#ifdef __INTERIX |
161 |
-# define S_BLKSIZE S_BLOCK_SIZE |
162 |
-#endif |
163 |
- |
164 |
-/* HP-UX */ |
165 |
-#ifdef __hpux |
166 |
-# define S_BLKSIZE st.st_blksize |
167 |
-#endif |
168 |
- |
169 |
-/* Everyone else */ |
170 |
-#ifndef S_BLKSIZE |
171 |
-# define S_BLKSIZE 512 |
172 |
-#endif |
173 |
|
174 |
diff --git a/libq/copy_file.c b/libq/copy_file.c |
175 |
index 4230b73..bf934f6 100644 |
176 |
--- a/libq/copy_file.c |
177 |
+++ b/libq/copy_file.c |
178 |
@@ -1,36 +1,3 @@ |
179 |
-static ssize_t safe_read(int fd, void *buf, size_t len) |
180 |
-{ |
181 |
- ssize_t ret; |
182 |
- |
183 |
- while (1) { |
184 |
- ret = read(fd, buf, len); |
185 |
- if (ret >= 0) |
186 |
- break; |
187 |
- else if (errno != EINTR) |
188 |
- break; |
189 |
- } |
190 |
- |
191 |
- return ret; |
192 |
-} |
193 |
- |
194 |
-static ssize_t safe_write(int fd, const void *buf, size_t len) |
195 |
-{ |
196 |
- ssize_t ret; |
197 |
- |
198 |
- while (len) { |
199 |
- ret = write(fd, buf, len); |
200 |
- if (ret < 0) { |
201 |
- if (errno == EINTR) |
202 |
- continue; |
203 |
- return -1; |
204 |
- } |
205 |
- buf += ret; |
206 |
- len -= ret; |
207 |
- } |
208 |
- |
209 |
- return ret; |
210 |
-} |
211 |
- |
212 |
static int copy_file_fd(int fd_src, int fd_dst) |
213 |
{ |
214 |
ssize_t rcnt, wcnt; |
215 |
|
216 |
diff --git a/libq/libq.c b/libq/libq.c |
217 |
index a9e5b6a..1861fad 100644 |
218 |
--- a/libq/libq.c |
219 |
+++ b/libq/libq.c |
220 |
@@ -1,5 +1,5 @@ |
221 |
/* |
222 |
- * Copyright 2005-2018 Gentoo Foundation |
223 |
+ * Copyright 2005-2019 Gentoo Foundation |
224 |
* Distributed under the terms of the GNU General Public License v2 |
225 |
* |
226 |
* Copyright 2005-2008 Ned Ludd - <solar@g.o> |
227 |
@@ -7,13 +7,6 @@ |
228 |
* Copyright 2018- Fabian Groffen - <grobian@g.o> |
229 |
*/ |
230 |
|
231 |
-#if defined(__linux__) |
232 |
-# include <endian.h> |
233 |
-# include <byteswap.h> |
234 |
-#elif defined(__FreeBSD__) |
235 |
-# include <sys/endian.h> |
236 |
-#endif |
237 |
- |
238 |
/* busybox imports */ |
239 |
#include "busybox.h" |
240 |
#include "i18n.h" |
241 |
@@ -25,10 +18,9 @@ |
242 |
#include "md5_sha1_sum.c" |
243 |
#include "human_readable.c" |
244 |
#include "rmspace.c" |
245 |
-#include "compat.c" |
246 |
|
247 |
-#include "copy_file.c" |
248 |
#include "safe_io.c" |
249 |
+#include "copy_file.c" |
250 |
#include "xchdir.c" |
251 |
#include "xmkdir.c" |
252 |
#include "xregex.c" |
253 |
|
254 |
diff --git a/libq/safe_io.c b/libq/safe_io.c |
255 |
index da5d695..3f234d6 100644 |
256 |
--- a/libq/safe_io.c |
257 |
+++ b/libq/safe_io.c |
258 |
@@ -1,7 +1,7 @@ |
259 |
/* |
260 |
- * utility funcs |
261 |
+ * "safe" versions of read/write, dealing with interrupts |
262 |
* |
263 |
- * Copyright 2005-2018 Gentoo Foundation |
264 |
+ * Copyright 2005-2019 Gentoo Foundation |
265 |
* Distributed under the terms of the GNU General Public License v2 |
266 |
*/ |
267 |
|
268 |
@@ -34,3 +34,36 @@ safe_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) |
269 |
return ret; |
270 |
} |
271 |
#define fwrite safe_fwrite |
272 |
+ |
273 |
+static ssize_t safe_read(int fd, void *buf, size_t len) |
274 |
+{ |
275 |
+ ssize_t ret; |
276 |
+ |
277 |
+ while (1) { |
278 |
+ ret = read(fd, buf, len); |
279 |
+ if (ret >= 0) |
280 |
+ break; |
281 |
+ else if (errno != EINTR) |
282 |
+ break; |
283 |
+ } |
284 |
+ |
285 |
+ return ret; |
286 |
+} |
287 |
+ |
288 |
+static ssize_t safe_write(int fd, const void *buf, size_t len) |
289 |
+{ |
290 |
+ ssize_t ret; |
291 |
+ |
292 |
+ while (len) { |
293 |
+ ret = write(fd, buf, len); |
294 |
+ if (ret < 0) { |
295 |
+ if (errno == EINTR) |
296 |
+ continue; |
297 |
+ return -1; |
298 |
+ } |
299 |
+ buf += ret; |
300 |
+ len -= ret; |
301 |
+ } |
302 |
+ |
303 |
+ return ret; |
304 |
+} |
305 |
|
306 |
diff --git a/porting.h b/porting.h |
307 |
index 9239897..97a45c7 100644 |
308 |
--- a/porting.h |
309 |
+++ b/porting.h |
310 |
@@ -1,9 +1,10 @@ |
311 |
/* |
312 |
- * Copyright 2005-2018 Gentoo Foundation |
313 |
+ * Copyright 2005-2019 Gentoo Foundation |
314 |
* Distributed under the terms of the GNU General Public License v2 |
315 |
* |
316 |
* Copyright 2005-2008 Ned Ludd - <solar@g.o> |
317 |
* Copyright 2005-2014 Mike Frysinger - <vapier@g.o> |
318 |
+ * Copyright 2018- Fabian Groffen - <grobian@g.o> |
319 |
* |
320 |
* All the junk in one trunk! |
321 |
*/ |
322 |
@@ -55,6 +56,46 @@ |
323 |
#include <libproc.h> |
324 |
#endif |
325 |
|
326 |
+#if defined(__linux__) |
327 |
+# include <endian.h> |
328 |
+# include <byteswap.h> |
329 |
+#elif defined(__FreeBSD__) |
330 |
+# include <sys/endian.h> |
331 |
+#endif |
332 |
+ |
333 |
+/* Solaris */ |
334 |
+#if defined(__sun) && defined(__SVR4) |
335 |
+# include <sys/dklabel.h> |
336 |
+# define S_BLKSIZE DK_DEVID_BLKSIZE |
337 |
+#elif defined(__hpux__) || defined(__MINT__) |
338 |
+/* must not include both dir.h and dirent.h on hpux11..11 & FreeMiNT */ |
339 |
+#elif defined(__linux__) |
340 |
+/* Linux systems do not need sys/dir.h as they are generally POSIX sane */ |
341 |
+#else |
342 |
+# include <sys/dir.h> |
343 |
+#endif |
344 |
+ |
345 |
+/* AIX */ |
346 |
+#ifdef _AIX |
347 |
+# include <sys/stat.h> |
348 |
+# define S_BLKSIZE DEV_BSIZE |
349 |
+#endif |
350 |
+ |
351 |
+/* Windows Interix */ |
352 |
+#ifdef __INTERIX |
353 |
+# define S_BLKSIZE S_BLOCK_SIZE |
354 |
+#endif |
355 |
+ |
356 |
+/* HP-UX */ |
357 |
+#ifdef __hpux |
358 |
+# define S_BLKSIZE st.st_blksize |
359 |
+#endif |
360 |
+ |
361 |
+/* Everyone else */ |
362 |
+#ifndef S_BLKSIZE |
363 |
+# define S_BLKSIZE 512 |
364 |
+#endif |
365 |
+ |
366 |
#if defined(__sun) && defined(__SVR4) |
367 |
/* workaround non-const defined name in option struct, such that we |
368 |
* don't get a zillion of warnings */ |
369 |
@@ -70,7 +111,7 @@ struct option { |
370 |
extern int getopt_long(int, char * const *, const char *, |
371 |
const struct option *, int *); |
372 |
#else |
373 |
-#include <getopt.h> |
374 |
+# include <getopt.h> |
375 |
#endif |
376 |
|
377 |
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr))) |
378 |
@@ -80,22 +121,22 @@ extern int getopt_long(int, char * const *, const char *, |
379 |
#endif |
380 |
|
381 |
#ifndef MIN |
382 |
-#define MIN(x, y) ((x) < (y) ? (x) : (y)) |
383 |
+# define MIN(x, y) ((x) < (y) ? (x) : (y)) |
384 |
#endif |
385 |
#ifndef MAX |
386 |
-#define MAX(x, y) ((x) < (y) ? (y) : (x)) |
387 |
+# define MAX(x, y) ((x) < (y) ? (y) : (x)) |
388 |
#endif |
389 |
|
390 |
/* Easy enough to glue to older versions */ |
391 |
#ifndef O_CLOEXEC |
392 |
-#define O_CLOEXEC 0 |
393 |
+# define O_CLOEXEC 0 |
394 |
#endif |
395 |
#ifndef O_PATH |
396 |
-#define O_PATH 0 |
397 |
+# define O_PATH 0 |
398 |
#endif |
399 |
|
400 |
#ifndef CONFIG_EPREFIX |
401 |
-#define CONFIG_EPREFIX "/" |
402 |
+# define CONFIG_EPREFIX "/" |
403 |
#endif |
404 |
|
405 |
#define likely(x) __builtin_expect((x), 1) |
406 |
|
407 |
diff --git a/tests/copy_file/test.c b/tests/copy_file/test.c |
408 |
index 72b1c77..d0f164d 100644 |
409 |
--- a/tests/copy_file/test.c |
410 |
+++ b/tests/copy_file/test.c |
411 |
@@ -5,6 +5,7 @@ |
412 |
|
413 |
#include "tests/tests.h" |
414 |
|
415 |
+#include "libq/safe_io.c" |
416 |
#include "libq/copy_file.c" |
417 |
|
418 |
static int src_fd, dst_fd; |