Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions runtime/flang/backspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ _f90io_backspace(__INT_T *unit, __INT_T *bitv, __INT_T *iostat, int swap_bytes)

if (f->nonadvance) {
f->nonadvance = FALSE;
FIO_FCB_INVALIDATE_GETC_BUFFER(f, return __io_errno());
#if defined(WINNT)
if (__fortio_binary_mode(f->fp))
__io_fputc('\r', f->fp);
if (__fortio_binary_mode(f->__io_fp))
__io_fputc('\r', f->__io_fp);
#endif
__io_fputc('\n', f->fp);
if (__io_ferror(f->fp))
__io_fputc('\n', f->__io_fp);
if (__io_ferror(f->__io_fp))
return __io_errno();
}

fp = f->fp;
/* if already at the beginning just return without error */
/* if (f->nextrec < 2) */
if (__io_ftell(fp) == 0) /* use ftell in case file opened 'append' */
if (FIO_FCB_FTELL(f) == 0) /* use ftell in case file opened 'append' */
return 0;

if (f->form == FIO_UNFORMATTED) { /* CASE 1: unformatted file */
Expand All @@ -95,6 +95,9 @@ _f90io_backspace(__INT_T *unit, __INT_T *bitv, __INT_T *iostat, int swap_bytes)
so back up over trailing length field, read the size, then
back up over the record and both length fields */

FIO_FCB_INVALIDATE_GETC_BUFFER(f, return __fortio_error(__io_errno()));
fp = f->__io_fp;

rec_continued:
if (__io_fseek(fp, -((seekoffx_t)RCWSZ), SEEK_CUR) != 0)
return __fortio_error(__io_errno());
Expand All @@ -112,17 +115,21 @@ _f90io_backspace(__INT_T *unit, __INT_T *bitv, __INT_T *iostat, int swap_bytes)
goto rec_continued;
f->coherent = 0; /* avoid unnecessary seek later on */
} else { /* CASE 2: formatted file */
int ch;
seekoffx_t pos;
assert(f->form == FIO_FORMATTED);
pos = __io_ftell(fp) - 1;
pos = FIO_FCB_FTELL(f) - 1L;
assert(pos >= 0);
while (TRUE) {
if (pos > 0)
--pos;
if (__io_fseek(fp, pos, SEEK_SET) != 0)
return __fortio_error(__io_errno());
FIO_FCB_FSEEK_SET(f, pos, return __fortio_error(__io_errno()));

if (pos == 0 || __io_fgetc(fp) == '\n') {
if (pos == 0)
ch = 0;
else
FIO_FCB_BUFFERED_GETC(ch, f, return __fortio_error(__io_errno()));
if (pos == 0 || ch == '\n') {
/* must set coherent flag to 'read' in case the next operation
on this file is a write: */
f->coherent = 2 /*read*/;
Expand Down
16 changes: 8 additions & 8 deletions runtime/flang/close.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ __fortio_close(FIO_FCB *f, int flag)
if (f->nonadvance) {
f->nonadvance = FALSE;
#if defined(WINNT)
if (__fortio_binary_mode(f->fp))
__io_fputc('\r', f->fp);
if (__fortio_binary_mode(f->__io_fp))
__io_fputc('\r', f->__io_fp);
#endif
__io_fputc('\n', f->fp);
if (__io_ferror(f->fp))
__io_fputc('\n', f->__io_fp);
if (__io_ferror(f->__io_fp))
return __io_errno();
}

if (!f->stdunit) {
if (__io_fclose(f->fp) != 0) {
if (__io_fclose(f->__io_fp) != 0) {
return __fortio_error(__io_errno());
}
if (flag == 0 && f->dispose == FIO_DELETE)
Expand All @@ -79,7 +79,7 @@ __fortio_close(FIO_FCB *f, int flag)
#if defined(TARGET_OSX)
if (f->unit != 5 && f->unit != -5)
#endif
if (__io_fflush(f->fp) != 0)
if (__io_fflush(f->__io_fp) != 0)
return __fortio_error(__io_errno());
}

Expand Down Expand Up @@ -201,10 +201,10 @@ __fortio_cleanup(void)
* consequently, need to extract the 'next' field now.
*/
f_next = f->next;
if (f->fp == NULL) { /* open? */
if (f->__io_fp == NULL) { /* open? */
continue;
}
__io_fflush(f->fp);
__io_fflush(f->__io_fp);
if (f->stdunit) { /* standard unit? */
continue;
}
Expand Down
17 changes: 9 additions & 8 deletions runtime/flang/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,11 @@ __fortio_error(int errval)
}

fioFcbTbls.error = TRUE;
if (fdesc && fdesc->fp && fdesc->acc == FIO_DIRECT) {
if (fdesc && fdesc->__io_fp && fdesc->acc == FIO_DIRECT) {
/* leave file in consistent state: */
fdesc->nextrec = 1;
__io_fseek(fdesc->fp, 0L, SEEK_SET);
FIO_FCB_INVALIDATE_GETC_BUFFER_BEFORE_FSEEK(fdesc);
__io_fseek(fdesc->__io_fp, 0L, SEEK_SET);
}

if ((iobitv & FIO_BITV_EOR) && (errval == FIO_ETOOBIG)) {
Expand Down Expand Up @@ -837,7 +838,7 @@ win_set_binary(FIO_FCB *f)
{
FILE *fil;

fil = f->fp;
fil = f->__io_fp;
if (!__fort_isatty(__fort_getfd(fil))) {
__fortio_setmode_binary(fil);
}
Expand All @@ -863,7 +864,7 @@ __fortio_init(void)
/* preconnect stdin as unit -5 for * unit specifier */
f = __fortio_alloc_fcb();

f->fp = __io_stdin();
f->__io_fp = __io_stdin();
f->unit = -5;
f->name = "stdin ";
f->reclen = 0;
Expand Down Expand Up @@ -894,7 +895,7 @@ __fortio_init(void)
/* preconnect stdout as unit -6 for * unit specifier */
f = __fortio_alloc_fcb();

f->fp = __io_stdout();
f->__io_fp = __io_stdout();
f->unit = -6;
f->name = "stdout ";
f->reclen = 0;
Expand Down Expand Up @@ -925,7 +926,7 @@ __fortio_init(void)
/* preconnect stdin as unit 5 */
f = __fortio_alloc_fcb();

f->fp = __io_stdin();
f->__io_fp = __io_stdin();
f->unit = 5;
f->name = "stdin ";
f->reclen = 0;
Expand Down Expand Up @@ -956,7 +957,7 @@ __fortio_init(void)
/* preconnect stdout as unit 6 */
f = __fortio_alloc_fcb();

f->fp = __io_stdout();
f->__io_fp = __io_stdout();
f->unit = 6;
f->name = "stdout ";
f->reclen = 0;
Expand Down Expand Up @@ -987,7 +988,7 @@ __fortio_init(void)
/* preconnect stderr as unit 0 */
f = __fortio_alloc_fcb();

f->fp = __io_stderr();
f->__io_fp = __io_stderr();
f->unit = 0;
f->name = "stderr ";
f->reclen = 0;
Expand Down
2 changes: 1 addition & 1 deletion runtime/flang/flush.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ __INT_T *iostat;
}
}

if (__io_fflush(f->fp) != 0) {
if (__io_fflush(f->__io_fp) != 0) {
s = __fortio_error(__io_errno());
__fortio_errend03();
return s;
Expand Down
21 changes: 12 additions & 9 deletions runtime/flang/fmtread.c
Original file line number Diff line number Diff line change
Expand Up @@ -3221,7 +3221,7 @@ fr_read_record(void)
g->rec_buff += g->rec_len; /* point to next record */
} else { /* external file */
FIO_FCB *f = g->fcb;
FILE *fp = f->fp;

if (f->pread) {
int idx = 0;
char *p = f->pread;
Expand All @@ -3230,7 +3230,7 @@ fr_read_record(void)
while (TRUE) { /* read one char per iteration until '\n' */
int c = *(p++);
if (c == EOF) {
if (__io_feof(fp)) {
if (__io_feof(f->__io_fp)) {
if (idx)
break;
return FIO_EEOF;
Expand Down Expand Up @@ -3264,15 +3264,18 @@ fr_read_record(void)
if (f->acc == FIO_DIRECT) {
if (f->nextrec > f->maxrec + 1)
return FIO_EDREAD; /* attempt to read non-existent rec */
if (__io_fread(g->rec_buff, 1, g->rec_len, fp) != g->rec_len)
FIO_FCB_INVALIDATE_GETC_BUFFER(f, return __io_errno());
if (__io_fread(g->rec_buff, 1, g->rec_len, f->__io_fp) != g->rec_len)
return __io_errno();
} else { /* sequential read */
idx = 0;

while (TRUE) { /* read one char per iteration until '\n' */
int c = __io_fgetc(fp);
int c;

FIO_FCB_BUFFERED_GETC(c, f, return __io_errno());
if (c == EOF) {
if (__io_feof(fp)) {
if (__io_feof(f->__io_fp)) {
if (idx)
break;
if (g->nonadvance && !g->eor_seen && g->rec_len != 0)
Expand All @@ -3284,12 +3287,12 @@ fr_read_record(void)
return __io_errno();
}
if (c == '\r' && EOR_CRLF) {
c = __io_fgetc(fp);
FIO_FCB_BUFFERED_GETC(c, f, return __io_errno());
if (c == '\n') {
g->eor_len = 2;
break;
}
__io_ungetc(c, fp);
FIO_FCB_BUFFERED_UNGETC(c, f);
c = '\r';
}
if (c == '\n') {
Expand Down Expand Up @@ -3382,7 +3385,7 @@ _f90io_fmtr_end(void)
int i;
i = g->rec_len - g->curr_pos + g->eor_len;
--(g->fcb->nextrec); /* decr errmsg recnum */
if (__io_fseek(g->fcb->fp, (seekoffx_t)-i, SEEK_CUR) != 0) {
FIO_FCB_FSEEK_CUR(g->fcb, (seekoffx_t)-i, {
if (g->fcb->stdunit) {
/*
* Can't seek stdin, but need to leave the postion
Expand All @@ -3393,7 +3396,7 @@ _f90io_fmtr_end(void)
return 0;
}
return __fortio_error(__io_errno());
}
});
}
}
}
Expand Down
23 changes: 14 additions & 9 deletions runtime/flang/fmtwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -2617,40 +2617,45 @@ fw_write_record(void)
FIO_FCB *f = g->fcb;

if (f->acc == FIO_DIRECT) {
if (FWRITE(g->rec_buff, 1, g->rec_len, f->fp) != (int)g->rec_len)
FIO_FCB_INVALIDATE_GETC_BUFFER(f, return __io_errno());
if (FWRITE(g->rec_buff, 1, g->rec_len, f->__io_fp) != (int)g->rec_len)
return __io_errno();
} else { /* sequential write */
if (g->nonadvance) {
if (g->curr_pos >= g->max_pos) {
g->max_pos = g->curr_pos;
fw_check_size(g->max_pos);
if (FWRITE(g->rec_buff, 1, g->max_pos, f->fp) != (int)g->max_pos)
FIO_FCB_INVALIDATE_GETC_BUFFER(f, return __io_errno());
if (FWRITE(g->rec_buff, 1, g->max_pos, f->__io_fp) != (int)g->max_pos)
return __io_errno();
} else if (g->curr_pos < g->max_pos) {
long len = g->max_pos - g->curr_pos;

if (FWRITE(g->rec_buff, 1, g->curr_pos, f->fp) != (int)g->curr_pos)
FIO_FCB_INVALIDATE_GETC_BUFFER(f, return __io_errno());
if (FWRITE(g->rec_buff, 1, g->curr_pos, f->__io_fp) != (int)g->curr_pos)
return __io_errno();
g->fcb->skip = len;
g->fcb->skip_buff = malloc(len);
memcpy(g->fcb->skip_buff, &g->rec_buff[g->curr_pos], len);
}
f->nonadvance = TRUE; /* do it later */
} else {
if (FWRITE(g->rec_buff, 1, g->max_pos, f->fp) != (int)g->max_pos)
FIO_FCB_INVALIDATE_GETC_BUFFER(f, return __io_errno());
if (FWRITE(g->rec_buff, 1, g->max_pos, f->__io_fp) != (int)g->max_pos)
return __io_errno();
f->nonadvance = FALSE; /* do it now */
if (!(g->suppress_crlf)) {
FIO_FCB_INVALIDATE_GETC_BUFFER(f, return __io_errno());
/* append carriage return */
#if defined(WINNT)
if (__fortio_binary_mode(f->fp))
__io_fputc('\r', f->fp);
if (__fortio_binary_mode(f->__io_fp))
__io_fputc('\r', f->__io_fp);
#endif
/* if (g->max_pos > 0)*/
__io_fputc('\n', f->fp);
if (__io_ferror(f->fp))
__io_fputc('\n', f->__io_fp);
if (__io_ferror(f->__io_fp))
return __io_errno();
} else if (fflush(f->fp) != 0)
} else if (fflush(f->__io_fp) != 0)
return __io_errno();
}
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/flang/fstat3f.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int ENT3F(FSTAT, fstat)(int *lu, int *statb)

f = __fio_find_unit(*lu);
if (f && !FIO_FCB_STDUNIT(f)) {
/* need a way to get f->fp's fildes */
/* need a way to get f->__io_fp's fildes */
if (i = _stat32(FIO_FCB_NAME(f), &b))
i = __io_errno();
} else {
Expand Down Expand Up @@ -78,7 +78,7 @@ int ENT3F(FSTAT, fstat)(int *lu, int *statb)

f = __fio_find_unit(*lu);
if (f && !FIO_FCB_STDUNIT(f)) {
/** need a way to get f->fp's fildes **/
/** need a way to get f->__io_fp's fildes **/
if ((i = stat(FIO_FCB_NAME(f), &b)))
i = __io_errno();
} else {
Expand Down
4 changes: 2 additions & 2 deletions runtime/flang/fstat643f.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int ENT3F(FSTAT64, fstat64)(int *lu, long long *statb)

f = __fio_find_unit(*lu);
if (f && !FIO_FCB_STDUNIT(f)) {
/** need a way to get f->fp's fildes **/
/** need a way to get f->__io_fp's fildes **/
if (i = _stat64(FIO_FCB_NAME(f), bp))
i = __io_errno();
} else {
Expand Down Expand Up @@ -102,7 +102,7 @@ int ENT3F(FSTAT64, fstat64)(int *lu, long long *statb)

f = __fio_find_unit(*lu);
if (f && !FIO_FCB_STDUNIT(f)) {
/** need a way to get f->fp's fildes **/
/** need a way to get f->__io_fp's fildes **/
if ((i = stat(FIO_FCB_NAME(f), &b)))
i = __io_errno();
} else {
Expand Down
Loading