6 extern FILE *tmpfile();
15 extern char *f__r_mode[], *f__w_mode[];
18 integer f_end(a) alist *a;
20 integer f_end(alist *a)
27 f__fatal (131, "I/O recursion");
28 if(a->aunit>=MXUNIT || a->aunit<0) err(a->aerr,101,"endfile");
29 b = &f__units[a->aunit];
32 sprintf(nbuf,"fort.%ld",a->aunit);
33 if (tf = fopen(nbuf, f__w_mode[0]))
38 return(b->useek ? t_runc(a) : 0);
43 copy(from, len, to) FILE *from, *to; register long len;
45 copy(FILE *from, register long len, FILE *to)
51 while(fread(buf, len1 = len > BUFSIZ ? BUFSIZ : (int)len, 1, from)) {
52 if (!fwrite(buf, len1, 1, to))
54 if ((len -= len1) <= 0)
72 b = &f__units[a->aunit];
74 return(0); /*don't truncate direct files*/
75 loc=ftell(bf = b->ufd);
76 fseek(bf,0L,SEEK_END);
78 if (loc >= len || b->useek == 0 || b->ufnm == NULL)
82 if (!(bf = fopen(b->ufnm, f__w_mode[b->ufmt])))
88 if (!(bf = fopen(b->ufnm, f__r_mode[0]))
89 || !(tf = tmpfile())) {
96 if (copy(bf, loc, tf)) {
101 if (!(bf = freopen(b->ufnm, f__w_mode[0], bf)))
104 if (copy(tf, loc, bf))
107 #ifdef NON_UNIX_STDIO
110 if (!(bf = fopen(b->ufnm, f__w_mode[3])))
112 fseek(bf,0L,SEEK_END);
121 err(a->aerr,111,"endfile");