Listing 2.3.
Quick Dump


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define bSIZE 1024

int main( int argc, char *argv[] )
  /* ---------------------------------------------------- **
   * Copy file contents to stdout.
   * ---------------------------------------------------- **
   */
  {
  int      fd_in;
  int      fd_out;
  ssize_t  count;
  char     bufr[bSIZE];

  if( argc != 2 )
    {
    (void)fprintf( stderr,
                   "Usage: %s <filename>\n", argv[0] );
    exit( EXIT_FAILURE );
    }

  fd_in = open( argv[1], O_RDONLY );
  if( fd_in < 0 )
    {
    perror( "open()" );
    exit( EXIT_FAILURE );
    }
  fd_out = fileno( stdout );

  do
    {
    count = read( fd_in, bufr, bSIZE );
    if( count > 0 )
      count = write( fd_out, bufr, (size_t)count );
    } while( bSIZE == count );

  if( count < 0 )
    {
    perror( "read()/write()" );
    exit( EXIT_FAILURE );
    }

  (void)close( fd_in );
  exit( EXIT_SUCCESS );
  } /* main */


$Revision: 1.1 $
$Date: 2002/08/14 06:10:19 $
[W3C Validated] Copyright © 2002 Christopher R. Hertel 
Released under the terms of the LGPL