aboutsummaryrefslogtreecommitdiff
path: root/tests/files.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-02 11:31:53 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-02 11:31:53 -0800
commitfaf6b1d3504a8e999d94469abf92938492bedb7b (patch)
treec986c1218d4206c18b71758a1ef09c47b47bdf63 /tests/files.cpp
parentfe80f74127650c4e51ea72975fdc5e3b631843db (diff)
mkstemp
Diffstat (limited to 'tests/files.cpp')
-rw-r--r--tests/files.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/files.cpp b/tests/files.cpp
index e1a38421..04baa151 100644
--- a/tests/files.cpp
+++ b/tests/files.cpp
@@ -1,6 +1,7 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
int main()
{
@@ -103,6 +104,23 @@ int main()
fclose(inf);
printf("fscanfed: %d - %s\n", number, text);
+ // temp files
+ const char *tname = "file_XXXXXX.txt";
+ char tname1[100];
+ char tname2[100];
+ strcpy(tname1, tname);
+ strcpy(tname2, tname);
+ assert(!strcmp(tname1, tname2)); // equal
+ int f1 = mkstemp(tname1);
+ int f2 = mkstemp(tname2);
+ assert(f1 != f2);
+ //printf("%d,%d,%s,%s\n", f1, f2, tname1, tname2);
+ assert(strcmp(tname1, tname2)); // not equal
+ assert(fopen(tname1, "r"));
+ assert(fopen(tname2, "r"));
+ assert(!fopen(tname2+1, "r")); // sanity check that we can't open just anything
+ printf("ok.\n");
+
return 0;
}