mirror of
https://github.com/moparisthebest/pacman
synced 2024-08-13 17:03:46 -04:00
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>
This commit is contained in:
parent
4e6361642e
commit
010279e449
@ -215,27 +215,31 @@ int _alpm_makepath_mode(const char *path, mode_t mode)
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CPBUFSIZE 8 * 1024
|
||||||
|
|
||||||
int _alpm_copyfile(const char *src, const char *dest)
|
int _alpm_copyfile(const char *src, const char *dest)
|
||||||
{
|
{
|
||||||
FILE *in, *out;
|
FILE *in, *out;
|
||||||
size_t len;
|
size_t len;
|
||||||
char buf[4097];
|
char *buf;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
in = fopen(src, "r");
|
in = fopen(src, "rb");
|
||||||
if(in == NULL) {
|
if(in == NULL) {
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
out = fopen(dest, "w");
|
out = fopen(dest, "wb");
|
||||||
if(out == NULL) {
|
if(out == NULL) {
|
||||||
fclose(in);
|
fclose(in);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CALLOC(buf, 1, CPBUFSIZE, ret = 1; goto cleanup;);
|
||||||
|
|
||||||
/* do the actual file copy */
|
/* do the actual file copy */
|
||||||
while((len = fread(buf, 1, 4096, in))) {
|
while((len = fread(buf, 1, CPBUFSIZE, in))) {
|
||||||
fwrite(buf, 1, len, out);
|
fwrite(buf, 1, len, out);
|
||||||
}
|
}
|
||||||
fclose(in);
|
|
||||||
|
|
||||||
/* chmod dest to permissions of src, as long as it is not a symlink */
|
/* chmod dest to permissions of src, as long as it is not a symlink */
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
@ -245,12 +249,14 @@ int _alpm_copyfile(const char *src, const char *dest)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* stat was unsuccessful */
|
/* stat was unsuccessful */
|
||||||
fclose(out);
|
ret = 1;
|
||||||
return(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
fclose(in);
|
||||||
fclose(out);
|
fclose(out);
|
||||||
return(0);
|
FREE(buf);
|
||||||
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Trim whitespace and newlines from a string
|
/* Trim whitespace and newlines from a string
|
||||||
|
Loading…
Reference in New Issue
Block a user