FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 04-29-2008, 03:34 AM
Dan McGee
 
Default 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>
---
lib/libalpm/util.c | 22 ++++++++++++++--------
1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index a7a6573..92e9991 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
--
1.5.5.1


_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 

Thread Tools




All times are GMT. The time now is 01:34 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org