summaryrefslogtreecommitdiffstats
path: root/lib/libI77/err.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libI77/err.c')
-rw-r--r--lib/libI77/err.c78
1 files changed, 35 insertions, 43 deletions
diff --git a/lib/libI77/err.c b/lib/libI77/err.c
index 29747ff..e25d19f 100644
--- a/lib/libI77/err.c
+++ b/lib/libI77/err.c
@@ -1,12 +1,10 @@
#ifndef NON_UNIX_STDIO
+#define _INCLUDE_POSIX_SOURCE /* for HP-UX */
+#define _INCLUDE_XOPEN_SOURCE /* for HP-UX */
#include "sys/types.h"
#include "sys/stat.h"
#endif
#include "f2c.h"
-#include "fio.h"
-#include "fmt.h" /* for struct syl */
-#include "rawio.h" /* for fcntl.h, fdopen */
-#ifdef NON_UNIX_STDIO
#ifdef KR_headers
extern char *malloc();
#else
@@ -15,7 +13,8 @@ extern char *malloc();
#undef max
#include "stdlib.h"
#endif
-#endif
+#include "fio.h"
+#include "fmt.h" /* for struct syl */
/*global definitions*/
unit f__units[MXUNIT]; /*unit table*/
@@ -29,9 +28,11 @@ flag f__external; /*1 if external io, 0 if internal */
#ifdef KR_headers
int (*f__doed)(),(*f__doned)();
int (*f__doend)(),(*f__donewrec)(),(*f__dorevert)();
-int (*f__getn)(),(*f__putn)(); /*for formatted io*/
+int (*f__getn)(); /* for formatted input */
+void (*f__putn)(); /* for formatted output */
#else
-int (*f__getn)(void),(*f__putn)(int); /*for formatted io*/
+int (*f__getn)(void); /* for formatted input */
+void (*f__putn)(int); /* for formatted output */
int (*f__doed)(struct syl*, char*, ftnlen),(*f__doned)(struct syl*);
int (*f__dorevert)(void),(*f__donewrec)(void),(*f__doend)(void);
#endif
@@ -171,11 +172,6 @@ f_init(Void)
p= &f__units[0];
p->ufd=stderr;
p->useek=f__canseek(stderr);
-#ifdef NON_UNIX_STDIO
- setbuf(stderr, (char *)malloc(BUFSIZ));
-#else
- stderr->_flag &= ~_IONBF;
-#endif
p->ufmt=1;
p->uwrt=1;
p = &f__units[5];
@@ -196,21 +192,29 @@ f__nowreading(unit *x)
#endif
{
long loc;
- int ufmt;
- extern char *f__r_mode[];
+ int ufmt, urw;
+ extern char *f__r_mode[], *f__w_mode[];
+ if (x->urw & 1)
+ goto done;
if (!x->ufnm)
goto cantread;
- ufmt = x->ufmt;
- loc=ftell(x->ufd);
- if(freopen(x->ufnm,f__r_mode[ufmt],x->ufd) == NULL) {
+ ufmt = x->url ? 0 : x->ufmt;
+ loc = ftell(x->ufd);
+ urw = 3;
+ if (!freopen(x->ufnm, f__w_mode[ufmt|2], x->ufd)) {
+ urw = 1;
+ if(!freopen(x->ufnm, f__r_mode[ufmt], x->ufd)) {
cantread:
- errno = 126;
- return(1);
+ errno = 126;
+ return 1;
+ }
}
- x->uwrt=0;
- (void) fseek(x->ufd,loc,SEEK_SET);
- return(0);
+ fseek(x->ufd,loc,SEEK_SET);
+ x->urw = urw;
+ done:
+ x->uwrt = 0;
+ return 0;
}
#ifdef KR_headers
f__nowwriting(x) unit *x;
@@ -221,46 +225,34 @@ f__nowwriting(unit *x)
long loc;
int ufmt;
extern char *f__w_mode[];
-#ifndef NON_UNIX_STDIO
- int k;
-#endif
+ if (x->urw & 2)
+ goto done;
if (!x->ufnm)
goto cantwrite;
- ufmt = x->ufmt;
-#ifdef NON_UNIX_STDIO
- ufmt |= 2;
-#endif
+ ufmt = x->url ? 0 : x->ufmt;
if (x->uwrt == 3) { /* just did write, rewind */
-#ifdef NON_UNIX_STDIO
if (!(f__cf = x->ufd =
freopen(x->ufnm,f__w_mode[ufmt],x->ufd)))
-#else
- if (close(creat(x->ufnm,0666)))
-#endif
goto cantwrite;
+ x->urw = 2;
}
else {
loc=ftell(x->ufd);
-#ifdef NON_UNIX_STDIO
if (!(f__cf = x->ufd =
- freopen(x->ufnm, f__w_mode[ufmt], x->ufd)))
-#else
- if (fclose(x->ufd) < 0
- || (k = x->uwrt == 2 ? creat(x->ufnm,0666)
- : open(x->ufnm,O_WRONLY)) < 0
- || (f__cf = x->ufd = fdopen(k,f__w_mode[ufmt])) == NULL)
-#endif
+ freopen(x->ufnm, f__w_mode[ufmt |= 2], x->ufd)))
{
x->ufd = NULL;
cantwrite:
errno = 127;
return(1);
}
- (void) fseek(x->ufd,loc,SEEK_SET);
+ x->urw = 3;
+ fseek(x->ufd,loc,SEEK_SET);
}
+ done:
x->uwrt = 1;
- return(0);
+ return 0;
}
int
OpenPOWER on IntegriCloud