| 1 | #include <stdio.h>
|
|---|
| 2 | #include <io.h>
|
|---|
| 3 | #include <fcntl.h>
|
|---|
| 4 | #include <sys/types.h>
|
|---|
| 5 | #include <sys/stat.h>
|
|---|
| 6 |
|
|---|
| 7 | int main( void )
|
|---|
| 8 | {
|
|---|
| 9 | const char *name = "read-1.test";
|
|---|
| 10 |
|
|---|
| 11 | char buf1[] = "\n\n\n";
|
|---|
| 12 | char buf2[ sizeof( buf1 )];
|
|---|
| 13 | int fd;
|
|---|
| 14 | int wrn;
|
|---|
| 15 | int rdn;
|
|---|
| 16 | int cmp;
|
|---|
| 17 | int failed;
|
|---|
| 18 |
|
|---|
| 19 | printf("Testing read() in text mode...\n");
|
|---|
| 20 |
|
|---|
| 21 | fd = open( name, O_RDWR | O_CREAT | O_TEXT, S_IREAD | S_IWRITE );
|
|---|
| 22 |
|
|---|
| 23 | wrn = write( fd, buf1, sizeof( buf1 ));
|
|---|
| 24 |
|
|---|
| 25 | lseek( fd, 0, SEEK_SET );
|
|---|
| 26 | rdn = read( fd, buf2, sizeof( buf1 ));
|
|---|
| 27 |
|
|---|
| 28 | cmp = memcmp( buf1, buf2, sizeof( buf1 ));
|
|---|
| 29 |
|
|---|
| 30 | failed = wrn != sizeof( buf1 ) || rdn != sizeof( buf1 ) || cmp != 0;
|
|---|
| 31 |
|
|---|
| 32 | printf("%s: wrn = %d(%d), rdn = %d(%d), cmp = %d(%d)\n",
|
|---|
| 33 | failed ? "FAILED" : "PASSED", wrn, sizeof( buf1 ),
|
|---|
| 34 | rdn, sizeof( buf1 ), cmp, 0 );
|
|---|
| 35 |
|
|---|
| 36 | close( fd );
|
|---|
| 37 |
|
|---|
| 38 | return failed;
|
|---|
| 39 | }
|
|---|