mkdtemp.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2017-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #include <common/utils.h>
  18. #include "../helper.h"
  19. #include <unistd.h>
  20. int do_test(char *(*func)(char *tmpl))
  21. {
  22. int ret;
  23. char *path;
  24. char dirname[128];
  25. char *ptr;
  26. struct stat sb;
  27. path = starpu_getenv("TMPDIR");
  28. if (!path)
  29. path = starpu_getenv("TEMP");
  30. if (!path)
  31. path = starpu_getenv("TMP");
  32. if (!path)
  33. path = "/tmp";
  34. snprintf(dirname, sizeof(dirname), "%s/abcdef_XXXXXX", path);
  35. ptr = func(dirname);
  36. FPRINTF(stderr, "Directory '%s' (res '%s')\n", dirname, ptr);
  37. // use stat
  38. ret = stat(dirname, &sb);
  39. if (ret != 0 || !S_ISDIR(sb.st_mode))
  40. {
  41. FPRINTF(stderr, "Directory '%s' has not been created\n", dirname);
  42. return 1;
  43. }
  44. ret = rmdir(dirname);
  45. STARPU_CHECK_RETURN_VALUE(ret, "rmdir '%s'\n", dirname);
  46. return ret;
  47. }
  48. int main(void)
  49. {
  50. int ret, ret2;
  51. ret = do_test(_starpu_mkdtemp);
  52. ret2 = do_test(_starpu_mkdtemp_internal);
  53. return ret + ret2;
  54. }