test for pwrite() (Contributed by Buccapatnam Tirumala, Gautam)
This commit is contained in:
		
							parent
							
								
									24a5f48921
								
							
						
					
					
						commit
						f2c3cbab00
					
				@ -11,7 +11,8 @@ OBJ=	test1  test2  test3  test4  test5  test6  test7  test8  test9  \
 | 
			
		||||
	       test21 test22 test23        test25 test26 test27 test28 test29 \
 | 
			
		||||
	test30 test31 test32        test34 test35 test36 test37 test38 \
 | 
			
		||||
	test39 t10a t11a t11b test40 t40a t40b t40c t40d t40e t40f test41 \
 | 
			
		||||
	test42 test44 test45 test47 test48 test49 test50 test51 test52 test53
 | 
			
		||||
	test42 test44 test45 test47 test48 test49 test50 test51 test52 test53 \
 | 
			
		||||
	test54
 | 
			
		||||
 | 
			
		||||
BIGOBJ=  test20 test24
 | 
			
		||||
ROOTOBJ= test11 test33 test43 test46
 | 
			
		||||
@ -108,3 +109,4 @@ test51: test51.c
 | 
			
		||||
test51-gcc: test51.c
 | 
			
		||||
test52: test52.c
 | 
			
		||||
test52-gcc: test52.c
 | 
			
		||||
test54: test54.c
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										64
									
								
								test/test54.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								test/test54.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,64 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <err.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
int main(void)
 | 
			
		||||
{
 | 
			
		||||
	int fd;
 | 
			
		||||
	char *wbuf, *rbuf;
 | 
			
		||||
	off_t off=0;
 | 
			
		||||
	size_t size;
 | 
			
		||||
	ssize_t nwritten;
 | 
			
		||||
	ssize_t nread;
 | 
			
		||||
	char *filename;
 | 
			
		||||
	int i;
 | 
			
		||||
 | 
			
		||||
	printf("Test 54 ");
 | 
			
		||||
	fflush(stdout);
 | 
			
		||||
 | 
			
		||||
	if((filename = mktemp("/tmp/pwrite_test_XXXXXXX")) == NULL) {
 | 
			
		||||
		err(1, "Failed to create tempfile");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if((fd = open(filename, O_CREAT|O_RDWR)) < 0) {
 | 
			
		||||
		err(1, "Failed to open %s", filename);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	size = 1 + rand() % 4096;
 | 
			
		||||
	off = rand();
 | 
			
		||||
 | 
			
		||||
	if((wbuf = malloc(sizeof(char)*size)) == NULL) {
 | 
			
		||||
		errx(1, "Malloc failed.\n");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for(i = 0; i < size; i++) {
 | 
			
		||||
		wbuf[i] = 1 + rand()%127;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	if((nwritten = pwrite(fd, wbuf, size, off)) < 0) {
 | 
			
		||||
		err(1, "pwrite failed");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if((rbuf = malloc(sizeof(char)*nwritten)) == NULL) {
 | 
			
		||||
		errx(1, "Malloc failed.\n");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if((nread = pread(fd, rbuf, nwritten, off)) < 0) {
 | 
			
		||||
		err(1, "pread failed");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if(strncmp(rbuf, wbuf, nread) != 0) {
 | 
			
		||||
		err(1, "Test failed.\n");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	printf(" ok\n");
 | 
			
		||||
 | 
			
		||||
	close(fd);
 | 
			
		||||
	free(wbuf);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user