I am running Cygwin 1.7.27 (0.271/5/3) and g++ 4.8.2. I am testing attempts to make temporary files in a POSIX-compliant way, using mkstemp().
I get the following error when I compile code that calls mkstemp(): ----------------------------------------- $ g++ -Wall -ansi -pedantic foo.cpp foo.cpp: In function ‘int main()’: foo.cpp:44:21: error: ‘mkstemp’ was not declared in this scope ----------------------------------------- Here is my code: ----------------------------------------- # # foo.cpp # #include <stdio.h> #include <cstdlib> #include <unistd.h> #include <sys/stat.h> #include <cstring> #ifndef P_tmpdir #ifdef _P_tmpdir #define P_tmpdir _P_tmpdir /* MingW */ #else #define P_tmpdir "/tmp" #endif #endif int main () { char const* p = getenv("TMPDIR"); if ( p == NULL ) p = P_tmpdir; printf("%s\n", p); int fd; char* tmpl = (char*)malloc(1 + strlen(p) + L_tmpnam); printf("%d\n", L_tmpnam); printf("%ld\n", strlen(p) + L_tmpnam); strcpy(tmpl, p); strcpy(tmpl+strlen(p), "/sb.XXXXXX"); printf("%s\n", tmpl); mkdir(p, 0700); // ignoring return val... mkstemp will fail if directory isn't writable if ( (fd = mkstemp(tmpl)) == -1 ) { fprintf(stderr, "unable to create temp file!\n"); return EXIT_FAILURE; } printf("%s\n", tmpl); printf("%d\n", remove(tmpl)); printf("%d\n", remove("this-aint-no-file")); free(tmpl); return EXIT_SUCCESS; } ----------------------------------------- Is mkstemp() part of Cygwin? If not, what options would I have to replace this code with equivalent functionality? Thanks, Alex -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple