{"id":2221374,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2221374/?format=json","web_url":"http://patchwork.ozlabs.org/project/ltp/patch/20260409103041.8253-2-chrubis@suse.cz/","project":{"id":59,"url":"http://patchwork.ozlabs.org/api/1.2/projects/59/?format=json","name":"Linux Test Project development","link_name":"ltp","list_id":"ltp.lists.linux.it","list_email":"ltp@lists.linux.it","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260409103041.8253-2-chrubis@suse.cz>","list_archive_url":null,"date":"2026-04-09T10:30:40","name":"[1/2] lib: safe_file_ops: Add SAFE_FILE_READ_STR()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"b02136a4f5f23ad7aaec1c9268a0b824789e952e","submitter":{"id":8530,"url":"http://patchwork.ozlabs.org/api/1.2/people/8530/?format=json","name":"Cyril Hrubis","email":"chrubis@suse.cz"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/ltp/patch/20260409103041.8253-2-chrubis@suse.cz/mbox/","series":[{"id":499269,"url":"http://patchwork.ozlabs.org/api/1.2/series/499269/?format=json","web_url":"http://patchwork.ozlabs.org/project/ltp/list/?series=499269","date":"2026-04-09T10:30:39","name":"Fix proc parsing in newuname01","version":1,"mbox":"http://patchwork.ozlabs.org/series/499269/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2221374/comments/","check":"warning","checks":"http://patchwork.ozlabs.org/api/patches/2221374/checks/","tags":{},"related":[],"headers":{"Return-Path":"<ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>","X-Original-To":["incoming@patchwork.ozlabs.org","ltp@lists.linux.it"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","ltp@picard.linux.it"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256\n header.s=susede2_rsa header.b=Upuk97Fy;\n\tdkim=fail reason=\"signature verification failed\" header.d=suse.cz\n header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519\n header.b=Q+j1YaW1;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key)\n header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa\n header.b=hGag+QN8;\n\tdkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256\n header.s=susede2_ed25519 header.b=qndyqi7J;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it\n (client-ip=213.254.12.146; helo=picard.linux.it;\n envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it;\n receiver=patchwork.ozlabs.org)","smtp-out1.suse.de;\n dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=hGag+QN8;\n dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=qndyqi7J"],"Received":["from picard.linux.it (picard.linux.it [213.254.12.146])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4frx6Q6FP6z1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 09 Apr 2026 20:30:54 +1000 (AEST)","from picard.linux.it (localhost [IPv6:::1])\n\tby picard.linux.it (Postfix) with ESMTP id AE61E3E2F37\n\tfor <incoming@patchwork.ozlabs.org>; Thu,  9 Apr 2026 12:30:52 +0200 (CEST)","from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it\n [IPv6:2001:4b78:1:20::3])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature ECDSA (secp384r1))\n (No client certificate requested)\n by picard.linux.it (Postfix) with ESMTPS id BB0543DEBF8\n for <ltp@lists.linux.it>; Thu,  9 Apr 2026 12:30:32 +0200 (CEST)","from smtp-out1.suse.de (smtp-out1.suse.de\n [IPv6:2a07:de40:b251:101:10:150:64:1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 4A6971A00901\n for <ltp@lists.linux.it>; Thu,  9 Apr 2026 12:30:32 +0200 (CEST)","from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org\n [IPv6:2a07:de40:b281:104:10:150:64:97])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by smtp-out1.suse.de (Postfix) with ESMTPS id E67184EEAF\n for <ltp@lists.linux.it>; Thu,  9 Apr 2026 10:30:30 +0000 (UTC)","from imap1.dmz-prg2.suse.org (localhost [127.0.0.1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D972E4A0B3\n for <ltp@lists.linux.it>; Thu,  9 Apr 2026 10:30:30 +0000 (UTC)","from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167])\n by imap1.dmz-prg2.suse.org with ESMTPSA id doyFNMZ/12lAEAAAD6G6ig\n (envelope-from <chrubis@suse.cz>)\n for <ltp@lists.linux.it>; Thu, 09 Apr 2026 10:30:30 +0000"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz;\n s=susede2_rsa;\n t=1775730631; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:\n mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=+gcvb69npmLg6i4pLz/R4tYcvpoR6TJ2eMFCwYLyPQ4=;\n b=Upuk97FyBULtuH9iND6GRkWCHUimcP4Y29UQGsVh3apRX7w8sY+6p5Oq8j/ipf3VcNVlwQ\n 4qEu8Jh2klZEXXko6/lMBQhWdk2CDlEg0ly0n6JUSFX2Cmi4/ELBMGtipR8ZP7YY5kbRal\n vvFagvdc6jYKre5Q9WcvtFZ0pP9GgBw=","v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz;\n s=susede2_ed25519; t=1775730631;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:\n mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=+gcvb69npmLg6i4pLz/R4tYcvpoR6TJ2eMFCwYLyPQ4=;\n b=Q+j1YaW1xfJ/ENPPE8uVnTxyS5xYVv0ogmYL1Z+CtCb+o6EAx28WtPYMIrcvO8KQNLHBG4\n ScUSqxHb+a3MvDAg==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz;\n s=susede2_rsa;\n t=1775730630; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:\n mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=+gcvb69npmLg6i4pLz/R4tYcvpoR6TJ2eMFCwYLyPQ4=;\n b=hGag+QN8Ot4s0uU3ARoItL9HNfLa4XI0HT3c+PTtPNdDfnKpVg9HGMtTVPTfKePDfMaXN3\n wa3LjGpn8q0jWgT20x4Au9b+SrKAQbjQEzqXi66ElBnWcQrv2jONb5nGhYQe6ykEpa8nAw\n eFa4miVI/FvVl5lnuB8zpT4YCE52tjI=","v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz;\n s=susede2_ed25519; t=1775730630;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:\n mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=+gcvb69npmLg6i4pLz/R4tYcvpoR6TJ2eMFCwYLyPQ4=;\n b=qndyqi7JuWjq7h1owasu1rZZpkGkObWG0+V6bbbSV/QWoSv4d49GIBb7MzpL0Hy4LnRxo5\n Toln0faks7st5tBA=="],"From":"Cyril Hrubis <chrubis@suse.cz>","To":"ltp@lists.linux.it","Date":"Thu,  9 Apr 2026 12:30:40 +0200","Message-ID":"<20260409103041.8253-2-chrubis@suse.cz>","X-Mailer":"git-send-email 2.52.0","In-Reply-To":"<20260409103041.8253-1-chrubis@suse.cz>","References":"<20260409103041.8253-1-chrubis@suse.cz>","MIME-Version":"1.0","X-Spamd-Result":"default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%];\n NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[];\n R_MISSING_CHARSET(0.50)[];\n R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519];\n NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain];\n MX_GOOD(-0.01)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[];\n RCVD_COUNT_TWO(0.00)[2]; RCPT_COUNT_ONE(0.00)[1];\n MIME_TRACE(0.00)[0:+]; FUZZY_RATELIMITED(0.00)[rspamd.com];\n SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from];\n FROM_HAS_DN(0.00)[]; FROM_EQ_ENVFROM(0.00)[];\n DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.cz:mid,suse.cz:dkim,suse.cz:email];\n TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[];\n RCVD_TLS_ALL(0.00)[];\n PREVIOUSLY_DELIVERED(0.00)[ltp@lists.linux.it];\n DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received,2a07:de40:b281:104:10:150:64:97:from];\n DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519];\n DKIM_TRACE(0.00)[suse.cz:+]","X-Rspamd-Action":"no action","X-Spam-Score":"-3.01","X-Spam-Level":"","X-Rspamd-Server":"rspamd1.dmz-prg2.suse.org","X-Rspamd-Queue-Id":"E67184EEAF","X-Spam-Status":"No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID,\n DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no\n autolearn=disabled version=4.0.1","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on in-3.smtp.seeweb.it","X-Virus-Scanned":"clamav-milter 1.0.9 at in-3.smtp.seeweb.it","X-Virus-Status":"Clean","Subject":"[LTP] [PATCH 1/2] lib: safe_file_ops: Add SAFE_FILE_READ_STR()","X-BeenThere":"ltp@lists.linux.it","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"Linux Test Project <ltp.lists.linux.it>","List-Unsubscribe":"<https://lists.linux.it/options/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=unsubscribe>","List-Archive":"<http://lists.linux.it/pipermail/ltp/>","List-Post":"<mailto:ltp@lists.linux.it>","List-Help":"<mailto:ltp-request@lists.linux.it?subject=help>","List-Subscribe":"<https://lists.linux.it/listinfo/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it","Sender":"\"ltp\" <ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>"},"content":"Unlike the scanf(\"%s\") this function can properly handle empty files and\nin case of an empty file produces an empty string.\n\nSigned-off-by: Cyril Hrubis <chrubis@suse.cz>\n---\n include/tst_safe_file_ops.h | 21 +++++++++++++++++++++\n lib/safe_file_ops.c         | 24 ++++++++++++++++++++++++\n 2 files changed, 45 insertions(+)","diff":"diff --git a/include/tst_safe_file_ops.h b/include/tst_safe_file_ops.h\nindex 0d8819594..d9110ba9c 100644\n--- a/include/tst_safe_file_ops.h\n+++ b/include/tst_safe_file_ops.h\n@@ -14,6 +14,27 @@\n \tsafe_file_scanf(__FILE__, __LINE__, NULL, \\\n \t                (path), (fmt), ## __VA_ARGS__)\n \n+/**\n+ * SAFE_FILE_READ_STR() - Reads a string from a file.\n+ *\n+ * Unlike scanf(\"%s\") this function works fine with empty files or files that\n+ * consist only of white spaces. In such case an empty string is stored into\n+ * the supplied buffer.\n+ *\n+ * It's recomended to use this for various sysfs or procfs files that may be\n+ * empty.\n+ *\n+ * @path: A path to a file.\n+ * @buf: A buffer to store the string into.\n+ * @buf_size: A buffer size.\n+ */\n+#define SAFE_FILE_READ_STR(path, buf, buf_size) \\\n+\tsafe_file_read_str(__FILE__, __LINE__, \\\n+\t                   (path), (buf), (buf_size))\n+\n+void safe_file_read_str(const char *file, const int lineno,\n+                        const char *path, char *buf, size_t buf_size);\n+\n #define FILE_LINES_SCANF(path, fmt, ...) \\\n \tfile_lines_scanf(__FILE__, __LINE__, NULL, 0,\\\n \t\t\t(path), (fmt), ## __VA_ARGS__)\ndiff --git a/lib/safe_file_ops.c b/lib/safe_file_ops.c\nindex 8314c4b1b..2d163c0af 100644\n--- a/lib/safe_file_ops.c\n+++ b/lib/safe_file_ops.c\n@@ -160,6 +160,30 @@ void safe_file_scanf(const char *file, const int lineno,\n \t}\n }\n \n+void safe_file_read_str(const char *file, const int lineno,\n+                        const char *path, char *buf, size_t buf_size)\n+{\n+\tFILE *f;\n+\n+\tf = fopen(path, \"r\");\n+\tif (!f) {\n+\t\ttst_brkm_(file, lineno, TBROK | TERRNO, NULL,\n+\t\t          \"Failed to open FILE '%s' for reading\", path);\n+\t}\n+\n+\tif (!fgets(buf, buf_size, f))\n+\t\tbuf[0] = 0;\n+\n+\tsize_t len = strlen(buf);\n+\n+\tif (len && buf[len-1] == '\\n')\n+\t\tbuf[len-1] = 0;\n+\n+\tif (fclose(f)) {\n+\t\ttst_brkm_(file, lineno, TBROK | TERRNO, NULL,\n+\t\t\t\"Failed to close FILE '%s'\", path);\n+\t}\n+}\n \n /*\n  * Try to parse each line from file specified by 'path' according\n","prefixes":["1/2"]}