init-db::copy_file() - use copy_fd()
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Nov 5, 2005 at 11:07 UTC
32276c8059908874afb7a2db039ccc7bcfd84ec7
1 file changed
+3
-24
init-db.c
+3
-24
@@ -21,7 +21,7 @@ static void safe_create_dir(const char *dir)
21
22
static int copy_file(const char *dst, const char *src, int mode)
23
{
24
- int fdi, fdo;
24
+ int fdi, fdo, status;
25
26
mode = (mode & 0111) ? 0777 : 0666;
27
if ((fdi = open(src, O_RDONLY)) < 0)
@@ -30,30 +30,9 @@ static int copy_file(const char *dst, const char *src, int mode)
30
close(fdi);
31
return fdo;
32
}
33
- while (1) {
34
- char buf[BUFSIZ];
35
- ssize_t leni, leno, ofs;
36
- leni = read(fdi, buf, sizeof(buf));
37
- if (leni < 0) {
38
- error_return:
39
- close(fdo);
40
- close(fdi);
41
- return -1;
42
- }
43
- if (!leni)
44
- break;
45
- ofs = 0;
46
- do {
47
- leno = write(fdo, buf+ofs, leni);
48
- if (leno < 0)
49
- goto error_return;
50
- leni -= leno;
51
- ofs += leno;
52
- } while (0 < leni);
53
- }
33
+ status = copy_fd(fdi, fdo);
34
close(fdo);
55
- close(fdi);
56
- return 0;
35
+ return status;
36
}
37
38
static void copy_templates_1(char *path, int baselen,