source: trunk/src/gcc/libf2c/libI77/endfile.c@ 410

Last change on this file since 410 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#include "config.h"
2#include "f2c.h"
3#include "fio.h"
4
5#include <sys/types.h>
6#include <unistd.h>
7
8#ifdef KR_headers
9extern char *strcpy();
10extern FILE *tmpfile();
11#else
12#undef abs
13#undef min
14#undef max
15#include <stdlib.h>
16#include <string.h>
17#endif
18
19extern char *f__r_mode[], *f__w_mode[];
20
21#ifdef KR_headers
22integer f_end(a) alist *a;
23#else
24integer f_end(alist *a)
25#endif
26{
27 unit *b;
28 FILE *tf;
29
30 if (f__init & 2)
31 f__fatal (131, "I/O recursion");
32 if(a->aunit>=MXUNIT || a->aunit<0) err(a->aerr,101,"endfile");
33 b = &f__units[a->aunit];
34 if(b->ufd==NULL) {
35 char nbuf[10];
36 sprintf(nbuf,"fort.%ld",(long)a->aunit);
37 if (tf = fopen(nbuf, f__w_mode[0]))
38 fclose(tf);
39 return(0);
40 }
41 b->uend=1;
42 return(b->useek ? t_runc(a) : 0);
43}
44
45#ifndef HAVE_FTRUNCATE
46 static int
47#ifdef KR_headers
48copy(from, len, to) FILE *from, *to; register long len;
49#else
50copy(FILE *from, register long len, FILE *to)
51#endif
52{
53 int len1;
54 char buf[BUFSIZ];
55
56 while(fread(buf, len1 = len > BUFSIZ ? BUFSIZ : (int)len, 1, from)) {
57 if (!fwrite(buf, len1, 1, to))
58 return 1;
59 if ((len -= len1) <= 0)
60 break;
61 }
62 return 0;
63 }
64#endif /* !defined(HAVE_FTRUNCATE) */