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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [tests/] [psxtests/] [psxfile01/] [test_write.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 performs a write() and
3
 *  handles implied open(), lseek(), write(), and close() operations.
4
 *
5
 *  test_write.c,v 1.2 2002/08/02 00:53:21 joel Exp
6
 */
7
 
8
#include <stdio.h>
9
 
10
#include <sys/types.h>
11
#include <sys/stat.h>
12
#include <fcntl.h>
13
#include <unistd.h>
14
#include <errno.h>
15
#include <string.h>
16
 
17
#include <assert.h>
18
 
19
#include <pmacros.h>
20
 
21
/*
22
 *  test_write routine
23
 */
24
 
25
void test_write(
26
  char   *file,
27
  off_t  offset,
28
  char  *buffer
29
)
30
{
31
  int   fd;
32
  int   status;
33
  int   length;
34
 
35
 
36
  length = strlen( buffer );
37
 
38
  fd = open( file, O_WRONLY );
39
  if ( fd == -1 ) {
40
    printf( "test_write: open( %s ) failed : %s\n", file, strerror( errno ) );
41
    rtems_test_exit( 0 );
42
  }
43
 
44
  status = lseek( fd, offset, SEEK_SET );
45
  assert( status != -1 );
46
 
47
  status = write( fd, buffer, length );
48
  if ( status == -1 ) {
49
    printf( "test_write: write( %s ) failed : %s\n", file, strerror( errno ) );
50
    rtems_test_exit( 0 );
51
  }
52
 
53
  if ( status != length ) {
54
    printf( "test_write: write( %s ) only wrote %d of %d bytes\n",
55
            file, status, length );
56
    rtems_test_exit( 0 );
57
  }
58
 
59
  status = close( fd );
60
  assert( !status );
61
}

powered by: WebSVN 2.1.0

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