1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * A test support function which extends the file to the specified |
---|
5 | * length. This handles the implied open(), lseek(), write(), and close() |
---|
6 | * operations. |
---|
7 | * |
---|
8 | * The defined behavior is a seek() followed by a write() extends the file |
---|
9 | * and zero fills the new length part. |
---|
10 | */ |
---|
11 | |
---|
12 | /* |
---|
13 | * COPYRIGHT (c) 1989-2012. |
---|
14 | * On-Line Applications Research Corporation (OAR). |
---|
15 | * |
---|
16 | * The license and distribution terms for this file may be |
---|
17 | * found in the file LICENSE in this distribution or at |
---|
18 | * http://www.rtems.com/license/LICENSE. |
---|
19 | */ |
---|
20 | |
---|
21 | #ifdef HAVE_CONFIG_H |
---|
22 | #include "config.h" |
---|
23 | #endif |
---|
24 | |
---|
25 | #include <stdio.h> |
---|
26 | |
---|
27 | #include <sys/types.h> |
---|
28 | #include <sys/stat.h> |
---|
29 | #include <fcntl.h> |
---|
30 | #include <unistd.h> |
---|
31 | #include <errno.h> |
---|
32 | #include <string.h> |
---|
33 | #include <ctype.h> |
---|
34 | |
---|
35 | #include <pmacros.h> |
---|
36 | |
---|
37 | /* forward declarations to avoid warnings */ |
---|
38 | void test_extend(char *file, off_t offset); |
---|
39 | |
---|
40 | /* |
---|
41 | * test_extend routine |
---|
42 | */ |
---|
43 | void test_extend( |
---|
44 | char *file, |
---|
45 | off_t offset |
---|
46 | ) |
---|
47 | { |
---|
48 | int fd; |
---|
49 | int status; |
---|
50 | char c = 0; |
---|
51 | |
---|
52 | fd = open( file, O_WRONLY ); |
---|
53 | if ( fd == -1 ) { |
---|
54 | printf( "test_extend: open( %s ) failed : %s\n", file, strerror( errno ) ); |
---|
55 | rtems_test_exit( 0 ); |
---|
56 | } |
---|
57 | |
---|
58 | status = lseek( fd, offset - 1, SEEK_SET ); |
---|
59 | rtems_test_assert( status != -1 ); |
---|
60 | |
---|
61 | status = write( fd, &c, 1 ); |
---|
62 | if ( status == -1 ) { |
---|
63 | printf( "test_extend: write( %s ) failed : %s\n", file, strerror( errno ) ); |
---|
64 | rtems_test_exit( 0 ); |
---|
65 | } |
---|
66 | |
---|
67 | if ( status != 1 ) { |
---|
68 | printf( "test_extend: write( %s ) only wrote %d of %d bytes\n", |
---|
69 | file, status, 1 ); |
---|
70 | rtems_test_exit( 0 ); |
---|
71 | } |
---|
72 | |
---|
73 | status = close( fd ); |
---|
74 | rtems_test_assert( !status ); |
---|
75 | } |
---|