Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-04-28 22:23:31 -0500
committerDan McGee <dan@archlinux.org>2008-04-28 22:24:40 -0500
commit010279e449e87fb42fe587b649ed0e9994e65dba (patch)
tree2e39ed13666ccaf1113daf3291c03a9b4f6f3e82 /lib/libalpm/util.c
parent4e6361642e632b8631e3d12ee33b1cf5293edb83 (diff)
Updates to _alpm_copyfile()
Rework to use a single #define for the buffsize, and in the process clean up some other code and double the default buffer size. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/util.c')
-rw-r--r--lib/libalpm/util.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index a7a6573a..92e99914 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -215,27 +215,31 @@ int _alpm_makepath_mode(const char *path, mode_t mode)
return(0);
}
+#define CPBUFSIZE 8 * 1024
+
int _alpm_copyfile(const char *src, const char *dest)
{
FILE *in, *out;
size_t len;
- char buf[4097];
+ char *buf;
+ int ret = 0;
- in = fopen(src, "r");
+ in = fopen(src, "rb");
if(in == NULL) {
return(1);
}
- out = fopen(dest, "w");
+ out = fopen(dest, "wb");
if(out == NULL) {
fclose(in);
return(1);
}
+ CALLOC(buf, 1, CPBUFSIZE, ret = 1; goto cleanup;);
+
/* do the actual file copy */
- while((len = fread(buf, 1, 4096, in))) {
+ while((len = fread(buf, 1, CPBUFSIZE, in))) {
fwrite(buf, 1, len, out);
}
- fclose(in);
/* chmod dest to permissions of src, as long as it is not a symlink */
struct stat statbuf;
@@ -245,12 +249,14 @@ int _alpm_copyfile(const char *src, const char *dest)
}
} else {
/* stat was unsuccessful */
- fclose(out);
- return(1);
+ ret = 1;
}
+cleanup:
+ fclose(in);
fclose(out);
- return(0);
+ FREE(buf);
+ return(ret);
}
/* Trim whitespace and newlines from a string