[daveroth@acm.org: 1.5.0: Problem with fseeko() after fdopen()]

J. Johnston jjohnstn@redhat.com
Fri Jul 25 16:27:00 GMT 2003


Looks good.  Please change the doc comment that fdopen is ANSI.  It is a newlib
extension.  There is some logic missing from fdopen() regarding initializing
the lock which should be in your code as well.

-- Jeff J.

Christopher Faylor wrote:
> On Thu, Jul 24, 2003 at 06:56:28PM -0400, J. Johnston wrote:
> 
>>A fdopen64.c is required and cygwin will have to map to it like it has
>>done for the other io64 routines.
> 
> 
> Ok to apply?
> 
> cgf
> 
> 2003-07-24  Christopher Faylor  <cgf@redhat.com>
> 
> 	* libc/stdio64/fdopen64.c: New file.
> 	* libc/stdio64/Makefile.am (LIB_OBJS): Add fdopen64.o
> 	* libc/stdio64/Makefile.in: Regenerate.
> 	* libc/include/stdio.h (fdopen64): Define.
> 	* libc/include/stdio.h (_fdopen64_r): Ditto.
> 
> Index: libc/include/stdio.h
> ===================================================================
> RCS file: /cvs/uberbaum/newlib/libc/include/stdio.h,v
> retrieving revision 1.23
> diff -u -p -r1.23 stdio.h
> --- libc/include/stdio.h	13 May 2003 09:46:48 -0000	1.23
> +++ libc/include/stdio.h	25 Jul 2003 02:34:26 -0000
> @@ -309,6 +309,7 @@ ssize_t _EXFUN(__getline, (char **, size
>  
>  #ifdef __LARGE64_FILES
>  #ifndef __CYGWIN__
> +FILE *	_EXFUN(fdopen64, (int, const char *));
>  FILE *  _EXFUN(fopen64, (const char *, const char *));
>  _off64_t _EXFUN(ftello64, (FILE *));
>  _off64_t _EXFUN(fseeko64, (FILE *, _off64_t, int));
> @@ -316,6 +317,7 @@ int     _EXFUN(fgetpos64, (FILE *, _fpos
>  int     _EXFUN(fsetpos64, (FILE *, const _fpos64_t *));
>  FILE *  _EXFUN(tmpfile64, (void));
>  
> +FILE *	_EXFUN(_fdopen64_r, (struct _reent *, int, const char *));
>  FILE *  _EXFUN(_fopen64_r, (struct _reent *,const char *, const char *));
>  _off64_t _EXFUN(_ftello64_r, (struct _reent *, FILE *));
>  _off64_t _EXFUN(_fseeko64_r, (struct _reent *, FILE *, _off64_t, int));
> Index: libc/stdio64/Makefile.am
> ===================================================================
> RCS file: /cvs/uberbaum/newlib/libc/stdio64/Makefile.am,v
> retrieving revision 1.4
> diff -u -p -r1.4 Makefile.am
> --- libc/stdio64/Makefile.am	26 Aug 2002 18:56:07 -0000	1.4
> +++ libc/stdio64/Makefile.am	25 Jul 2003 02:34:26 -0000
> @@ -12,6 +12,7 @@ if ELIX_LEVEL_1
>  LIB_OBJS =
>  else
>  LIB_OBJS = \
> +	fdopen64.$(oext) 	\
>  	fgetpos64.$(oext)	\
>  	fopen64.$(oext) 	\
>  	freopen64.$(oext) 	\
> Index: libc/stdio64/Makefile.in
> ===================================================================
> RCS file: /cvs/uberbaum/newlib/libc/stdio64/Makefile.in,v
> retrieving revision 1.6
> diff -u -p -r1.6 Makefile.in
> --- libc/stdio64/Makefile.in	26 Aug 2002 18:56:07 -0000	1.6
> +++ libc/stdio64/Makefile.in	25 Jul 2003 02:34:26 -0000
> @@ -1,6 +1,6 @@
> -# Makefile.in generated automatically by automake 1.4 from Makefile.am
> +# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
>  
> -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
> +# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
>  # This Makefile.in is free software; the Free Software Foundation
>  # gives unlimited permission to copy and/or distribute it,
>  # with or without modifications, as long as this notice is preserved.
> @@ -114,6 +114,7 @@ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLA
>  GENERAL_SOURCES = dummy.c local64.h
>  @ELIX_LEVEL_1_TRUE@LIB_OBJS = 
>  @ELIX_LEVEL_1_FALSE@LIB_OBJS = @ELIX_LEVEL_1_FALSE@\
> +@ELIX_LEVEL_1_FALSE@	fdopen64.$(oext) 	\
>  @ELIX_LEVEL_1_FALSE@	fgetpos64.$(oext)	\
>  @ELIX_LEVEL_1_FALSE@	fopen64.$(oext) 	\
>  @ELIX_LEVEL_1_FALSE@	freopen64.$(oext) 	\
> 
> diff -up /dev/null libc/stdio64/fdopen64.c
> --- /dev/null	2003-01-30 05:24:37.000000000 -0500
> +++ libc/stdio64/fdopen64.c	2003-07-24 22:31:20.481026228 -0400
> @@ -0,0 +1,130 @@
> +/*
> +FUNCTION
> +<<fdopen64>>---turn open file into a stream
> +
> +INDEX
> +	fdopen64
> +INDEX
> +	_fdopen64_r
> +
> +ANSI_SYNOPSIS
> +	#include <stdio.h>
> +	FILE *fdopen64(int <[fd]>, const char *<[mode]>);
> +	FILE *_fdopen64_r(void *<[reent]>,
> +                     int <[fd]>, const char *<[mode]>);
> +
> +TRAD_SYNOPSIS
> +	#include <stdio.h>
> +	FILE *fdopen64(<[fd]>, <[mode]>)
> +	int <[fd]>;
> +	char *<[mode]>;
> +
> +	FILE *_fdopen64_r(<[reent]>, <[fd]>, <[mode]>)
> +	char *<[reent]>;
> +        int <[fd]>;
> +	char *<[mode]>);
> +
> +DESCRIPTION
> +<<fdopen64>> produces a file descriptor of type <<FILE *>>, from a
> +descriptor for an already-open file (returned, for example, by the
> +system subroutine <<open>> rather than by <<fopen>>).
> +The <[mode]> argument has the same meanings as in <<fopen>>.
> +
> +RETURNS
> +File pointer or <<NULL>>, as for <<fopen>>.
> +
> +PORTABILITY
> +<<fdopen64>> is ANSI.
> +*/
> +
> +#include <sys/types.h>
> +#include <sys/fcntl.h>
> +
> +#include <stdio.h>
> +#include <errno.h>
> +#include "local64.h"
> +#include <_syslist.h>
> +
> +extern int __sflags ();
> +
> +FILE *
> +_DEFUN (_fdopen64_r, (ptr, fd, mode),
> +	struct _reent *ptr _AND
> +	int fd _AND
> +	_CONST char *mode)
> +{
> +  register FILE *fp;
> +  int flags, oflags;
> +#ifdef HAVE_FCNTL
> +  int fdflags, fdmode;
> +#endif
> +
> +  if ((flags = __sflags (ptr, mode, &oflags)) == 0)
> +    return 0;
> +
> +  /* make sure the mode the user wants is a subset of the actual mode */
> +#ifdef HAVE_FCNTL
> +  if ((fdflags = _fcntl_r (ptr, fd, F_GETFL, 0)) < 0)
> +    return 0;
> +  fdmode = fdflags & O_ACCMODE;
> +  if (fdmode != O_RDWR && (fdmode != (oflags & O_ACCMODE)))
> +    {
> +      ptr->_errno = EBADF;
> +      return 0;
> +    }
> +#endif
> +
> +  if ((fp = __sfp (ptr)) == 0)
> +    return 0;
> +  fp->_flags = flags;
> +  /*
> +   * If opened for appending, but underlying descriptor
> +   * does not have O_APPEND bit set, assert __SAPP so that
> +   * __swrite() will lseek to end before each write.
> +   */
> +  if ((oflags & O_APPEND)
> +#ifdef HAVE_FCNTL
> +       && !(fdflags & O_APPEND)
> +#endif
> +      )
> +    fp->_flags |= __SAPP;
> +  fp->_file = fd;
> +  fp->_cookie = (_PTR) fp;
> +
> +#undef _read
> +#undef _write
> +#undef _seek
> +#undef _close
> +
> +  fp->_read = __sread;
> +  fp->_write = __swrite64;
> +  fp->_seek = __sseek;
> +  fp->_seek64 = __sseek64;
> +  fp->_close = __sclose;
> +
> +#ifdef __SCLE
> +  /* Explicit given mode results in explicit setting mode on fd */
> +  if (oflags & O_BINARY)
> +    setmode(fp->_file, O_BINARY);
> +  else if (oflags & O_TEXT)
> +    setmode(fp->_file, O_TEXT);
> +  if (__stextmode(fp->_file))
> +    fp->_flags |= __SCLE;
> +#endif
> +
> +  fp->_flags |= __SL64;
> +
> +  return fp;
> +}
> +
> +#ifndef _REENT_ONLY
> +
> +FILE *
> +_DEFUN (fdopen64, (fd, mode),
> +	int fd _AND
> +	_CONST char *mode)
> +{
> +  return _fdopen64_r (_REENT, fd, mode);
> +}
> +
> +#endif




More information about the Newlib mailing list