This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/2] Move offset to end of file when fdopen is in "a" mode (#16532)


Siddhesh Poyarekar <siddhesh@redhat.com> writes:

> 	[BZ #16532]
> 	* libio/iofdopen.c (file_attach_fd): New function.
> 	(_IO_new_fdopen): Use it.
> 	* libio/tst-fopen-append-update.c: New test case.
> 	* libio/Makefile (tests): Add it.

Looks good.

> diff --git a/libio/iofdopen.c b/libio/iofdopen.c
> index 066ff19..b214ea6 100644
> --- a/libio/iofdopen.c
> +++ b/libio/iofdopen.c
> @@ -40,6 +40,38 @@
>  #endif
>  #endif
>  
> +/* Attach the FD to the FILE object FP.  If READ_WRITE indicates an append
> +   mode, seek to the end of the file instead of seeking to the current
> +   position.  */
> +static _IO_FILE *
> +file_attach_fd (_IO_FILE *fp, int fd, int read_write)
> +{
> +  int dir = _IO_seek_cur;
> +
> +  if (_IO_file_is_open (fp))
> +    return NULL;
> +
> +  fp->_fileno = fd;
> +  fp->_flags &= ~(_IO_NO_READS+_IO_NO_WRITES);
> +  fp->_flags |= _IO_DELETE_DONT_CLOSE;
> +  /* Get the current position of the file. */
> +  /* We have to do that since that may be junk. */
> +  fp->_offset = _IO_pos_BAD;
> +  int save_errno = errno;
> +
> +  if ((read_write & _IO_IS_APPENDING) && (read_write & _IO_NO_READS))

No implicit boolean coercion.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]