You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.3 KiB

  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>
  5. This program can be distributed under the terms of the GNU GPL.
  6. See the file COPYING.
  7. gcc -Wall fselclient.c -o fselclient
  8. */
  9. #include <sys/select.h>
  10. #include <sys/time.h>
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include <fcntl.h>
  14. #include <unistd.h>
  15. #include <ctype.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <errno.h>
  19. #define FSEL_FILES 16
  20. int main(void)
  21. {
  22. static const char hex_map[FSEL_FILES] = "0123456789ABCDEF";
  23. int fds[FSEL_FILES];
  24. int i, nfds;
  25. for (i = 0; i < FSEL_FILES; i++) {
  26. char name[] = { hex_map[i], '\0' };
  27. fds[i] = open(name, O_RDONLY);
  28. if (fds[i] < 0) {
  29. perror("open");
  30. return 1;
  31. }
  32. }
  33. nfds = fds[FSEL_FILES - 1] + 1;
  34. while (1) {
  35. static char buf[4096];
  36. fd_set rfds;
  37. int rc;
  38. FD_ZERO(&rfds);
  39. for (i = 0; i < FSEL_FILES; i++)
  40. FD_SET(fds[i], &rfds);
  41. rc = select(nfds, &rfds, NULL, NULL, NULL);
  42. if (rc < 0) {
  43. perror("select");
  44. return 1;
  45. }
  46. for (i = 0; i < FSEL_FILES; i++) {
  47. if (!FD_ISSET(fds[i], &rfds)) {
  48. printf("_: ");
  49. continue;
  50. }
  51. printf("%X:", i);
  52. rc = read(fds[i], buf, sizeof(buf));
  53. if (rc < 0) {
  54. perror("read");
  55. return 1;
  56. }
  57. printf("%02d ", rc);
  58. }
  59. printf("\n");
  60. }
  61. }