tst-fdset.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Test FD* macros.
  2. Copyright (C) 1997-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Robert Bihlmeyer <robbe@orcus.priv.at>.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <stdio.h>
  17. #include <sys/types.h>
  18. static int
  19. do_test (void)
  20. {
  21. int retval = 0;
  22. int i;
  23. fd_set set;
  24. FD_ZERO (&set);
  25. for (i=0; i < FD_SETSIZE; ++i)
  26. {
  27. printf ("%d => check:", i);
  28. if (FD_ISSET (i, &set) == 0)
  29. fputs ("ok", stdout);
  30. else
  31. {
  32. fputs ("nok", stdout);
  33. retval = 1;
  34. }
  35. fputs (", set", stdout);
  36. FD_SET (i, &set);
  37. fputs (", check:", stdout);
  38. if (FD_ISSET (i, &set))
  39. fputs ("ok", stdout);
  40. else
  41. {
  42. fputs ("nok", stdout);
  43. retval = 1;
  44. }
  45. fputs (", clear", stdout);
  46. FD_CLR (i, &set);
  47. fputs (", check:", stdout);
  48. if (FD_ISSET (i, &set) == 0)
  49. puts ("ok");
  50. else
  51. {
  52. puts ("nok");
  53. retval = 1;
  54. }
  55. }
  56. return retval;
  57. }
  58. #define TEST_FUNCTION do_test ()
  59. #include "../test-skeleton.c"