From owner-freebsd-current@FreeBSD.ORG Thu Feb 7 21:12:25 2013 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 8F11380B; Thu, 7 Feb 2013 21:12:25 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) by mx1.freebsd.org (Postfix) with ESMTP id 40622E04; Thu, 7 Feb 2013 21:12:25 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id B4F91358C55; Thu, 7 Feb 2013 22:12:23 +0100 (CET) Received: by snail.stack.nl (Postfix, from userid 1677) id 8020E2848C; Thu, 7 Feb 2013 22:12:23 +0100 (CET) Date: Thu, 7 Feb 2013 22:12:22 +0100 From: Jilles Tjoelker To: John Baldwin Subject: Re: [PATCH] open_memstream() and open_wmemstream() Message-ID: <20130207211222.GA98989@stack.nl> References: <201302051546.43839.jhb@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201302051546.43839.jhb@freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Feb 2013 21:12:25 -0000 On Tue, Feb 05, 2013 at 03:46:43PM -0500, John Baldwin wrote: > I've written an implementation of open_memstream() and > open_wmemstream() along with a set of regression tests. I'm pretty > sure open_memstream() is correct, and I believe open_wmemstream() is > correct for expected usage. The latter might even do the right thing > if you split a multi-byte character across multiple writes. One > question I have is if my choice to discard any pending multi-byte > state in the stream anytime a seek changes the effective position in > the output stream. I think this is correct as stdio will flush any > pending data before doing a seek, so if there is a partially parsed > character we aren't going to get the rest of it. I don't think partially parsed characters can happen with a correct application. As per C99, an application must not call byte output functions on a wide-oriented stream, and vice versa. Discarding the shift state on fseek()/fseeko() is permitted (but should be documented as this is implementation-defined behaviour). State-dependent encodings (where this is relevant) are rarely used nowadays. The conversion to bytes and back probably makes open_wmemstream() quite slow but I don't think that is very important. > http://www.FreeBSD.org/~jhb/patches/open_memstream.patch The seek functions should check for overflow in the addition (for SEEK_CUR and SEEK_END) and the conversion to size_t. -- Jilles Tjoelker