summaryrefslogtreecommitdiff
path: root/libf2c/libI77/endfile.c
diff options
context:
space:
mode:
authorfx <fx@138bc75d-0d04-0410-961f-82ee72b054a4>1998-05-19 10:52:03 +0000
committerfx <fx@138bc75d-0d04-0410-961f-82ee72b054a4>1998-05-19 10:52:03 +0000
commit3ad649e5f9e3e4dd6f1c965916b1427a7d56fdd5 (patch)
treec4e8e02849cc5a16fa5bc00db65b9b2aa8561eaf /libf2c/libI77/endfile.c
parent6e0804a53327a47eadbc1edac8c64e3aa7b1f579 (diff)
downloadgcc-3ad649e5f9e3e4dd6f1c965916b1427a7d56fdd5.tar.gz
Update to Netlib version of 1998-04-20
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@19877 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libf2c/libI77/endfile.c')
-rw-r--r--libf2c/libI77/endfile.c114
1 files changed, 20 insertions, 94 deletions
diff --git a/libf2c/libI77/endfile.c b/libf2c/libI77/endfile.c
index 6050d1e3b30..0b785a95165 100644
--- a/libf2c/libI77/endfile.c
+++ b/libf2c/libI77/endfile.c
@@ -1,10 +1,9 @@
#include "f2c.h"
#include "fio.h"
-#include <sys/types.h>
-#include "rawio.h"
#ifdef KR_headers
extern char *strcpy();
+extern FILE *tmpfile();
#else
#undef abs
#undef min
@@ -13,19 +12,7 @@ extern char *strcpy();
#include <string.h>
#endif
-#ifdef NON_UNIX_STDIO
-#ifndef unlink
-#define unlink remove
-#endif
-#else
-#if defined (MSDOS) && !defined (GO32)
-#include "io.h"
-#endif
-#endif
-
-#ifdef NON_UNIX_STDIO
extern char *f__r_mode[], *f__w_mode[];
-#endif
#ifdef KR_headers
integer f_end(a) alist *a;
@@ -34,21 +21,17 @@ integer f_end(alist *a)
#endif
{
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];
- (void) sprintf(nbuf,"fort.%ld",a->aunit);
-#ifdef NON_UNIX_STDIO
- { FILE *tf;
- if (tf = fopen(nbuf, f__w_mode[0]))
- fclose(tf);
- }
-#else
- close(creat(nbuf, 0666));
-#endif
+ sprintf(nbuf,"fort.%ld",a->aunit);
+ if (tf = fopen(nbuf, f__w_mode[0]))
+ fclose(tf);
return(0);
}
b->uend=1;
@@ -56,14 +39,13 @@ integer f_end(alist *a)
}
static int
-#ifdef NON_UNIX_STDIO
#ifdef KR_headers
-copy(from, len, to) char *from, *to; register long len;
+copy(from, len, to) FILE *from, *to; register long len;
#else
copy(FILE *from, register long len, FILE *to)
#endif
{
- int k, len1;
+ int len1;
char buf[BUFSIZ];
while(fread(buf, len1 = len > BUFSIZ ? BUFSIZ : (int)len, 1, from)) {
@@ -74,36 +56,6 @@ copy(FILE *from, register long len, FILE *to)
}
return 0;
}
-#else
-#ifdef KR_headers
-copy(from, len, to) char *from, *to; register long len;
-#else
-copy(char *from, register long len, char *to)
-#endif
-{
- register size_t n;
- int k, rc = 0, tmp;
- char buf[BUFSIZ];
-
- if ((k = open(from, O_RDONLY)) < 0)
- return 1;
- if ((tmp = creat(to,0666)) < 0)
- return 1;
- while((n = read(k, buf, (size_t) (len > BUFSIZ ? BUFSIZ : (int)len))) > 0) {
- if (write(tmp, buf, n) != n)
- { rc = 1; break; }
- if ((len -= n) <= 0)
- break;
- }
- close(k);
- close(tmp);
- return n < 0 ? 1 : rc;
- }
-#endif
-
-#ifndef L_tmpnam
-#define L_tmpnam 16
-#endif
int
#ifdef KR_headers
@@ -112,14 +64,9 @@ t_runc(a) alist *a;
t_runc(alist *a)
#endif
{
- char nm[L_tmpnam+12]; /* extra space in case L_tmpnam is tiny */
long loc, len;
unit *b;
-#ifdef NON_UNIX_STDIO
FILE *bf, *tf;
-#else
- FILE *bf;
-#endif
int rc = 0;
b = &f__units[a->aunit];
@@ -130,36 +77,20 @@ t_runc(alist *a)
len=ftell(bf);
if (loc >= len || b->useek == 0 || b->ufnm == NULL)
return(0);
-#ifdef NON_UNIX_STDIO
fclose(b->ufd);
-#else
- rewind(b->ufd); /* empty buffer */
-#endif
if (!loc) {
-#ifdef NON_UNIX_STDIO
if (!(bf = fopen(b->ufnm, f__w_mode[b->ufmt])))
-#else
- if (close(creat(b->ufnm,0666)))
-#endif
rc = 1;
if (b->uwrt)
b->uwrt = 1;
goto done;
}
-#ifdef _POSIX_SOURCE
- tmpnam(nm);
-#else
- strcpy(nm,"tmp.FXXXXXX");
- mktemp(nm);
-#endif
-#ifdef NON_UNIX_STDIO
- if (!(bf = fopen(b->ufnm, f__r_mode[0]))) {
+ if (!(bf = fopen(b->ufnm, f__r_mode[0]))
+ || !(tf = tmpfile())) {
bad:
rc = 1;
goto done;
}
- if (!(tf = fopen(nm, f__w_mode[0])))
- goto bad;
if (copy(bf, loc, tf)) {
bad1:
rc = 1;
@@ -167,28 +98,23 @@ t_runc(alist *a)
}
if (!(bf = freopen(b->ufnm, f__w_mode[0], bf)))
goto bad1;
- if (!(tf = freopen(nm, f__r_mode[0], tf)))
- goto bad1;
+ rewind(tf);
if (copy(tf, loc, bf))
goto bad1;
- if (f__w_mode[0] != f__w_mode[b->ufmt]) {
- if (!(bf = freopen(b->ufnm, f__w_mode[b->ufmt|2], bf)))
- goto bad1;
- fseek(bf, loc, SEEK_SET);
+ 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,0L,SEEK_END);
+ b->urw = 3;
}
+#endif
done1:
fclose(tf);
- unlink(nm);
done:
f__cf = b->ufd = bf;
-#else
- if (copy(b->ufnm, loc, nm)
- || copy(nm, loc, b->ufnm))
- rc = 1;
- unlink(nm);
- fseek(b->ufd, loc, SEEK_SET);
-done:
-#endif
if (rc)
err(a->aerr,111,"endfile");
return 0;