2010-06-23 00:07:23 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-04-16 18:04:46 +02:00
|
|
|
int max_error = 3;
|
|
|
|
#include "common.h"
|
|
|
|
|
2010-09-02 11:33:37 +02:00
|
|
|
|
|
|
|
int subtest = -1;
|
|
|
|
|
2013-04-16 18:04:46 +02:00
|
|
|
static void do_test(void)
|
2010-06-23 00:07:23 +02:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char *wbuf, *rbuf;
|
|
|
|
off_t off=0;
|
|
|
|
size_t size;
|
|
|
|
ssize_t nwritten;
|
|
|
|
ssize_t nread;
|
2013-09-27 14:07:37 +02:00
|
|
|
char filename[] = "pwrite_test_XXXXXXX";
|
2010-06-23 00:07:23 +02:00
|
|
|
int i;
|
|
|
|
|
2010-09-02 11:33:37 +02:00
|
|
|
subtest = 1;
|
2010-06-23 00:07:23 +02:00
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
if ((fd = mkstemp(filename)) < 0) e(1);
|
2010-06-23 00:07:23 +02:00
|
|
|
|
|
|
|
size = 1 + rand() % 4096;
|
|
|
|
off = rand();
|
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
if((wbuf = malloc(sizeof(char)*size)) == NULL) e(2);
|
2010-06-23 00:07:23 +02:00
|
|
|
|
|
|
|
for(i = 0; i < size; i++) {
|
|
|
|
wbuf[i] = 1 + rand()%127;
|
|
|
|
}
|
|
|
|
|
2011-11-14 11:07:49 +01:00
|
|
|
if ((nwritten = pwrite(fd, wbuf, size, off)) < 0) e(3);
|
|
|
|
if ((rbuf = malloc(sizeof(char)*nwritten)) == NULL) e(4);
|
|
|
|
if ((nread = pread(fd, rbuf, nwritten, off)) < 0) e(5);
|
|
|
|
if (strncmp(rbuf, wbuf, nread) != 0) e(6);
|
2010-06-23 00:07:23 +02:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
free(wbuf);
|
2010-09-02 11:33:37 +02:00
|
|
|
unlink(filename);
|
|
|
|
}
|
|
|
|
|
2010-06-23 00:07:23 +02:00
|
|
|
|
2010-09-02 11:33:37 +02:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
start(54);
|
|
|
|
do_test();
|
|
|
|
quit();
|
2011-11-28 11:07:55 +01:00
|
|
|
return(-1); /* Unreachable */
|
2010-06-23 00:07:23 +02:00
|
|
|
}
|