This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 1/2] Move offset to end of file when fdopen is in "a" mode (#16532)
- From: Andreas Schwab <schwab at suse dot de>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 11 Feb 2014 10:14:53 +0100
- Subject: Re: [PATCH 1/2] Move offset to end of file when fdopen is in "a" mode (#16532)
- Authentication-results: sourceware.org; auth=none
- References: <20140211083800 dot GB1424 at spoyarek dot pnq dot redhat dot com>
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."