From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 639FE385DC14 for ; Mon, 16 Oct 2023 21:34:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 639FE385DC14 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 639FE385DC14 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::631 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697492098; cv=none; b=Oey3vt6iwLTDR8gsyLPexKSMI2h/BlTekvd+wOI7ujdb6RfKd2412+C78thLxHx8he+/9obMrXJ+l8Six+3SMv7cJwLlQT1qCIIKHURis5Ck/dbAUH0T6aA/VYlgdIa7lfLTaz4Le/LMBxY6zcF2v7ql0wW2vd+oVvn73Egsuzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697492098; c=relaxed/simple; bh=0K6TbFjEo17LwX/cgi3i9jep5CYgEBZTQaKTGMCaZnY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=NK8NSeN4HmknYrRBEyYVU+MneCpgJ+RfnlWNedZ0X0lCK6AYYBsqRJ3KNFrOyzr0SOF0hU8+JHTqsPr2mq2gPETtU+4XAx9X/4XC4vanX2GuLPLYGbBIfL0YIWQJbEwfvkZCHmYDreNwEWkJzcKlltN+KWRbxebmrhNtzNLNXjw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c9d407bb15so41868255ad.0 for ; Mon, 16 Oct 2023 14:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697492096; x=1698096896; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=C+9muNSE5uVCDPDFEBgOwgwwquXxbPGYW57NeX4KQMQ=; b=aYm+xb3nRczKKTs5q+iZulLIKMkhPkDtqbKE7ZNkQk5eNuoo9sh/s4cJpY/Gr+Iino 7hUn4SZlrm+zqZ8XiFnlXoLG5Rn8JHKOfDEqXYV1XPxI1uyXV7YYiTh9k0gNEQe41MF5 An1Td8wlH7y/mCnrcvxUvuOuJ4cffCQYkztdlg2FuS5GzFFFlDCk3/Vy8EC0Uz1T0xPD BgF/DbqHkJeOOy8whRAEQUm3rsrcOYEec1hO0urAiPwz3OXGO+NkweqfMymVdz0vLKzi N0+lvkyUVkIGCejditf4dKw7ORjQbWfbc54+9tKLSkU73Oy0vd9zbpyuIykQhdkbbGsr /UQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697492096; x=1698096896; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=C+9muNSE5uVCDPDFEBgOwgwwquXxbPGYW57NeX4KQMQ=; b=eg7XH5mxKNyt0dkf/O126CFMhyT3GOw1jomcHSn4+1L2gWwxIXHvl+Hb7oaKa6Mkiu TRhufBQxE6DSPSvyQWxGOw39L88CJFfQ26gpaZTYWlPtQADO5NOHtoM6W0eDTGrcz6Rt JsU2oPD8G1OwgNR45go8UARk6chcaPOI721oUM+2yB5hi5nd0eMP9Rz3Q+ffsB4ey+4A T+ef6Ftb3SmJFxlqKEDLu9a5dRLIdBi2fWYJsicH+T9/r5NdfHbYgdfoly1NFpRoiRgp z/cXI+8zXEZM6RCIzD3zTRHgcpRFwWrfobp9qP95Va5v1btpSfO0ZBVzZBbQO2Fetnyv vD4A== X-Gm-Message-State: AOJu0Yw84fLWuolls8Ingt9rOCnLCKRyDI7lXuQBoqBLTDKwiAnQcHve 4xzwYDMaVzwFPwJpSf/LsCwJTg== X-Google-Smtp-Source: AGHT+IFJjThJ0dHP7ToXzkn2QkC0Vpgp1l7ccYs5JKcT77NNDHNqyhNVhBI6jJ/T1xrcc3kpgBIqZQ== X-Received: by 2002:a17:903:189:b0:1ca:7f91:aa5d with SMTP id z9-20020a170903018900b001ca7f91aa5dmr465374plg.16.1697492096236; Mon, 16 Oct 2023 14:34:56 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c2:d09b:6dd7:5070:b348:8a98? ([2804:1b3:a7c2:d09b:6dd7:5070:b348:8a98]) by smtp.gmail.com with ESMTPSA id n17-20020a170902d2d100b001c9cb2fb8d8sm88985plc.49.2023.10.16.14.34.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Oct 2023 14:34:55 -0700 (PDT) Message-ID: <0126decc-6168-43b6-bb89-179998ce5b18@linaro.org> Date: Mon, 16 Oct 2023 18:34:53 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: fmemopen question Content-Language: en-US To: Nick Stoughton , libc-help@sourceware.org References: From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 12/10/23 11:57, Nick Stoughton via Libc-help wrote: > If I open a file for writing and immediately close it: > > fclose(fopen("foo", "w")); > > the file "foo" will be truncated to zero length if it exists. > > However, I I do this with a memory buffer, e.g. > char arr[] = { 'a','a','a','a','a','a','a','a','a','a', 0}; > fclose(fmemopen(arr, 10, "w")); > I would expect that arr[0] would have a null byte. > > But it doesn't. Is this a bug? > I think this falls to the Austin defect 657 [1], where the original fmemopen specification [2]: When a stream open for writing is flushed or closed, a null byte shall be written at the current position or at the end of the buffer, depending on the size of the contents. Indeed does not fully define when to write off the null byte. The proposed changed now allow glibc behavior (which only updates the stream on write operation): When a stream open for update (the mode argument includes '+') or for writing only is successfully written and the write advances the current buffer end position, a null byte shall be written at the new buffer end position if it fits. However, the defect submitter has asked for more clarification. So there still no resolution. It seems that at glibc and musl do not write a null byte at the start of the stream, different than BSD implementation (Free, Open, and NET) as well AIX72. [1] https://austingroupbugs.net/view.php?id=657