summaryrefslogtreecommitdiffstats
path: root/contrib/libf2c/libI77/endfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libf2c/libI77/endfile.c')
-rw-r--r--contrib/libf2c/libI77/endfile.c198
1 files changed, 94 insertions, 104 deletions
diff --git a/contrib/libf2c/libI77/endfile.c b/contrib/libf2c/libI77/endfile.c
index 4c5a9dd..513f210 100644
--- a/contrib/libf2c/libI77/endfile.c
+++ b/contrib/libf2c/libI77/endfile.c
@@ -5,136 +5,126 @@
#include <sys/types.h>
#include <unistd.h>
-#ifdef KR_headers
-extern char *strcpy();
-extern FILE *tmpfile();
-#else
#undef abs
#undef min
#undef max
#include <stdlib.h>
#include <string.h>
-#endif
extern char *f__r_mode[], *f__w_mode[];
-#ifdef KR_headers
-integer f_end(a) alist *a;
-#else
-integer f_end(alist *a)
-#endif
+integer
+f_end (alist * a)
{
- unit *b;
- FILE *tf;
+ unit *b;
+ FILE *tf;
- if (f__init & 2)
- f__fatal (131, "I/O recursion");
- if(a->aunit>=MXUNIT || a->aunit<0) err(a->aerr,101,"endfile");
- b = &f__units[a->aunit];
- if(b->ufd==NULL) {
- char nbuf[10];
- sprintf(nbuf,"fort.%ld",(long)a->aunit);
- if (tf = fopen(nbuf, f__w_mode[0]))
- fclose(tf);
- return(0);
- }
- b->uend=1;
- return(b->useek ? t_runc(a) : 0);
+ if (f__init & 2)
+ f__fatal (131, "I/O recursion");
+ if (a->aunit >= MXUNIT || a->aunit < 0)
+ err (a->aerr, 101, "endfile");
+ b = &f__units[a->aunit];
+ if (b->ufd == NULL)
+ {
+ char nbuf[10];
+ sprintf (nbuf, "fort.%ld", (long) a->aunit);
+ if ((tf = fopen (nbuf, f__w_mode[0])))
+ fclose (tf);
+ return (0);
+ }
+ b->uend = 1;
+ return (b->useek ? t_runc (a) : 0);
}
#ifndef HAVE_FTRUNCATE
- static int
-#ifdef KR_headers
-copy(from, len, to) FILE *from, *to; register long len;
-#else
-copy(FILE *from, register long len, FILE *to)
-#endif
+static int
+copy (FILE * from, register long len, FILE * to)
{
- int len1;
- char buf[BUFSIZ];
+ int len1;
+ char buf[BUFSIZ];
- while(fread(buf, len1 = len > BUFSIZ ? BUFSIZ : (int)len, 1, from)) {
- if (!fwrite(buf, len1, 1, to))
- return 1;
- if ((len -= len1) <= 0)
- break;
- }
- return 0;
- }
+ while (fread (buf, len1 = len > BUFSIZ ? BUFSIZ : (int) len, 1, from))
+ {
+ if (!fwrite (buf, len1, 1, to))
+ return 1;
+ if ((len -= len1) <= 0)
+ break;
+ }
+ return 0;
+}
#endif /* !defined(HAVE_FTRUNCATE) */
- int
-#ifdef KR_headers
-t_runc(a) alist *a;
-#else
-t_runc(alist *a)
-#endif
+int
+t_runc (alist * a)
{
- off_t loc, len;
- unit *b;
- int rc;
- FILE *bf;
+ off_t loc, len;
+ unit *b;
+ int rc;
+ FILE *bf;
#ifndef HAVE_FTRUNCATE
- FILE *tf;
+ FILE *tf;
#endif /* !defined(HAVE_FTRUNCATE) */
- b = &f__units[a->aunit];
- if(b->url)
- return(0); /*don't truncate direct files*/
- loc=FTELL(bf = b->ufd);
- FSEEK(bf,0,SEEK_END);
- len=FTELL(bf);
- if (loc >= len || b->useek == 0 || b->ufnm == NULL)
- return(0);
+ b = &f__units[a->aunit];
+ if (b->url)
+ return (0); /*don't truncate direct files */
+ loc = FTELL (bf = b->ufd);
+ FSEEK (bf, 0, SEEK_END);
+ len = FTELL (bf);
+ if (loc >= len || b->useek == 0 || b->ufnm == NULL)
+ return (0);
#ifndef HAVE_FTRUNCATE
- rc = 0;
- fclose(b->ufd);
- if (!loc) {
- if (!(bf = fopen(b->ufnm, f__w_mode[b->ufmt])))
- rc = 1;
- if (b->uwrt)
- b->uwrt = 1;
- goto done;
- }
- if (!(bf = fopen(b->ufnm, f__r_mode[0]))
- || !(tf = tmpfile())) {
+ rc = 0;
+ fclose (b->ufd);
+ if (!loc)
+ {
+ if (!(bf = fopen (b->ufnm, f__w_mode[b->ufmt])))
+ rc = 1;
+ if (b->uwrt)
+ b->uwrt = 1;
+ goto done;
+ }
+ if (!(bf = fopen (b->ufnm, f__r_mode[0])) || !(tf = tmpfile ()))
+ {
#ifdef NON_UNIX_STDIO
- bad:
+ bad:
#endif
- rc = 1;
- goto done;
- }
- if (copy(bf, loc, tf)) {
- bad1:
- rc = 1;
- goto done1;
- }
- if (!(bf = freopen(b->ufnm, f__w_mode[0], bf)))
- goto bad1;
- FSEEK(tf, 0, SEEK_SET);
- if (copy(tf, loc, bf))
- goto bad1;
- b->uwrt = 1;
- b->urw = 2;
+ rc = 1;
+ goto done;
+ }
+ if (copy (bf, loc, tf))
+ {
+ bad1:
+ rc = 1;
+ goto done1;
+ }
+ if (!(bf = freopen (b->ufnm, f__w_mode[0], bf)))
+ goto bad1;
+ FSEEK (tf, 0, SEEK_SET);
+ if (copy (tf, loc, bf))
+ goto bad1;
+ b->uwrt = 1;
+ b->urw = 2;
#ifdef NON_UNIX_STDIO
- if (b->ufmt) {
- fclose(bf);
- if (!(bf = fopen(b->ufnm, f__w_mode[3])))
- goto bad;
- FSEEK(bf,0,SEEK_END);
- b->urw = 3;
- }
+ if (b->ufmt)
+ {
+ fclose (bf);
+ if (!(bf = fopen (b->ufnm, f__w_mode[3])))
+ goto bad;
+ FSEEK (bf, 0, SEEK_END);
+ b->urw = 3;
+ }
#endif
done1:
- fclose(tf);
+ fclose (tf);
done:
- f__cf = b->ufd = bf;
-#else /* !defined(HAVE_FTRUNCATE) */
- fflush(b->ufd);
- rc = ftruncate(fileno(b->ufd), loc);
- FSEEK(bf,loc,SEEK_SET);
+ f__cf = b->ufd = bf;
+#else /* !defined(HAVE_FTRUNCATE) */
+ fflush (b->ufd);
+ rc = ftruncate (fileno (b->ufd), loc);
+ FSEEK (bf, loc, SEEK_SET);
#endif /* !defined(HAVE_FTRUNCATE) */
- if (rc)
- err(a->aerr,111,"endfile");
- return 0;
- }
+ if (rc)
+ err (a->aerr, 111, "endfile");
+ return 0;
+}
OpenPOWER on IntegriCloud