tst-svc.c 812 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Test for strverscmp() */
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #define MAX_STRINGS 256
  6. #define MAX_LINE_SIZE 32
  7. static int
  8. compare (const void *p1, const void *p2)
  9. {
  10. return strverscmp (*((char **) p1), *((char **) p2));
  11. }
  12. int
  13. do_test (void)
  14. {
  15. char line[MAX_LINE_SIZE + 1];
  16. char *str[MAX_STRINGS];
  17. int count = 0;
  18. int i, n;
  19. while (count < MAX_STRINGS && fgets (line, MAX_LINE_SIZE, stdin) != NULL)
  20. {
  21. n = strlen (line) - 1;
  22. if (line[n] == '\n')
  23. line[n] = '\0';
  24. str[count] = strdup (line);
  25. if (str[count] == NULL)
  26. exit (EXIT_FAILURE);
  27. ++count;
  28. }
  29. qsort (str, count, sizeof (char *), compare);
  30. for (i = 0; i < count; ++i)
  31. puts (str[i]);
  32. return EXIT_SUCCESS;
  33. }
  34. #include <support/test-driver.c>