mkdtemp.c 1.6 KB

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