From patchwork Fri Sep 6 19:41:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 1982067 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=frmy1Cjs; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X0mpg4rTgz1y1H for ; Sat, 7 Sep 2024 05:42:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6B4B3384A417 for ; Fri, 6 Sep 2024 19:42:33 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id C4EC43858C56 for ; Fri, 6 Sep 2024 19:42:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4EC43858C56 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C4EC43858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725651737; cv=none; b=rr1xogsIos1OcAn3Uvpje/cyvKflWUP0L3bARiQA8bG//45lXj/oUlHNBfNtX7+PwJLeYgpnAPrLSxXjALdJx2THYltv2dYLLAmxuCb1wbfSmzwcAvfdj+E4hYa3G1Qzsb4Pz7/QjvL2lTvzg3tF4sP07c7vcHO+jBjU0HBFIxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725651737; c=relaxed/simple; bh=zSHyEPu3vA+cEni8IM8vPm2v8n5c1gbT48EYOyWp8gA=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=AVvF5F4eK7IWfFHLyH+4shk4WCSbRnQRMxkxrhyMEnF4o/Jh00fL1cFPdDjTpv9QseUScwEsUBoFro0Ll7+lm4wT31sIyoEeeVixpW0llmLfFiZ70Y8IHCB7ktA4xcsjWraKYuOLJG9z6ZgXcTJjlbDsdev9ccsCJH6mDmf4SZM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725651735; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zrf0eOnJSsgaqznv2NmUawRgltx2GTXd27oD51BKb/g=; b=frmy1CjsaB0/gY3APuBdgdda9oDEP94dDGoJZYS6HnnUOLjfVaPcmKa9pNlAofHuQ91hxV wMv4X5UG5VTBYvMWZouIupEhQB7C4UsRMBDdXvr1H4pdrZN3Gj7n3I+phBsoAaPmrRnNLg UcMOFbMLJtPLxvrBUr5TSAgHGoi0zYY= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678-7UvS7gHbNw2ZIxD3hpkPJQ-1; Fri, 06 Sep 2024 15:42:14 -0400 X-MC-Unique: 7UvS7gHbNw2ZIxD3hpkPJQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-428040f49f9so19621255e9.0 for ; Fri, 06 Sep 2024 12:42:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725651733; x=1726256533; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wFSLzKUm/+5IRZhJh30uHdtr0qEiwwYJKfCK0hlbajg=; b=bAJPeiPTbcIhw7OJf/FBnIhyvHEZw+LAjp9jhdeMGVlb2TvOIPn3b/RHcOJR1ioY5b QaBK8kqzvsnjXLwFla25HL1ClyJI0Tg07sFXVX/2yoFz46HsUukQUmP4SG2C+HaKRBE2 YOs/jIoTiqr7xrcTs0XOK2HrqQWrjqc7zlZCVGeW3whkLSkZs5D0297XQ874Y2heMaFf CdNLOQoPNc8BP7yk2VgTMmCbD96OTGu/FoPifafcY/IPHeCY9wI2rpJYxM0TK+luBxUF J0WVe8n3qq0MaBVmy9Ifas1w0s10As+rwwzDFVlTIpzSWyT/GAj+XzQ7U+rT/r/bZPv1 cFaw== X-Gm-Message-State: AOJu0Yx6WOk/2CqJ5aSe2kWyYmVJyu7ZPDBDN4Z0zMcukoO+vhV9yALi t2yNWaPbCecmz2Q1tNxJCaMBl7q8cZsCYQtL7PSHVHN+NfJ6ssfFs+DjUJes49poKlRl//q2bfE OPPJXMxuNWzOEnBeOaP6OnZP6yRedncWKkfJqohPbZdN+bWRUguFgbcLJnw== X-Received: by 2002:adf:f948:0:b0:367:9881:7d66 with SMTP id ffacd0b85a97d-37892703fe7mr176831f8f.41.1725651733210; Fri, 06 Sep 2024 12:42:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwaFykNjJi5YP60GazdqG8KJP7h1PdeXcWMpItTlOSUvqf6JjlXoCeQiaFtCnm17Xxla0bag== X-Received: by 2002:adf:f948:0:b0:367:9881:7d66 with SMTP id ffacd0b85a97d-37892703fe7mr176817f8f.41.1725651732597; Fri, 06 Sep 2024 12:42:12 -0700 (PDT) Received: from digraph.polyomino.org.uk (digraph.polyomino.org.uk. [2001:8b0:bf73:93f7::51bb:e332]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3789160d528sm602248f8f.41.2024.09.06.12.42.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 12:42:12 -0700 (PDT) Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.95) (envelope-from ) id 1smepj-00ClA6-Bv; Fri, 06 Sep 2024 19:41:27 +0000 Date: Fri, 6 Sep 2024 19:41:27 +0000 (UTC) From: Joseph Myers To: Florian Weimer cc: libc-alpha@sourceware.org Subject: [PATCH v2] Document limitations on streams passed to freopen In-Reply-To: <87h6atjn9g.fsf@oldenburg.str.redhat.com> Message-ID: <27db72a2-3467-be3-8f43-1261e586ad5b@redhat.com> References: <3889717-62fc-7bcb-2f3e-bde77b7a9d6a@redhat.com> <87h6atjn9g.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org On Fri, 6 Sep 2024, Florian Weimer wrote: > We support reassignment of stdin etc., so please say something like “the > original values of the standatd streams @code{stdin}”. Assignment to > stdin does not magically make freopen valid. Fixed in this version. Document limitations on streams passed to freopen As recently discussed, document that freopen does not work with streams opened with functions such as popen, fmemopen, open_memstream or fopencookie. I've filed to clarify this issue in POSIX. Tested with "make info" and "make html". Reviewed-by: Carlos O'Donell --- Changed in v2: specify that it's the original values of the standard streams that are supported, rather than some non-fopen-opened stream that might have been assigned to them. diff --git a/manual/stdio.texi b/manual/stdio.texi index 29888a361f..8590ae955a 100644 --- a/manual/stdio.texi +++ b/manual/stdio.texi @@ -330,6 +330,14 @@ this ability, so using @code{freopen} is more portable. When the sources are compiled with @code{_FILE_OFFSET_BITS == 64} on a 32 bit machine this function is in fact @code{freopen64} since the LFS interface replaces transparently the old interface. + +@Theglibc{} only supports use of @code{freopen} on streams opened with +@code{fopen} or @code{fopen64} and on the original values of the +standard streams @code{stdin}, @code{stdout}, and @code{stderr}; such +a stream may be reopened multiple times with @code{freopen}. If it is +called on another kind of stream (opened with functions such as +@code{popen}, @code{fmemopen}, @code{open_memstream}, and +@code{fopencookie}), @code{freopen} fails and returns a null pointer. @end deftypefun @deftypefun {FILE *} freopen64 (const char *@var{filename}, const char *@var{opentype}, FILE *@var{stream})