1
0

get_system_dir.c 765 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Wrapper function around GetSystemDirectory that deals with
  3. * allocating the output buffer, and also caches the result for future
  4. * calls.
  5. */
  6. #include "putty.h"
  7. #ifdef WINSCP
  8. bool free_sysdir = false;
  9. void win_misc_cleanup()
  10. {
  11. free_sysdir = true;
  12. get_system_dir();
  13. free_sysdir = false;
  14. }
  15. #endif
  16. const char *get_system_dir(void)
  17. {
  18. static char *sysdir = NULL;
  19. static size_t sysdirsize = 0;
  20. #ifdef WINSCP
  21. if (free_sysdir)
  22. {
  23. sfree(sysdir);
  24. return NULL;
  25. }
  26. #endif
  27. if (!sysdir) {
  28. size_t len;
  29. while ((len = GetSystemDirectory(sysdir, sysdirsize)) >= sysdirsize)
  30. sgrowarray(sysdir, sysdirsize, len);
  31. }
  32. return sysdir;
  33. }