source: rtems/c/src/tests/psxtests/psxfile01/test_write.c @ d802489

4.104.114.84.95
Last change on this file since d802489 was d802489, checked in by Joel Sherrill <joel.sherrill@…>, on 08/02/02 at 00:53:21

2002-08-01 Joel Sherrill <joel@…>

  • Per PR47 add support for buffered test output. This involved adding defines to redirect output to a buffer and dump it when full, at "test pause", and at exit. To avoid problems when redefining exit(), all tests were modified to call rtems_test_exit(). Some tests, notable psxtests, had to be modified to include the standard test macro .h file (pmacros.h or tmacros.h) to enable this support.
  • include/pmacros.h, psx01/task.c, psx02/init.c, psx02/task.c, psx03/init.c, psx04/init.c, psx05/init.c, psx06/init.c, psx07/init.c, psx08/task3.c, psx09/init.c, psx10/init.c, psx11/init.c, psx12/init.c, psx13/Makefile.am, psx13/main.c, psx13/test.c, psxcancel/init.c, psxchroot01/Makefile.am, psxchroot01/main.c, psxchroot01/test.c, psxfile01/Makefile.am, psxfile01/main.c, psxfile01/test.c, psxfile01/test_cat.c, psxfile01/test_extend.c, psxfile01/test_write.c, psxmount/Makefile.am, psxmount/main.c, psxmount/test.c, psxmsgq01/init.c, psxreaddir/Makefile.am, psxreaddir/main.c, psxreaddir/test.c, psxsem01/init.c, psxstat/Makefile.am, psxstat/main.c, psxstat/test.c, psxtime/main.c, psxtime/test.c, psxtimer/psxtimer.c: Modified.
  • Property mode set to 100644
File size: 1.1 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#include <pmacros.h>
20
21/*
22 *  test_write routine
23 */
24
25void 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}
Note: See TracBrowser for help on using the repository browser.