mirror of
https://github.com/troglobit/libite.git
synced 2026-10-29 12:30:46 +00:00
test: reproduce copyfile() off by one regression
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
837c3f23be
commit
97cb2cb87c
1 file changed
+27
-4
+27
-4
@@ -2,16 +2,39 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
|
static int sz()
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
ssize_t len;
|
||||||
|
|
||||||
|
printf("=>Start copyfile(/dev/zero, 32768)\n");
|
||||||
|
len = copyfile("/dev/zero", "/tmp/zeroes", 32768, 0);
|
||||||
|
if (!len)
|
||||||
|
err(1, "failed copying any bytes from /dev/zero");
|
||||||
|
|
||||||
|
if (stat("/tmp/zeroes", &st))
|
||||||
|
err(1, "copied but cannot find destination");
|
||||||
|
if (st.st_size != 32768)
|
||||||
|
err(1, "file only %ld bytes, expected 32768", st.st_size);
|
||||||
|
|
||||||
|
if (len != st.st_size)
|
||||||
|
errx(1, "copied correct num bytes, 32768, but copyfile() returns %ld", len);
|
||||||
|
|
||||||
|
printf("OK => %ld\n", len);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
char *files[] = {
|
char *files[] = {
|
||||||
"/etc/passwd", "/tmp/mypwd", "/tmp/mypwd",
|
"/etc/passwd", "/tmp/mypwd", "/tmp/mypwd",
|
||||||
"/etc/passwd", "/tmp/", "/tmp/passwd",
|
"/etc/passwd", "/tmp/", "/tmp/passwd",
|
||||||
"/etc/passwd", "/tmp", "/tmp/passwd",
|
"/etc/passwd", "/tmp", "/tmp/passwd",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
FILE *src, *dst;
|
FILE *src, *dst;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
printf("=>Start testing fcopyfile()\n");
|
printf("=>Start testing fcopyfile()\n");
|
||||||
while (files[i]) {
|
while (files[i]) {
|
||||||
@@ -51,5 +74,5 @@ int main(void)
|
|||||||
i += 3;
|
i += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return sz();
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user