From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=W/v9KCyj; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 5776A5A026F for ; Wed, 15 Oct 2025 07:46:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760507193; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qiuZCfOGZV19OZ1yg5kbSoNKtEQzwKajl2tbnu1AJug=; b=W/v9KCyjCGY0DkCxXLvhcq85l2IkYjJ5nKSrJaCH9aaozHTTnnEEm+MOM4fsm1VaOarU5L wBiNMgqvFLoCgr2Zrz/4P1Wg3jbd4zx/xDURi9XYEQQYpW48X0aFJmzsDkwpfCq8yiUILt SWeFB4zPgEcIEgIGxgrHW6/6TuaAIFo= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-447-cecygZJbNv-Eg0Rke7W7NA-1; Wed, 15 Oct 2025 01:46:31 -0400 X-MC-Unique: cecygZJbNv-Eg0Rke7W7NA-1 X-Mimecast-MFC-AGG-ID: cecygZJbNv-Eg0Rke7W7NA_1760507190 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-639fbd37a7cso6324864a12.3 for ; Tue, 14 Oct 2025 22:46:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760507190; x=1761111990; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qiuZCfOGZV19OZ1yg5kbSoNKtEQzwKajl2tbnu1AJug=; b=lnC47U4nuZcJpvFtl/nhiSPRHCqh/bfvRoWQNRQ4rsZVBPTwwrh3ql0CG+e47NkvkW P0xbJlKri6M5eG9WAjcQM7Dugtimkpetal9QY4+WZcHSEvojVgGS0K4Ohnjo5FJSlt3n 8Y5JHxTOcU9t7LGQ2DIMoNDeVmgsx1SFNnYaPiGNyM2AeAq7G7Xt12F80C2DonnPk3fM bho7VdHQu1H02EwMY4dVC4BlnJnvwcGnfgYFQg8T9rAUIM/luXiTe8n+ymPMvQUwYiiQ 9//qxjzSY9KWNSnMpE9kxmY7XuxLVQujQ8T9jgTHTwpABzfe8FE7r0alaO1Wn+f+kBFU xy1Q== X-Gm-Message-State: AOJu0Yx2rhWTxkF7yWnRj751v78Qv2+o/l6xilcXbUNlx9qWIY1jMtK+ hdZHfCcheKkH40MFkk4RH+M41+e7PtCCp88llWCadWdIUb/SbI1OplFe+u31f4PyLnVoJ/9lKUC yL49Ndw27IEvYfqUAka7TvsVVljeU+jeUtxcBH87wKVaugGmnv2mbnNFilvUnU2zzSqggMdI5yC 7ARTMGPQBhWQG3InPSAGP3AFNmS3cV X-Gm-Gg: ASbGnct8GgqAZpQ3Iy3P6JlXiM/EzNlvdHmLj7YbryD8G7eRJ6n0yo1h0wgfpqRtafB 98zodS4bGFps/dv7OcHBGsah5ymLk8slsJ2iwivT9DXzk5VIWBrv5otyKkhXZvBe/dy+xhEG3KT X4gPGEKzU1IarwpYoXQPS6vQ== X-Received: by 2002:a05:6402:5213:b0:62f:2afa:60e6 with SMTP id 4fb4d7f45d1cf-639d5b6289bmr24869197a12.7.1760507189753; Tue, 14 Oct 2025 22:46:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8THCkMdeQAFh9TFaMbeb5/3+T8fP5mi1jZYDsl44PyDXfPaM7gt2RceXyXPXHySlUyjRxS/VwJG0yHNQWy80= X-Received: by 2002:a05:6402:5213:b0:62f:2afa:60e6 with SMTP id 4fb4d7f45d1cf-639d5b6289bmr24869164a12.7.1760507189165; Tue, 14 Oct 2025 22:46:29 -0700 (PDT) MIME-Version: 1.0 References: <20251014073836.18150-1-yuhuang@redhat.com> <20251014073836.18150-3-yuhuang@redhat.com> In-Reply-To: From: Yumei Huang Date: Wed, 15 Oct 2025 13:46:18 +0800 X-Gm-Features: AS18NWCaTpRgUjIeBaxcano96KRCrYRce9Ncg4bAzSVHBqvRDI_xMnjJC6MDJ_Q Message-ID: Subject: Re: [PATCH v3 2/4] util: Introduce read_file() and read_file_long() function To: David Gibson X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: wOAzs_8aTkipRhxMfhZeZx0quju79mkUmbsCPg00tzs_1760507190 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 6UCIWLQXOMCK3IRXRZDVF66KA7OQN7EL X-Message-ID-Hash: 6UCIWLQXOMCK3IRXRZDVF66KA7OQN7EL X-MailFrom: yuhuang@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, sbrivio@redhat.com X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Wed, Oct 15, 2025 at 12:46=E2=80=AFPM David Gibson wrote: > > On Wed, Oct 15, 2025 at 11:50:53AM +0800, Yumei Huang wrote: > > On Wed, Oct 15, 2025 at 7:28=E2=80=AFAM David Gibson > > wrote: > > > On Tue, Oct 14, 2025 at 03:38:34PM +0800, Yumei Huang wrote: > > > > Signed-off-by: Yumei Huang > [snip] > > > > + * @path: Path to the sysctl file > > > > + * @fallback: Default value if file can't be read > > > > + * > > > > + * Return: Parameter value, fallback on failure > > > > +*/ > > > > +long read_file_long(const char *path, long fallback) > > > > +{ > > > > + char buf[32]; > > > > > > Rather than just using a semi-arbitrary 32 here, I'd suggest defining > > > a new constant similar to UINT16_STRLEN. Except that's trickier for = a > > > type that doesn't have a known fixed width. Pity the C library > > > doesn't have constants for these AFAICT. > > > > I will just define a UINTMAX_STRLEN with (sizeof("2147483647")). > > That's not quite right. > - It should be INTMAX_STRLEN (signed), UINTMAX would be for the > unsigned version > - That assumes intmax_t is 32-bit which is probably not the case (it > will be 64-bit, maybe even 128-bit on modern systems) > - For signed cases, it's the minimum (negative) value that gives the > longest possible string (for 32-bit, "-2147483648") Maybe we could take it as 64 bits for now? I'm not sure under which circumstance we would read such a large number. If you agree, the define could be: #define INTMAX_STRLEN (sizeof("-9223372036854775808")) Or maybe define it to 20 directly : #define INTMAX_STRLEN 20 what do you think? > > -- > David Gibson (he or they) | I'll have my music baroque, and my code > david AT gibson.dropbear.id.au | minimalist, thank you, not the other wa= y > | around. > http://www.ozlabs.org/~dgibson --=20 Thanks, Yumei Huang