Mail Archives: djgpp-workers/2001/06/05/14:05:22
Here's my patch to eliminate _IOAPPEND. I also took Martin's suggestion from
a while back and added/used __get_fd_flags.
Index: libc/ansi/stdio/fflush.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/fflush.c,v
retrieving revision 1.6
diff -c -p -r1.6 fflush.c
*** libc/ansi/stdio/fflush.c 2001/05/22 20:48:25 1.6
--- libc/ansi/stdio/fflush.c 2001/06/05 17:42:09
***************
*** 11,16 ****
--- 11,17 ----
#include <unistd.h>
#include <libc/file.h>
#include <io.h>
+ #include <libc/fd_props.h>
int
fflush(FILE *f)
*************** fflush(FILE *f)
*** 30,36 ****
return 0;
}
! if (f->_flag & _IOAPPEND)
{
int save_errno = errno; /* We don't want llseek()'s setting
errno to remain. */
--- 31,38 ----
return 0;
}
! if (__has_fd_properties(fileno(f))
! && (__get_fd_flags(fileno(f)) & FILE_DESC_APPEND))
{
int save_errno = errno; /* We don't want llseek()'s setting
errno to remain. */
Index: libc/ansi/stdio/file.doc
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/file.doc,v
retrieving revision 1.4
diff -c -p -r1.4 file.doc
*** libc/ansi/stdio/file.doc 2000/11/19 06:52:57 1.4
--- libc/ansi/stdio/file.doc 2001/06/05 17:42:09
*************** _IOMYBUF buffer needs to be freed
*** 28,34 ****
_IOEOF file is at EOF
_IOERR error occurred
_IOSTRG sprintf
- _IOAPPEND append mode
_IORMONCL remove file on close
_IOUNGETC buffer contents does not correspond to file
_IOTERM file's handle hooked by termios
--- 28,33 ----
Index: libc/ansi/stdio/flsbuf.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/flsbuf.c,v
retrieving revision 1.6
diff -c -p -r1.6 flsbuf.c
*** libc/ansi/stdio/flsbuf.c 2001/05/22 20:48:25 1.6
--- libc/ansi/stdio/flsbuf.c 2001/06/05 17:42:09
***************
*** 11,16 ****
--- 11,17 ----
#include <go32.h>
#include <libc/file.h>
#include <io.h>
+ #include <libc/fd_props.h>
int
_flsbuf(int c, FILE *f)
*************** _flsbuf(int c, FILE *f)
*** 97,113 ****
|| __libc_write_termios_hook == NULL
|| __libc_write_termios_hook(fileno(f), base, rn, &n) == 0)
{
! if (f->_flag & _IOAPPEND)
{
int save_errno = errno; /* We don't want llseek()'s setting
errno to remain. */
! if( llseek(fileno(f), 0, SEEK_END) == -1 )
{
errno = save_errno;
return EOF;
}
}
! n = _write(fileno(f), base, rn);
}
if (n <= 0)
{
--- 98,116 ----
|| __libc_write_termios_hook == NULL
|| __libc_write_termios_hook(fileno(f), base, rn, &n) == 0)
{
! int fd = fileno(f);
! if (__has_fd_properties(fd)
! && (__get_fd_flags(fd) & FILE_DESC_APPEND))
{
int save_errno = errno; /* We don't want llseek()'s setting
errno to remain. */
! if( llseek(fd, 0, SEEK_END) == -1 )
{
errno = save_errno;
return EOF;
}
}
! n = _write(fd, base, rn);
}
if (n <= 0)
{
Index: libc/ansi/stdio/fopen.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/fopen.c,v
retrieving revision 1.2
diff -c -p -r1.2 fopen.c
*** libc/ansi/stdio/fopen.c 2001/05/22 20:48:25 1.2
--- libc/ansi/stdio/fopen.c 2001/06/05 17:42:10
*************** fopen(const char *file, const char *mode
*** 68,74 ****
if (*mode == 'a')
{
- f->_flag |= _IOAPPEND;
llseek(fd, 0, SEEK_END);
}
--- 68,73 ----
Index: libc/ansi/stdio/freopen.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/freopen.c,v
retrieving revision 1.4
diff -c -p -r1.4 freopen.c
*** libc/ansi/stdio/freopen.c 2001/05/22 20:48:25 1.4
--- libc/ansi/stdio/freopen.c 2001/06/05 17:42:10
*************** freopen(const char *file, const char *mo
*** 62,68 ****
if (*mode == 'a')
{
- f->_flag |= _IOAPPEND;
llseek(fd, 0, SEEK_END);
}
--- 62,67 ----
Index: libc/posix/stdio/fdopen.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/stdio/fdopen.c,v
retrieving revision 1.2
diff -c -p -r1.2 fdopen.c
*** libc/posix/stdio/fdopen.c 2001/05/22 20:48:25 1.2
--- libc/posix/stdio/fdopen.c 2001/06/05 17:42:26
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/types.h>
***************
*** 7,12 ****
--- 8,14 ----
#include <io.h>
#include <libc/file.h>
#include <libc/local.h>
+ #include <libc/fd_props.h>
FILE *
fdopen(int fildes, const char *mode)
*************** fdopen(int fildes, const char *mode)
*** 46,56 ****
else
oflags |= (_fmode & (O_TEXT|O_BINARY));
- if (*mode == 'a')
- {
- f->_flag |= _IOAPPEND;
- }
-
f->_cnt = 0;
f->_file = fildes;
f->_bufsiz = 0;
--- 48,53 ----
*************** fdopen(int fildes, const char *mode)
*** 64,69 ****
--- 61,75 ----
f->_base = f->_ptr = NULL;
setmode(fildes, oflags & (O_TEXT|O_BINARY));
+
+ /* Set or clear the append flag according to the mode. */
+ if (__has_fd_properties(fildes))
+ {
+ if (*mode == 'a')
+ __set_fd_flags(fildes, FILE_DESC_APPEND);
+ else
+ __clear_fd_flags(fildes, FILE_DESC_APPEND);
+ }
return f;
}
Index: include/libc/fd_props.h
===================================================================
RCS file: /cvs/djgpp/djgpp/include/libc/fd_props.h,v
retrieving revision 1.4
diff -c -p -r1.4 fd_props.h
*** include/libc/fd_props.h 2001/05/22 20:48:25 1.4
--- include/libc/fd_props.h 2001/06/05 17:53:41
*************** static __inline__ void __clear_fd_flags(
*** 60,65 ****
--- 60,70 ----
__fd_properties[_fd]->flags &= ~_flags;
}
+ static __inline__ unsigned long __get_fd_flags(int _fd)
+ {
+ return __fd_properties[_fd]->flags;
+ }
+
#endif /* !_POSIX_SOURCE */
#endif /* !__STRICT_ANSI__ */
#endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
- Raw text -