File: fexist.c

package info (click to toggle)
libite 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,188 kB
  • sloc: sh: 4,665; ansic: 4,165; makefile: 141
file content (27 lines) | stat: -rw-r--r-- 674 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <err.h>
#include "check.h"

int main(void)
{
	size_t i = 0;
	struct { char *file; int exist; } arr[] = {
		{ "data/fexist/regular",      1 },
		{ "data/fexist/executable",   1 },
		{ "data/fexist/link",         1 },
		{ "data/fexist/nonexistence", 0 },
		{ "data/fexist/broken-link",  0 },
		{ "data/fexist/dir",          1 },
		{ "/dev/null",                1 },
		{ NULL,  0 },
	};

	for (i = 0; i < NELEMS(arr); i++) {
		if (fexist(arr[i].file) != arr[i].exist)
			err(1, "Failed fexist(%s)", arr[i].file ?: "NULL");
		else
			printf("File %-11s %-14s => OK!\n", arr[i].file ?: "NULL",
			       arr[i].exist ? "does exist" : "does not exist");
	}

	return 0;
}