summaryrefslogtreecommitdiffstats
path: root/mdk-stage1
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-11-04 13:19:08 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-11-04 13:19:08 +0000
commit12d8ac5a7cc692f8516cafba5b264baeef37c81f (patch)
tree9a3aadde000d9c8639da035bbe4f13fbd4ecdd0f /mdk-stage1
parentdf916d5432b5c6bf22d2075ceb5a27b46d9d38ab (diff)
downloaddrakx-12d8ac5a7cc692f8516cafba5b264baeef37c81f.tar
drakx-12d8ac5a7cc692f8516cafba5b264baeef37c81f.tar.gz
drakx-12d8ac5a7cc692f8516cafba5b264baeef37c81f.tar.bz2
drakx-12d8ac5a7cc692f8516cafba5b264baeef37c81f.tar.xz
drakx-12d8ac5a7cc692f8516cafba5b264baeef37c81f.zip
create save_fd() out of copy_file()
Diffstat (limited to 'mdk-stage1')
-rw-r--r--mdk-stage1/tools.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c
index eeef7e8d7..3be678943 100644
--- a/mdk-stage1/tools.c
+++ b/mdk-stage1/tools.c
@@ -242,54 +242,61 @@ int ramdisk_possible(void)
}
-enum return_type copy_file(char * from, char * to, void (*callback_func)(int overall))
+enum return_type save_fd(int from_fd, char * to, void (*callback_func)(int overall))
{
- FILE * f_from, * f_to;
+ FILE * f_to;
size_t quantity __attribute__((aligned(16))), overall = 0;
char buf[4096] __attribute__((aligned(4096)));
int ret = RETURN_ERROR;
- log_message("copy_file: %s -> %s", from, to);
-
- if (!(f_from = fopen(from, "rb"))) {
- log_perror(from);
- return RETURN_ERROR;
- }
-
if (!(f_to = fopen(to, "w"))) {
log_perror(to);
goto close_from;
- return RETURN_ERROR;
}
do {
- if ((quantity = fread(buf, 1, sizeof(buf), f_from)) > 0) {
+ quantity = read(from_fd, buf, sizeof(buf));
+ if (quantity > 0) {
if (fwrite(buf, 1, quantity, f_to) != quantity) {
log_message("short write (%s)", strerror(errno));
goto cleanup;
}
- }
+ } else if (quantity == -1) {
+ log_message("an error occured: %s", strerror(errno));
+ goto cleanup;
+ }
+
if (callback_func) {
overall += quantity;
callback_func(overall);
}
- } while (!feof(f_from) && !ferror(f_from) && !ferror(f_to));
-
- if (ferror(f_from) || ferror(f_to)) {
- log_message("an error occured: %s", strerror(errno));
- goto cleanup;
- }
+ } while (quantity);
ret = RETURN_OK;
cleanup:
fclose(f_to);
close_from:
- fclose(f_from);
+ fclose(from_fd);
return ret;
}
+enum return_type copy_file(char * from, char * to, void (*callback_func)(int overall))
+{
+ int from_fd;
+
+ log_message("copy_file: %s -> %s", from, to);
+
+ from_fd = open(from, O_RDONLY);
+ if (from_fd != -1) {
+ return save_fd(from_fd, to, callback_func);
+ } else {
+ log_perror(from);
+ return RETURN_ERROR;
+ }
+}
+
#ifndef MANDRAKE_MOVE
static void save_stuff_for_rescue(void)
{