1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
/*
* $Id: rfcat.c,v 1.2 2008/10/01 14:02:10 dhsmith Exp $
*/
/*
* Copyright (C) 2001-2008 by CERN/IT/PDP/DM
* All rights reserved
*/
#ifndef lint
static char sccsid[] = "@(#)$RCSfile: rfcat.c,v $ $Revision: 1.2 $ $Date: 2008/10/01 14:02:10 $ CERN/IT/PDP/DM Jean-Philippe Baud";
#endif /* not lint */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(_WIN32)
#include <winsock2.h>
#endif
#include "rfio_api.h"
main(argc, argv)
int argc;
char **argv;
{
int errflg = 0;
int i;
#if defined(_WIN32)
WSADATA wsadata;
if (WSAStartup (MAKEWORD (2, 0), &wsadata)) {
fprintf (stderr, "WSAStartup unsuccessful\n");
exit (2);
}
#endif
if (argc == 1)
errflg = catfile ("-");
else
for (i = 1; i < argc; i++)
errflg += catfile (argv[i]);
#if defined(_WIN32)
WSACleanup();
#endif
exit (errflg ? 1 : 0);
}
catfile(inpfile)
char *inpfile;
{
char buf [32768];
int c;
int rc;
FILE *s;
int v;
/* Streaming opening is always better */
v = RFIO_STREAM;
rfiosetopt (RFIO_READOPT, &v, 4);
if (strcmp (inpfile, "-") == 0)
s = stdin;
else if ((s = rfio_fopen64 (inpfile, "r")) == NULL) {
rfio_perror (inpfile);
return (1);
}
while ((c = rfio_fread (buf, 1, sizeof(buf), s)) > 0) {
if ((rc = fwrite (buf, 1, c, stdout)) < c) {
fprintf (stderr, "rfcat %s: %s\n", inpfile,
strerror ((rc < 0) ? errno : ENOSPC));
if (strcmp (inpfile, "-"))
rfio_fclose (s);
return (1);
}
}
if (strcmp (inpfile, "-"))
rfio_fclose (s);
return (0);
}
|