FOSSology  4.4.0
Open Source License Compliance by Open Source Software
repcat.c
Go to the documentation of this file.
1 /*
2  repcat: Cat a file.
3  SPDX-FileCopyrightText: © 2007-2011 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: LGPL-2.1-only
6 
7  stdout = data from file.
8 */
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include "libfossrepo.h"
16 
17 #ifdef COMMIT_HASH
18 char BuildVersion[]="Build version: " COMMIT_HASH ".\n";
19 #endif
20 
25 int main(int argc, char* argv[])
26 {
27  int LenIn, LenOut;
28  int i;
29  char Buf[10240];
30  FILE* F;
31 
32  if (argc != 3)
33  {
34  fprintf(stderr, "Usage: %s type filename > output\n", argv[0]);
35  exit(-1);
36  }
37 
38  F = fo_RepFread(argv[1], argv[2]);
39  if (!F)
40  {
41  fprintf(stderr, "ERROR: Invalid -- type='%s' filename='%s'\n",
42  argv[1], argv[2]);
43  return (-1);
44  }
45 
46  LenIn = 1;
47  while (LenIn > 0)
48  {
49  LenIn = fread(Buf, 1, sizeof(Buf), F);
50  if (LenIn > 0)
51  {
52  LenOut = 0;
53  while (LenOut < LenIn)
54  {
55  i = fwrite(Buf + LenOut, 1, LenIn - LenOut, stdout);
56  LenOut += i;
57  if (i == 0) break;
58  }
59  }
60  }
61  fo_RepFclose(F);
62  return (0);
63 } /* main() */
64 
char BuildVersion[]
Definition: buckets.c:68
int fo_RepFclose(FILE *F)
Perform an fclose.
Definition: libfossrepo.c:601
FILE * fo_RepFread(char *Type, char *Filename)
Perform an fopen for reading only.
Definition: libfossrepo.c:613
int main(int argc, char *argv[])
Read a file and print to stdout.
Definition: repcat.c:25