different behaviour of mkstemp between windows and linux

47 Views Asked by At

The following small application will behave differently on Linux and Windows.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

char template[100];

int main()
{
  strncpy(template, "stXXXXXX", 11);
  mkstemp(template);
  printf("%s\n", template);
  return 0;
}

When simply executed multiple times it will produce the expected result (ie. a different file with a random name) on both Windows and Linux. However, if we also remove the generated file after each execution:

  • on Linux it will produce the expected result
  • on Windows it will produce the same file

enter image description here

On both Linux and Windows I used the latest gcc 13. For Windows I have used the release from winlibs.

Do you have any idea why that is?

0

There are 0 best solutions below