mirror of
https://github.com/troglobit/libite.git
synced 2026-10-02 05:42:49 +07:00
test: reproduce copyfile() off by one regression
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+27
-4
@@ -2,16 +2,39 @@
|
||||
#include <errno.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 i = 0;
|
||||
char *files[] = {
|
||||
"/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
|
||||
};
|
||||
FILE *src, *dst;
|
||||
int i = 0;
|
||||
|
||||
printf("=>Start testing fcopyfile()\n");
|
||||
while (files[i]) {
|
||||
@@ -51,5 +74,5 @@ int main(void)
|
||||
i += 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return sz();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user