File: lfile.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 (74 lines) | stat: -rw-r--r-- 1,389 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include "check.h"

#define FSTAB "data/lfile/fstab"

static int fstab(void)
{
	int field = 1;
	char *token;
	lfile_t *lf;

	lf = lfopen(FSTAB, " \t\n");
	if (!lf) {
		perror("Failed opening " FSTAB);
		return 1;
	}

	printheader(NULL, "FILE SYSTEM                               MOUNT     OPTIONS            D P", 0);
	while ((token = lftok(lf))) {
		if (field == 1)
			printf("%-41s ", token);
		if (field == 2)
			printf("%-9s ", token);
		if (field == 4)
			printf("%-17s  ", token);
		if (field == 5)
			printf("%d ", atoi(token));
		if (field == 6) {
			field = 0;
			printf("%d\n", atoi(token));
		}

		field++;
	}

	lfclose(lf);

	return 0;
}

int main(void)
{
	int val;

	val = fgetint("data/lfile/protocols", " \n\t", "udp");
	if (val == -1) {
		perror("Failed locating 'udp' protocol");
		return 1;
	}
	printf("udp has proto %d\n", val);

	val = fgetint("data/lfile/services", " /\n\t", "ftp");
	if (val == -1) {
		perror("Failed locating 'ftp' service");
		return 1;
	}
	printf("ftp is inet port %d\n", val);

	val = fgetint("data/lfile/group", "x:\n", "utmp");
	if (val == -1) {
		perror("Failed locating group 'utmp'");
		return 1;
	}
	printf("utmp is gid %d\n", val);

	val = fgetint("data/lfile/passwd", "x:\n", "nobody");
	if (val == -1) {
		perror("Failed locating user 'nobody'");
		return 1;
	}
	printf("nobody is uid %d\n", val);

	return fstab();
}