}
}
-int
+int
get_fd(void)
{
struct test_file *tf = get_tf();
return tf->fd;
}
-static const char *basename(const char *path)
+static const char *my_basename(const char *path)
{
char *c = strrchr(path, '/');
return c ? c++ : path;
}
-void
+void
open_test_files(char **argv, int argc)
{
struct test_file *tf;
struct stat statbuf;
int fd = get_fd();
- ftruncate(fd, (off_t)0);
- ftruncate(fd, (off_t)100000);
+ /* should not ignore ftruncate(2)'s return value */
+ if (ftruncate(fd, (off_t)0) < 0) {
+ prterr("trunc_hack: ftruncate(0)");
+ exit(1);
+ }
+ if (ftruncate(fd, (off_t)100000) < 0) {
+ prterr("trunc_hack: ftruncate(100000)");
+ exit(1);
+ }
if (fstat(fd, &statbuf)) {
prterr("trunc_hack: fstat");
statbuf.st_size = -1;
prt("no extend on truncate! not posix!\n");
exit(130);
}
- ftruncate(fd, 0);
+ if (ftruncate(fd, 0) < 0) {
+ prterr("trunc_hack: ftruncate(0) (2nd call)");
+ exit(1);
+ }
}
static char *tf_buf = NULL;
open_test_files(argv, argc);
- strncat(goodfile, dirpath ? basename(fname) : fname, 256);
+ strncat(goodfile, dirpath ? my_basename(fname) : fname, 256);
strcat (goodfile, ".fsxgood");
fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
if (fsxgoodfd < 0) {
prterr(goodfile);
exit(92);
}
- strncat(logfile, dirpath ? basename(fname) : fname, 256);
+ strncat(logfile, dirpath ? my_basename(fname) : fname, 256);
strcat (logfile, ".fsxlog");
fsxlogf = fopen(logfile, "w");
if (fsxlogf == NULL) {