0

I need to create temporary folder in C/C++ library, and make it compatible with Windows/MinGW. While mkdir("/tmp/something") works well (with permissions parameter of course) under Linux/macOS/whatever else, it fails under MinGW with ENOENT error.

Do I correctly understand that since _mkdir() is Windows API call then it should contain Windows path (i.e. will not be translated from /tmp/...) ?

And, then, what will be correct solution to access temporary folder? Use $TEMP environment variable? Any other ways via some WinAPI calls?

Thanks.

Nickolay Olshevsky
  • 13,706
  • 1
  • 34
  • 48
  • Your best bet might be [mkdtemp](https://linux.die.net/man/3/mkdtemp) with an `#ifdef`, Look here: [Creating a unique temporary directory from pure C in windows](https://stackoverflow.com/questions/6287475) – paulsm4 Nov 05 '19 at 17:49
  • You can find possible solution in raw C++ here: https://stackoverflow.com/questions/3379956/how-to-create-a-temporary-directory-in-c – Nick Bondarenko Nov 05 '19 at 17:50
  • Thanks, but actually the main question is about 'which root temp path should I use, and should I rely on /tmp'. I have a wrapper which uses `mktemp()` but I need something instead of `/tmp` to feed there. – Nickolay Olshevsky Nov 05 '19 at 19:47
  • I'd rather use the environment variable. You never know how a Windows system is set up. – the busybee Nov 05 '19 at 20:53
  • IIRC, MinGW is not a POSIX emulation layer, unlike MSYS2. So you need to use DOS paths and conventions such as the `TEMP` environment variable. – Eryk Sun Nov 05 '19 at 22:24
  • Thanks for the comments. I ended up by using getenv("TEMP") and this works pretty well. – Nickolay Olshevsky Nov 06 '19 at 18:05

0 Answers0