source: rtems/testsuites/psxtests/psxfile01/test_extend.c @ a23cad6

4.104.114.84.95
Last change on this file since a23cad6 was a23cad6, checked in by Joel Sherrill <joel.sherrill@…>, on 11/23/99 at 13:43:34

Files only used by psxfile01, so moved there.

  • 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 != -1 );
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.