Lines 1-109
Link Here
|
1 |
--- /dev/null |
|
|
2 |
+++ b/lib/read_all.h |
3 |
@@ -0,0 +1,32 @@ |
4 |
+/* |
5 |
+ * read_all - a read variant that masks EAGAIN and EINTR. |
6 |
+ * This function tries hard to make sure to read the complete requested |
7 |
+ * length, and if it hits EOF while reading, it returns 0. |
8 |
+ * |
9 |
+ * Originally written by Theodore Y. Ts'o. |
10 |
+ * Factored out from misc/uuidd.c and lib/uuid/gen_uuid.c |
11 |
+ * and bugfixed by Matthias Andree, 2009. |
12 |
+ */ |
13 |
+ |
14 |
+ssize_t read_all(int fd, char *buf, size_t count) |
15 |
+{ |
16 |
+ ssize_t ret; |
17 |
+ ssize_t c = 0; |
18 |
+ |
19 |
+ memset(buf, 0, count); |
20 |
+ while (count > 0) { |
21 |
+ ret = read(fd, buf, count); |
22 |
+ if (ret == -1) { |
23 |
+ if ((errno == EAGAIN) || (errno == EINTR)) |
24 |
+ continue; |
25 |
+ return -1; |
26 |
+ } |
27 |
+ if (ret == 0) { |
28 |
+ return c; |
29 |
+ } |
30 |
+ count -= ret; |
31 |
+ buf += ret; |
32 |
+ c += ret; |
33 |
+ } |
34 |
+ return c; |
35 |
+} |
36 |
--- a/lib/uuid/Makefile.in |
37 |
+++ b/lib/uuid/Makefile.in |
38 |
@@ -190,7 +190,7 @@ clear.o: $(srcdir)/clear.c $(srcdir)/uuidP.h $(srcdir)/uuid.h |
39 |
compare.o: $(srcdir)/compare.c $(srcdir)/uuidP.h $(srcdir)/uuid.h |
40 |
copy.o: $(srcdir)/copy.c $(srcdir)/uuidP.h $(srcdir)/uuid.h |
41 |
gen_uuid.o: $(srcdir)/gen_uuid.c $(srcdir)/uuidP.h $(srcdir)/uuid.h \ |
42 |
- $(srcdir)/uuidd.h |
43 |
+ $(srcdir)/uuidd.h $(top_srcdir)/lib/read_all.h |
44 |
isnull.o: $(srcdir)/isnull.c $(srcdir)/uuidP.h $(srcdir)/uuid.h |
45 |
pack.o: $(srcdir)/pack.c $(srcdir)/uuidP.h $(srcdir)/uuid.h |
46 |
parse.o: $(srcdir)/parse.c $(srcdir)/uuidP.h $(srcdir)/uuid.h |
47 |
--- a/lib/uuid/gen_uuid.c |
48 |
+++ b/lib/uuid/gen_uuid.c |
49 |
@@ -415,25 +415,11 @@ try_again: |
50 |
return 0; |
51 |
} |
52 |
|
53 |
-static ssize_t read_all(int fd, char *buf, size_t count) |
54 |
-{ |
55 |
- ssize_t ret; |
56 |
- ssize_t c = 0; |
57 |
- |
58 |
- memset(buf, 0, count); |
59 |
- while (count > 0) { |
60 |
- ret = read(fd, buf, count); |
61 |
- if (ret < 0) { |
62 |
- if ((errno == EAGAIN) || (errno == EINTR)) |
63 |
- continue; |
64 |
- return -1; |
65 |
- } |
66 |
- count -= ret; |
67 |
- buf += ret; |
68 |
- c += ret; |
69 |
- } |
70 |
- return c; |
71 |
-} |
72 |
+/* |
73 |
+ * Import read_all function and make it static. |
74 |
+ */ |
75 |
+static |
76 |
+#include "read_all.h" |
77 |
|
78 |
/* |
79 |
* Close all file descriptors |
80 |
--- a/misc/uuidd.c |
81 |
+++ b/misc/uuidd.c |
82 |
@@ -85,25 +85,8 @@ static void create_daemon(void) |
83 |
die("setreuid"); |
84 |
} |
85 |
|
86 |
-static int read_all(int fd, char *buf, size_t count) |
87 |
-{ |
88 |
- ssize_t ret; |
89 |
- int c = 0; |
90 |
- |
91 |
- memset(buf, 0, count); |
92 |
- while (count > 0) { |
93 |
- ret = read(fd, buf, count); |
94 |
- if (ret < 0) { |
95 |
- if ((errno == EAGAIN) || (errno == EINTR)) |
96 |
- continue; |
97 |
- return -1; |
98 |
- } |
99 |
- count -= ret; |
100 |
- buf += ret; |
101 |
- c += ret; |
102 |
- } |
103 |
- return c; |
104 |
-} |
105 |
+static |
106 |
+#include "read_all.h" |
107 |
|
108 |
static int write_all(int fd, char *buf, size_t count) |
109 |
{ |