xref: /aosp_15_r20/external/ltp/lib/newlib_tests/tst_safe_fileops.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2016 Linux Test Project
4  */
5 
6 #include <stdio.h>
7 #include "tst_test.h"
8 
do_test(void)9 static void do_test(void)
10 {
11 	long free;
12 	long nproc;
13 	long dummy;
14 
15 	SAFE_FILE_LINES_SCANF("/proc/meminfo", "MemFree: %ld", &free);
16 	if (FILE_LINES_SCANF("/proc/stat", "processes %ld", &nproc))
17 		tst_brk(TBROK, "Could not parse processes");
18 	tst_res(TPASS, "Free: %ld, nproc: %ld", free, nproc);
19 
20 	if (FILE_LINES_SCANF("/proc/stat", "non-existent %ld", &dummy))
21 		tst_res(TPASS, "non-existent not found");
22 	SAFE_FILE_LINES_SCANF("/proc/stat", "non-existent %ld", &dummy);
23 }
24 
25 static struct tst_test test = {
26 	.test_all = do_test,
27 };
28