source: rtems/c/src/tests/psxtests/filesupp/test_extend.c @ 0895bdb

4.104.114.84.9
Last change on this file since 0895bdb was 0895bdb, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 23, 1998 at 6:57:48 PM

Added tests in support of the file system infrastructure.

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/*
2 *  A test support function which extends the file to the specified
3 *  length.  This handles the implied open(), lseek(), write(), and close()
4 *  operations.
5 *
6 *  The defined behavior is a seek() followed by a write() extends the file
7 *  and zero fills the new length part.
8 *
9 *  $Id$
10 */
11
12#include <stdio.h>
13
14#include <sys/types.h>
15#include <sys/stat.h>
16#include <fcntl.h>
17#include <unistd.h>
18#include <errno.h>
19#include <string.h>
20#include <ctype.h>
21
22#include <assert.h>
23
24/*
25 *  test_extend routine
26 */
27
28void test_extend(
29  char   *file,
30  off_t  offset
31)
32{
33  int   fd;
34  int   status;
35  char  c = 0;
36
37  fd = open( file, O_WRONLY );
38  if ( fd == -1 ) {
39    printf( "test_extend: open( %s ) failed : %s\n", file, strerror( errno ) );
40    exit( 0 );
41  }
42
43  status = lseek( fd, offset - 1, SEEK_SET );
44  assert( !status );
45
46  status = write( fd, &c, 1 );
47  if ( status == -1 ) {
48    printf( "test_extend: write( %s ) failed : %s\n", file, strerror( errno ) );
49    exit( 0 );
50  }
51
52  if ( status != 1 ) {
53    printf( "test_extend: write( %s ) only wrote %d of %d bytes\n",
54            file, status, 1 );
55    exit( 0 );
56  }
57
58  status = close( fd );
59  assert( !status );
60}
Note: See TracBrowser for help on using the repository browser.