File: append.c

package info (click to toggle)
gcl 2.6.14-19
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 60,804 kB
  • sloc: ansic: 177,407; lisp: 151,508; asm: 128,169; sh: 22,510; cpp: 11,923; tcl: 3,181; perl: 2,930; makefile: 2,360; sed: 334; yacc: 226; lex: 95; awk: 30; fortran: 24; csh: 23
file content (35 lines) | stat: -rwxr-xr-x 673 bytes parent folder | download | duplicates (14)
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
#include <stdio.h>
/* usage:   append a b c
   equivalent to cat a b >> c
   if only cat were binary... but by some wonderful dos like deicision,
   it is not under cygnus..
   */   
int
main(int argc,char *argv[])
{ int i;
  FILE *out ;
  if (argc < 2) return 0;
  out = fopen(argv[argc-1],"a+b");
  if (out == 0)
    { perror("cant open"); return 1; }
  for (i=1; i < argc-1 ; i++)
    {
      FILE *fp = fopen(argv[i],"rb");
      int ch;
      if (fp == 0)
	{ perror("cant open"); return 1; }
      while (1) {
	ch =getc(fp);
	if (ch == EOF && feof(fp))
	  { fclose(fp);
	  break;
	  } else
	    putc(ch,out);
      
      }
    }
  fclose(out);
  return 0;
}