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