test.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. libpftw — parallel file tree walk library
  3. Copyright (C) 2015 Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #define _GNU_SOURCE
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include "pftw.h"
  19. int cb_print_pftw(
  20. const char *fpath,
  21. const struct stat *sb,
  22. int typeflag,
  23. struct FTW *ftwbuf,
  24. void *arg)
  25. {
  26. return cb_print_ftw(fpath, sb, typeflag, ftwbuf);
  27. }
  28. int cb_print_ftw(
  29. const char *fpath,
  30. const struct stat *sb,
  31. int typeflag,
  32. struct FTW *ftwbuf)
  33. {
  34. printf("%s\n", fpath);
  35. return FTW_CONTINUE;
  36. }
  37. int syntax(char *argv[]) {
  38. fprintf(stderr, "syntax: %s <pftw|nftw> <directory>\n", argv[0]);
  39. return -1;
  40. }
  41. int main(int argc, char *argv[]) {
  42. if (argc < 3)
  43. return syntax(argv);
  44. if (!strcmp(argv[1], "pftw")) {
  45. fprintf(stderr, "pftw_init(8) -> %i\n", pftw_init(8));
  46. fprintf(stderr, "pftw() -> %i\n", pftw(argv[2], cb_print_pftw, 0, FTW_PHYS|FTW_ACTIONRETVAL, NULL));
  47. fprintf(stderr, "pftw_deinit() -> %i\n", pftw_deinit());
  48. return 0;
  49. } else
  50. if (!strcmp(argv[1], "nftw")) {
  51. fprintf(stderr, "nftw() -> %i\n", nftw(argv[2], cb_print_ftw, 0, FTW_PHYS|FTW_ACTIONRETVAL));
  52. return 0;
  53. }
  54. return syntax(argv);
  55. }