test_grp.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * test_grp.c - This file is part of the libc-8086/grp package for ELKS,
  3. * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include <unistd.h>
  8. #include <stdio.h>
  9. #include <fcntl.h>
  10. #include <grp.h>
  11. int main(int argc, char **argv)
  12. {
  13. struct group *group;
  14. char **tmp_mem;
  15. int test_gid;
  16. fprintf(stdout, "Beginning test of libc/grp...\n");
  17. fprintf(stdout, "=> Testing setgrent(), getgrent(), endgrent()...\n");
  18. fprintf(stdout, "-> setgrent()...\n");
  19. setgrent();
  20. fprintf(stdout, "-> getgrent()...\n");
  21. printf
  22. ("********************************************************************************\n");
  23. while ((group = getgrent()) != NULL) {
  24. printf("gr_name\t\t: %s\n", group->gr_name);
  25. printf("gr_passwd\t: %s\n", group->gr_passwd);
  26. printf("gr_gid\t\t: %d\n", (int) group->gr_gid);
  27. printf("gr_mem\t\t: ");
  28. fflush(stdout);
  29. tmp_mem = group->gr_mem;
  30. while (*tmp_mem != NULL) {
  31. printf("%s, ", *tmp_mem);
  32. tmp_mem++;
  33. }
  34. printf
  35. ("\n********************************************************************************\n");
  36. }
  37. fprintf(stdout, "-> endgrent()...\n");
  38. endgrent();
  39. fprintf(stdout,
  40. "=> Test of setgrent(), getgrent(), endgrent() complete.\n");
  41. fprintf(stdout, "=> Testing getgrid(), getgrnam()...\n");
  42. fprintf(stdout, "-> getgrgid()...\n");
  43. printf
  44. ("********************************************************************************\n");
  45. for (test_gid = 0; test_gid < 100; test_gid++) {
  46. fprintf(stdout, "-> getgrgid(%d)...\n", test_gid);
  47. group = getgrgid((gid_t) test_gid);
  48. if (group != NULL) {
  49. printf("gr_name\t: %s\n", group->gr_name);
  50. printf("gr_passwd\t: %s\n", group->gr_passwd);
  51. printf("gr_gid\t: %d\n", (int) group->gr_gid);
  52. printf("gr_mem\t\t: ");
  53. fflush(stdout);
  54. tmp_mem = group->gr_mem;
  55. while (*tmp_mem != NULL) {
  56. printf("%s, ", *tmp_mem);
  57. tmp_mem++;
  58. }
  59. }
  60. printf
  61. ("\n********************************************************************************\n");
  62. }
  63. fprintf(stdout, "-> getgrnam()...\n");
  64. group = getgrnam("root");
  65. if (group == NULL) {
  66. printf(">NULL<\n");
  67. } else {
  68. printf("gr_name\t: %s\n", group->gr_name);
  69. printf("gr_passwd\t: %s\n", group->gr_passwd);
  70. printf("gr_gid\t: %d\n", (int) group->gr_gid);
  71. printf("gr_mem\t\t: ");
  72. fflush(stdout);
  73. tmp_mem = group->gr_mem;
  74. while (*tmp_mem != NULL) {
  75. printf("%s, ", *tmp_mem);
  76. tmp_mem++;
  77. }
  78. printf("\n");
  79. }
  80. return 0;
  81. }