1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #include "config.h"
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <fcntl.h>
- enum {
- EX_OK = 0,
- EX_FAIL,
- EX_BAD,
- };
- int
- check_seek_hole (int fd)
- {
- #ifdef SEEK_HOLE
- struct stat stat;
- off_t offset;
-
- if (lseek (fd, 100*1024*1024, SEEK_END) < 0)
- return EX_BAD;
-
- if (write (fd, "data\n", 5) != 5)
- return EX_BAD;
-
- if (lseek (fd, 100*1024*1024, SEEK_END) < 0)
- return EX_BAD;
-
- if (write (fd, "data\n", 5) != 5)
- return EX_BAD;
- if (fstat (fd, &stat))
- return EX_BAD;
- offset = lseek (fd, 0, SEEK_DATA);
- if (offset == (off_t)-1)
- return EX_FAIL;
- offset = lseek (fd, offset, SEEK_HOLE);
- if (offset == (off_t)-1 || offset == stat.st_size)
- return EX_FAIL;
- return EX_OK;
- #else
- return EX_BAD;
- #endif
- }
- int
- main ()
- {
- #ifdef SEEK_HOLE
- int rc;
- char template[] = "testseekhole-XXXXXX";
- int fd = mkstemp (template);
- if (fd == -1)
- return EX_BAD;
- rc = check_seek_hole (fd);
- close (fd);
- unlink (template);
- return rc;
- #else
- return EX_FAIL;
- #endif
- }
|