OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [tests/] [psxtests/] [psxfile01/] [test_extend.c] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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
 *  test_extend.c,v 1.2 2002/08/02 00:53:21 joel Exp
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
#include <pmacros.h>
25
 
26
/*
27
 *  test_extend routine
28
 */
29
 
30
void test_extend(
31
  char   *file,
32
  off_t  offset
33
)
34
{
35
  int   fd;
36
  int   status;
37
  char  c = 0;
38
 
39
  fd = open( file, O_WRONLY );
40
  if ( fd == -1 ) {
41
    printf( "test_extend: open( %s ) failed : %s\n", file, strerror( errno ) );
42
    rtems_test_exit( 0 );
43
  }
44
 
45
  status = lseek( fd, offset - 1, SEEK_SET );
46
  assert( status != -1 );
47
 
48
  status = write( fd, &c, 1 );
49
  if ( status == -1 ) {
50
    printf( "test_extend: write( %s ) failed : %s\n", file, strerror( errno ) );
51
    rtems_test_exit( 0 );
52
  }
53
 
54
  if ( status != 1 ) {
55
    printf( "test_extend: write( %s ) only wrote %d of %d bytes\n",
56
            file, status, 1 );
57
    rtems_test_exit( 0 );
58
  }
59
 
60
  status = close( fd );
61
  assert( !status );
62
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.