OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [tests/] [psxtests/] [psxfile01/] [test_extend.c] - Blame information for rev 484

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

Line No. Rev Author Line
1 30 unneback
/*
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: test_extend.c,v 1.2 2001-09-27 12:02:25 chris 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
/*
25
 *  test_extend routine
26
 */
27
 
28
void 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
}

powered by: WebSVN 2.1.0

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