add missing argument check in ulockmgr.c
[fuse.git] / example / fselclient.c
blob7c4b8375f58f2db9565f1ef467116eda9598520d
1 /*
2 FUSE fselclient: FUSE select example client
3 Copyright (C) 2008 SUSE Linux Products GmbH
4 Copyright (C) 2008 Tejun Heo <teheo@suse.de>
6 This program can be distributed under the terms of the GNU GPL.
7 See the file COPYING.
9 gcc -Wall fselclient.c -o fselclient
12 #include <sys/select.h>
13 #include <sys/time.h>
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <fcntl.h>
17 #include <unistd.h>
18 #include <ctype.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <errno.h>
23 #define FSEL_FILES 16
25 int main(void)
27 static const char hex_map[FSEL_FILES] = "0123456789ABCDEF";
28 int fds[FSEL_FILES];
29 int i, nfds;
31 for (i = 0; i < FSEL_FILES; i++) {
32 char name[] = { hex_map[i], '\0' };
33 fds[i] = open(name, O_RDONLY);
34 if (fds[i] < 0) {
35 perror("open");
36 return 1;
39 nfds = fds[FSEL_FILES - 1] + 1;
41 while (1) {
42 static char buf[4096];
43 fd_set rfds;
44 int rc;
46 FD_ZERO(&rfds);
47 for (i = 0; i < FSEL_FILES; i++)
48 FD_SET(fds[i], &rfds);
50 rc = select(nfds, &rfds, NULL, NULL, NULL);
52 if (rc < 0) {
53 perror("select");
54 return 1;
57 for (i = 0; i < FSEL_FILES; i++) {
58 if (!FD_ISSET(fds[i], &rfds)) {
59 printf("_: ");
60 continue;
62 printf("%X:", i);
63 rc = read(fds[i], buf, sizeof(buf));
64 if (rc < 0) {
65 perror("read");
66 return 1;
68 printf("%02d ", rc);
70 printf("\n");