FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
repcat.c
Go to the documentation of this file.
1 /****************************************************************
2 repcat: Cat a file.
3 
4 Copyright (C) 2007-2011 Hewlett-Packard Development Company, L.P.
5 
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License version 2.1 as published by the Free Software Foundation.
9 
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public License
16 along with this library; if not, write to the Free Software Foundation, Inc.0
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 ***********************
20 stdout = data from file.
21 ****************************************************************/
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include "libfossrepo.h"
29 
30 #ifdef COMMIT_HASH
31 char BuildVersion[]="Build version: " COMMIT_HASH ".\n";
32 #endif
33 
38 int main(int argc, char* argv[])
39 {
40  int LenIn, LenOut;
41  int i;
42  char Buf[10240];
43  FILE* F;
44 
45  if (argc != 3)
46  {
47  fprintf(stderr, "Usage: %s type filename > output\n", argv[0]);
48  exit(-1);
49  }
50 
51  F = fo_RepFread(argv[1], argv[2]);
52  if (!F)
53  {
54  fprintf(stderr, "ERROR: Invalid -- type='%s' filename='%s'\n",
55  argv[1], argv[2]);
56  return (-1);
57  }
58 
59  LenIn = 1;
60  while (LenIn > 0)
61  {
62  LenIn = fread(Buf, 1, sizeof(Buf), F);
63  if (LenIn > 0)
64  {
65  LenOut = 0;
66  while (LenOut < LenIn)
67  {
68  i = fwrite(Buf + LenOut, 1, LenIn - LenOut, stdout);
69  LenOut += i;
70  if (i == 0) break;
71  }
72  }
73  }
74  fo_RepFclose(F);
75  return (0);
76 } /* main() */
77 
char BuildVersion[]
Definition: buckets.c:79
FILE * fo_RepFread(char *Type, char *Filename)
Perform an fopen for reading only.
Definition: libfossrepo.c:625
int fo_RepFclose(FILE *F)
Perform an fclose.
Definition: libfossrepo.c:613
int main(int argc, char *argv[])
Read a file and print to stdout.
Definition: repcat.c:38