FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
repwrite.c
Go to the documentation of this file.
1 /****************************************************************
2 repwrite: Create 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 ****************************************************************/
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include "libfossrepo.h"
31 
32 #ifdef COMMIT_HASH
33 char BuildVersion[]="Build version: " COMMIT_HASH ".\n";
34 #endif
35 
36 int main(int argc, char* argv[])
37 {
38  int LenIn, LenOut;
39  int i;
40  char Buf[10240];
41  FILE* F;
42 
43  if (argc != 3)
44  {
45  fprintf(stderr, "Usage: %s type filename < input\n", argv[0]);
46  exit(-1);
47  }
48 
49  F = fo_RepFwrite(argv[1], argv[2]);
50  if (!F)
51  {
52  fprintf(stderr, "ERROR: Invalid -- type='%s' filename='%s'\n",
53  argv[1], argv[2]);
54  return (-1);
55  }
56 
57  LenIn = 1;
58  while (LenIn > 0)
59  {
60  LenIn = fread(Buf, 1, sizeof(Buf), stdin);
61  if (LenIn > 0)
62  {
63  LenOut = 0;
64  while (LenOut < LenIn)
65  {
66  i = fwrite(Buf + LenOut, 1, LenIn - LenOut, F);
67  LenOut += i;
68  if (i == 0) break;
69  }
70  }
71  }
72  fo_RepFclose(F);
73  return (0);
74 } /* main() */
75 
char BuildVersion[]
Definition: buckets.c:79
FILE * fo_RepFwrite(char *Type, char *Filename)
Perform an fwrite. Also creates directories.
Definition: libfossrepo.c:722
int fo_RepFclose(FILE *F)
Perform an fclose.
Definition: libfossrepo.c:613