Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-projects commit in portage-utils/libq: copy_file.c libq.c md5_sha1_sum.c
Date: Wed, 23 Feb 2011 22:59:03
Message-Id: 20110223225852.2E7DF20057@flycatcher.gentoo.org
1 vapier 11/02/23 22:58:52
2
3 Modified: libq.c md5_sha1_sum.c
4 Added: copy_file.c
5 Log:
6 rewrite merge code to take care of file updates ourself rather than shelling out
7
8 Revision Changes Path
9 1.23 portage-utils/libq/libq.c
10
11 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.c?rev=1.23&view=markup
12 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.c?rev=1.23&content-type=text/plain
13 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.c?r1=1.22&r2=1.23
14
15 Index: libq.c
16 ===================================================================
17 RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/libq.c,v
18 retrieving revision 1.22
19 retrieving revision 1.23
20 diff -u -r1.22 -r1.23
21 --- libq.c 23 Feb 2011 08:59:45 -0000 1.22
22 +++ libq.c 23 Feb 2011 22:58:52 -0000 1.23
23 @@ -20,6 +20,7 @@
24 #include "which.c"
25 #include "compat.c"
26
27 +#include "copy_file.c"
28 #include "safe_io.c"
29 #include "xchdir.c"
30 #include "xgetcwd.c"
31
32
33
34 1.7 portage-utils/libq/md5_sha1_sum.c
35
36 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/md5_sha1_sum.c?rev=1.7&view=markup
37 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/md5_sha1_sum.c?rev=1.7&content-type=text/plain
38 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/md5_sha1_sum.c?r1=1.6&r2=1.7
39
40 Index: md5_sha1_sum.c
41 ===================================================================
42 RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/md5_sha1_sum.c,v
43 retrieving revision 1.6
44 retrieving revision 1.7
45 diff -u -r1.6 -r1.7
46 --- md5_sha1_sum.c 25 Sep 2009 14:58:37 -0000 1.6
47 +++ md5_sha1_sum.c 23 Feb 2011 22:58:52 -0000 1.7
48 @@ -48,10 +48,10 @@
49 return (hex_value);
50 }
51
52 -static unsigned char *hash_file(const char *filename, uint8_t hash_algo)
53 +static unsigned char *hash_file_at(int dfd, const char *filename, uint8_t hash_algo)
54 {
55 int fd;
56 - fd = open(filename, O_RDONLY);
57 + fd = openat(dfd, filename, O_RDONLY);
58 if (fd != -1) {
59 static uint8_t hash_value_bin[20];
60 static unsigned char *hash_value;
61 @@ -64,3 +64,8 @@
62 }
63 return NULL;
64 }
65 +
66 +static unsigned char *hash_file(const char *filename, uint8_t hash_algo)
67 +{
68 + return hash_file_at(AT_FDCWD, filename, hash_algo);
69 +}
70
71
72
73 1.1 portage-utils/libq/copy_file.c
74
75 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/copy_file.c?rev=1.1&view=markup
76 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/copy_file.c?rev=1.1&content-type=text/plain
77
78 Index: copy_file.c
79 ===================================================================
80 static int copy_file_fd(int fd_src, int fd_dst)
81 {
82 FILE *fp_src, *fp_dst;
83 size_t rcnt, wcnt;
84 char buf[BUFSIZE];
85
86 /* dont fclose() as that implicitly close()'s */
87
88 fp_src = fdopen(fd_src, "r");
89 if (!fp_src)
90 return -1;
91
92 fp_dst = fdopen(fd_dst, "w");
93 if (!fp_dst)
94 return -1;
95
96 while (1) {
97 rcnt = fread(buf, sizeof(buf[0]), sizeof(buf), fp_src);
98 if (!rcnt) {
99 fflush(fp_dst);
100 return feof(fp_src) ? 0 : -1;
101 }
102
103 wcnt = fwrite(buf, sizeof(buf[0]), rcnt, fp_dst);
104 if (wcnt != rcnt) {
105 if (ferror(fp_dst))
106 return -1;
107 fseek(fp_src, wcnt - rcnt, SEEK_CUR);
108 }
109 }
110 }