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

Subversion Repositories openrisc

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

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 performs a write() and
3
 *  handles implied open(), lseek(), write(), and close() operations.
4
 *
5
 *  $Id: test_write.c,v 1.2 2001-09-27 12:02:25 chris 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
/*
20
 *  test_write routine
21
 */
22
 
23
void test_write(
24
  char   *file,
25
  off_t  offset,
26
  char  *buffer
27
)
28
{
29
  int   fd;
30
  int   status;
31
  int   length;
32
 
33
 
34
  length = strlen( buffer );
35
 
36
  fd = open( file, O_WRONLY );
37
  if ( fd == -1 ) {
38
    printf( "test_write: open( %s ) failed : %s\n", file, strerror( errno ) );
39
    exit( 0 );
40
  }
41
 
42
  status = lseek( fd, offset, SEEK_SET );
43
  assert( status != -1 );
44
 
45
  status = write( fd, buffer, length );
46
  if ( status == -1 ) {
47
    printf( "test_write: write( %s ) failed : %s\n", file, strerror( errno ) );
48
    exit( 0 );
49
  }
50
 
51
  if ( status != length ) {
52
    printf( "test_write: write( %s ) only wrote %d of %d bytes\n",
53
            file, status, length );
54
    exit( 0 );
55
  }
56
 
57
  status = close( fd );
58
  assert( !status );
59
}

powered by: WebSVN 2.1.0

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