Update of /cvsroot/libsysio/libsysio/tests
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23114
Modified Files:
test_copy.c
Log Message:
Can't use stat when SYSIO_LABEL_NAMES is set to 1. Also, try to be more
efficient by using a larger block size derived from the file stat information.
Index: test_copy.c
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/test_copy.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -w -b -B -p -r1.11 -r1.12
--- test_copy.c 4 Feb 2005 00:29:26 -0000 1.11
+++ test_copy.c 9 Feb 2005 14:00:27 -0000 1.12
@@ -152,11 +152,14 @@ copy_file(const char *spath, const char
int sfd, dfd;
int flags;
int rtn;
- static char buf[1024];
+ struct stat stat;
+ char *buf;
+ size_t bufsiz;
ssize_t cc, wcc;
sfd = dfd = -1;
rtn = -1;
+ buf = NULL;
sfd = open_file(spath, O_RDONLY, 0);
if (sfd < 0)
@@ -168,7 +171,22 @@ copy_file(const char *spath, const char
if (dfd < 0)
goto out;
- while ((cc = SYSIO_INTERFACE_NAME(read)(sfd, buf, sizeof(buf))) > 0)
+ rtn = SYSIO_INTERFACE_NAME(fstat)(dfd, &stat);
+ if (rtn != 0) {
+ perror(dpath);
+ goto out;
+ }
+ bufsiz = stat.st_blksize;
+ if (bufsiz < (64 * 1024))
+ bufsiz =
+ (((64 * 1024) / stat.st_blksize - 1) + 1) * (64 * 1024);
+ buf = malloc(bufsiz);
+ if (!buf) {
+ perror(dpath);
+ goto out;
+ }
+
+ while ((cc = SYSIO_INTERFACE_NAME(read)(sfd, buf, bufsiz)) > 0)
if ((wcc = SYSIO_INTERFACE_NAME(write)(dfd, buf, cc)) != cc) {
if (wcc < 0) {
perror(dpath);
@@ -181,10 +199,14 @@ copy_file(const char *spath, const char
(unsigned )cc);
break;
}
- if (cc < 0)
+ if (cc < 0) {
perror(spath);
+ rtn = -1;
+ }
out:
+ if (buf)
+ free(buf);
if (sfd >= 0 && SYSIO_INTERFACE_NAME(close)(sfd) != 0)
perror(spath);
if (dfd >= 0 &&
@@ -192,5 +214,5 @@ out:
SYSIO_INTERFACE_NAME(close)(dfd) != 0))
perror(dpath);
- return 0;
+ return rtn;
}
|