source: rtems/c/src/tests/psxtests/filesupp/test_write.c @ 1ed9d57

4.104.114.84.95
Last change on this file since 1ed9d57 was 1ed9d57, checked in by Jennifer Averett <Jennifer.Averett@…>, on 03/29/99 at 18:05:01

Fixed expected return status from lseek to look for not failure (-1).

  • Property mode set to 100644
File size: 1.0 KB
Line 
1/*
2 *  A test support function which performs a write() and
3 *  handles implied open(), lseek(), write(), and close() operations.
4 *
5 *  $Id$
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
23void 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}
Note: See TracBrowser for help on using the repository browser.