init-db::copy_file() - use copy_fd()

Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Junio C Hamano 2005-11-05 11:07:22 -08:00
parent e6c64fc1e9
commit 32276c8059

View File

@ -21,7 +21,7 @@ static void safe_create_dir(const char *dir)
static int copy_file(const char *dst, const char *src, int mode) static int copy_file(const char *dst, const char *src, int mode)
{ {
int fdi, fdo; int fdi, fdo, status;
mode = (mode & 0111) ? 0777 : 0666; mode = (mode & 0111) ? 0777 : 0666;
if ((fdi = open(src, O_RDONLY)) < 0) if ((fdi = open(src, O_RDONLY)) < 0)
@ -30,30 +30,9 @@ static int copy_file(const char *dst, const char *src, int mode)
close(fdi); close(fdi);
return fdo; return fdo;
} }
while (1) { status = copy_fd(fdi, fdo);
char buf[BUFSIZ];
ssize_t leni, leno, ofs;
leni = read(fdi, buf, sizeof(buf));
if (leni < 0) {
error_return:
close(fdo);
close(fdi);
return -1;
}
if (!leni)
break;
ofs = 0;
do {
leno = write(fdo, buf+ofs, leni);
if (leno < 0)
goto error_return;
leni -= leno;
ofs += leno;
} while (0 < leni);
}
close(fdo); close(fdo);
close(fdi); return status;
return 0;
} }
static void copy_templates_1(char *path, int baselen, static void copy_templates_1(char *path, int baselen,