summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2020-10-08 11:58:11 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-10-08 11:58:11 +0100
commiteacee53c2e795a1c5e187558ccced2d66390d761 (patch)
tree03d374e1ed454827d64874c3548f564f1df1201b /src
parent509e3fcc7a65918f6bcf8a664353b45af457cfa6 (diff)
Evil : move mkstemp(s) and mkdtemp in eina_file directly
Summary: Also replace all mkstemp(s) and mkdtemp with the eina_file functions in the source Test Plan: run eina_file test Reviewers: raster Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12170
Diffstat (limited to 'src')
-rw-r--r--src/examples/eet/eet-data-cipher_decipher.c29
-rw-r--r--src/lib/ecore_con/efl_net_dialer_http.eo2
-rw-r--r--src/lib/ecore_con/efl_net_dialer_websocket.eo2
-rw-r--r--src/lib/eina/eina_file_common.c94
-rw-r--r--src/lib/eina/eina_file_posix.c76
-rw-r--r--src/lib/eina/eina_file_win32.c176
-rw-r--r--src/lib/eina/eina_main.c12
-rw-r--r--src/lib/eina/eina_private.h7
-rw-r--r--src/lib/eina/meson.build5
-rw-r--r--src/lib/evil/evil_stdlib.c109
-rw-r--r--src/lib/evil/evil_stdlib.h18
-rw-r--r--src/modules/elementary/access_output/mod.c13
-rw-r--r--src/tests/eet/eet_test_cipher.c14
-rw-r--r--src/tests/eet/eet_test_file.c58
-rw-r--r--src/tests/eet/eet_test_identity.c17
-rw-r--r--src/tests/eet/eet_test_image.c26
-rw-r--r--src/tests/elua/elua_lib.c16
-rw-r--r--src/tests/evil/evil_test_stdlib.c88
18 files changed, 361 insertions, 401 deletions
diff --git a/src/examples/eet/eet-data-cipher_decipher.c b/src/examples/eet/eet-data-cipher_decipher.c
index 4ff94d5782..fb6574064b 100644
--- a/src/examples/eet/eet-data-cipher_decipher.c
+++ b/src/examples/eet/eet-data-cipher_decipher.c
@@ -17,46 +17,46 @@ main(void)
17 const char *key = "This is a crypto key"; 17 const char *key = "This is a crypto key";
18 const char *key_bad = "This is another crypto key"; 18 const char *key_bad = "This is another crypto key";
19 19
20 char *file = strdup("/tmp/eet_cipher_example_XXXXXX");
21 Eet_File *ef; 20 Eet_File *ef;
22 char *test; 21 char *test;
23 int size; 22 int size;
24 int tmpfd; 23 int tmpfd;
24 Eina_Tmpstr *tmpf = NULL;
25 25
26 eet_init(); 26 eet_init();
27 27
28 if (-1 == (tmpfd = mkstemp(file)) || !!close(tmpfd)) 28 if (-1 == (tmpfd = eina_file_mkstemp("eet_cipher_example_XXXXXX", &tmpf)) || !!close(tmpfd))
29 { 29 {
30 fprintf( 30 fprintf(
31 stderr, "ERROR: could not create temporary file (%s) : %s\n", 31 stderr, "ERROR: could not create temporary file (%s) : %s\n",
32 file, strerror(errno)); 32 tmpf, strerror(errno));
33 goto panic; 33 goto panic;
34 } 34 }
35 35
36 /* Crypt an eet file. */ 36 /* Crypt an eet file. */
37 ef = eet_open(file, EET_FILE_MODE_WRITE); 37 ef = eet_open(tmpf, EET_FILE_MODE_WRITE);
38 if (!ef) 38 if (!ef)
39 { 39 {
40 fprintf( 40 fprintf(
41 stderr, "ERROR: could not access file (%s).\n", file); 41 stderr, "ERROR: could not access file (%s).\n", tmpf);
42 goto error; 42 goto error;
43 } 43 }
44 44
45 if (!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0, key)) 45 if (!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0, key))
46 { 46 {
47 fprintf( 47 fprintf(
48 stderr, "ERROR: could not access file (%s).\n", file); 48 stderr, "ERROR: could not access file (%s).\n", tmpf);
49 goto error; 49 goto error;
50 } 50 }
51 51
52 eet_close(ef); 52 eet_close(ef);
53 53
54 /* Decrypt an eet file. */ 54 /* Decrypt an eet file. */
55 ef = eet_open(file, EET_FILE_MODE_READ); 55 ef = eet_open(tmpf, EET_FILE_MODE_READ);
56 if (!ef) 56 if (!ef)
57 { 57 {
58 fprintf( 58 fprintf(
59 stderr, "ERROR: could not access file (%s).\n", file); 59 stderr, "ERROR: could not access file (%s).\n", tmpf);
60 goto error; 60 goto error;
61 } 61 }
62 62
@@ -65,7 +65,7 @@ main(void)
65 { 65 {
66 fprintf( 66 fprintf(
67 stderr, "ERROR: could decript contents on file %s, with key %s.\n", 67 stderr, "ERROR: could decript contents on file %s, with key %s.\n",
68 file, key); 68 tmpf, key);
69 goto error; 69 goto error;
70 } 70 }
71 71
@@ -86,11 +86,11 @@ main(void)
86 eet_close(ef); 86 eet_close(ef);
87 87
88 /* Decrypt an eet file, now using our BAD key!! */ 88 /* Decrypt an eet file, now using our BAD key!! */
89 ef = eet_open(file, EET_FILE_MODE_READ); 89 ef = eet_open(tmpf, EET_FILE_MODE_READ);
90 if (!ef) 90 if (!ef)
91 { 91 {
92 fprintf( 92 fprintf(
93 stderr, "ERROR: could not access file (%s).\n", file); 93 stderr, "ERROR: could not access file (%s).\n", tmpf);
94 goto error; 94 goto error;
95 } 95 }
96 96
@@ -102,18 +102,19 @@ main(void)
102 fprintf( 102 fprintf(
103 stderr, "ERROR: something is wrong with the contents of %s, as" 103 stderr, "ERROR: something is wrong with the contents of %s, as"
104 " we accessed it with a different key and it decripted our" 104 " we accessed it with a different key and it decripted our"
105 " information right.\n", file); 105 " information right.\n", tmpf);
106 goto error; 106 goto error;
107 } 107 }
108 108
109 eet_close(ef); 109 eet_close(ef);
110 110
111error: 111error:
112 if (unlink(file) != 0) 112 if (unlink(tmpf) != 0)
113 { 113 {
114 fprintf( 114 fprintf(
115 stderr, "ERROR: could not unlink file (%s).\n", file); 115 stderr, "ERROR: could not unlink file (%s)%d.\n", tmpf, errno);
116 } 116 }
117 eina_tmpstr_del(tmpf);
117 118
118panic: 119panic:
119 eet_shutdown(); 120 eet_shutdown();
diff --git a/src/lib/ecore_con/efl_net_dialer_http.eo b/src/lib/ecore_con/efl_net_dialer_http.eo
index 00bff4131b..f194d7bdc6 100644
--- a/src/lib/ecore_con/efl_net_dialer_http.eo
+++ b/src/lib/ecore_con/efl_net_dialer_http.eo
@@ -310,7 +310,7 @@ class @beta Efl.Net.Dialer_Http extends Efl.Loop_Consumer implements Efl.Net.Dia
310 310
311 If a new, empty session is to be used, start with an 311 If a new, empty session is to be used, start with an
312 empty or non-existent file such as created with 312 empty or non-existent file such as created with
313 mkstemp() or tmpfile(). Alternatively use an 313 eina_file_mkstemp() or tmpfile(). Alternatively use an
314 empty string ("") to store it in memory. 314 empty string ("") to store it in memory.
315 315
316 If you want to start from a pre-existing cookie jar 316 If you want to start from a pre-existing cookie jar
diff --git a/src/lib/ecore_con/efl_net_dialer_websocket.eo b/src/lib/ecore_con/efl_net_dialer_websocket.eo
index 612f504d46..1d4d98fb44 100644
--- a/src/lib/ecore_con/efl_net_dialer_websocket.eo
+++ b/src/lib/ecore_con/efl_net_dialer_websocket.eo
@@ -273,7 +273,7 @@ class @beta Efl.Net.Dialer_Websocket extends Efl.Loop_Consumer implements Efl.Ne
273 273
274 If a new, empty session is to be used, start with an 274 If a new, empty session is to be used, start with an
275 empty or non-existent file such as one created with 275 empty or non-existent file such as one created with
276 mkstemp() or tmpfile(). Alternatively use an 276 eina_file_mkstemp() or tmpfile(). Alternatively use an
277 empty string ("") to keep it in memory. 277 empty string ("") to keep it in memory.
278 278
279 If you want to start from a pre-existent cookie jar 279 If you want to start from a pre-existent cookie jar
diff --git a/src/lib/eina/eina_file_common.c b/src/lib/eina/eina_file_common.c
index 0380ea7a85..70ac5384fb 100644
--- a/src/lib/eina/eina_file_common.c
+++ b/src/lib/eina/eina_file_common.c
@@ -28,7 +28,7 @@
28#include <errno.h> 28#include <errno.h>
29 29
30#ifdef _WIN32 30#ifdef _WIN32
31# include <evil_private.h> /* windows.h fcntl mkstemps mkdtemp */ 31# include <evil_private.h> /* windows.h */
32#endif 32#endif
33 33
34#define COPY_BLOCKSIZE (4 * 1024 * 1024) 34#define COPY_BLOCKSIZE (4 * 1024 * 1024)
@@ -993,98 +993,6 @@ eina_file_copy(const char *src, const char *dst, Eina_File_Copy_Flags flags, Ein
993 return success; 993 return success;
994} 994}
995 995
996EAPI int
997eina_file_mkstemp(const char *templatename, Eina_Tmpstr **path)
998{
999 char buffer[PATH_MAX];
1000 const char *XXXXXX = NULL, *sep;
1001 int fd, len;
1002#ifndef _WIN32
1003 mode_t old_umask;
1004#endif
1005
1006 EINA_SAFETY_ON_NULL_RETURN_VAL(templatename, -1);
1007
1008 sep = strchr(templatename, '/');
1009#ifdef _WIN32
1010 if (!sep) sep = strchr(templatename, '\\');
1011#endif
1012 if (sep)
1013 {
1014 len = eina_strlcpy(buffer, templatename, sizeof(buffer));
1015 }
1016 else
1017 {
1018 len = eina_file_path_join(buffer, sizeof(buffer),
1019 eina_environment_tmp_get(), templatename);
1020 }
1021
1022 /*
1023 * Unix:
1024 * Make sure temp file is created with secure permissions,
1025 * http://man7.org/linux/man-pages/man3/mkstemp.3.html#NOTES
1026 *
1027 * Windows:
1028 * no secure permissions anyway and the umask use below makes
1029 * the file read-only.
1030 */
1031#ifndef _WIN32
1032 old_umask = umask(S_IRWXG|S_IRWXO);
1033#endif
1034 if ((XXXXXX = strstr(buffer, "XXXXXX.")) != NULL)
1035 {
1036 int suffixlen = buffer + len - XXXXXX - 6;
1037 fd = mkstemps(buffer, suffixlen);
1038 }
1039 else
1040 fd = mkstemp(buffer);
1041#ifndef _WIN32
1042 umask(old_umask);
1043#endif
1044
1045 if (fd < 0)
1046 {
1047 if (path) *path = NULL;
1048 return -1;
1049 }
1050
1051 if (path) *path = eina_tmpstr_add(buffer);
1052 return fd;
1053}
1054
1055EAPI Eina_Bool
1056eina_file_mkdtemp(const char *templatename, Eina_Tmpstr **path)
1057{
1058 char buffer[PATH_MAX];
1059 char *tmpdirname, *sep;
1060
1061 EINA_SAFETY_ON_NULL_RETURN_VAL(templatename, EINA_FALSE);
1062
1063 sep = strchr(templatename, '/');
1064#ifdef _WIN32
1065 if (!sep) sep = strchr(templatename, '\\');
1066#endif
1067 if (sep)
1068 {
1069 eina_strlcpy(buffer, templatename, sizeof(buffer));
1070 }
1071 else
1072 {
1073 eina_file_path_join(buffer, sizeof(buffer),
1074 eina_environment_tmp_get(), templatename);
1075 }
1076
1077 tmpdirname = mkdtemp(buffer);
1078 if (tmpdirname == NULL)
1079 {
1080 if (path) *path = NULL;
1081 return EINA_FALSE;
1082 }
1083
1084 if (path) *path = eina_tmpstr_add(tmpdirname);
1085 return EINA_TRUE;
1086}
1087
1088/*============================================================================* 996/*============================================================================*
1089 * Global * 997 * Global *
1090 *============================================================================*/ 998 *============================================================================*/
diff --git a/src/lib/eina/eina_file_posix.c b/src/lib/eina/eina_file_posix.c
index 14460b2f01..72f0e510fe 100644
--- a/src/lib/eina/eina_file_posix.c
+++ b/src/lib/eina/eina_file_posix.c
@@ -1509,3 +1509,79 @@ skip3:
1509 } 1509 }
1510#endif 1510#endif
1511} 1511}
1512
1513EAPI int
1514eina_file_mkstemp(const char *templatename, Eina_Tmpstr **path)
1515{
1516 char buffer[PATH_MAX];
1517 const char *XXXXXX = NULL, *sep;
1518 int fd, len;
1519 mode_t old_umask;
1520
1521 EINA_SAFETY_ON_NULL_RETURN_VAL(templatename, -1);
1522
1523 sep = strchr(templatename, '/');
1524 if (sep)
1525 {
1526 len = eina_strlcpy(buffer, templatename, sizeof(buffer));
1527 }
1528 else
1529 {
1530 len = eina_file_path_join(buffer, sizeof(buffer),
1531 eina_environment_tmp_get(), templatename);
1532 }
1533
1534 /*
1535 * Unix:
1536 * Make sure temp file is created with secure permissions,
1537 * http://man7.org/linux/man-pages/man3/mkstemp.3.html#NOTES
1538 */
1539 old_umask = umask(S_IRWXG|S_IRWXO);
1540 if ((XXXXXX = strstr(buffer, "XXXXXX.")) != NULL)
1541 {
1542 int suffixlen = buffer + len - XXXXXX - 6;
1543 fd = mkstemps(buffer, suffixlen);
1544 }
1545 else
1546 fd = mkstemp(buffer);
1547 umask(old_umask);
1548
1549 if (fd < 0)
1550 {
1551 if (path) *path = NULL;
1552 return -1;
1553 }
1554
1555 if (path) *path = eina_tmpstr_add(buffer);
1556 return fd;
1557}
1558
1559EAPI Eina_Bool
1560eina_file_mkdtemp(const char *templatename, Eina_Tmpstr **path)
1561{
1562 char buffer[PATH_MAX];
1563 char *tmpdirname, *sep;
1564
1565 EINA_SAFETY_ON_NULL_RETURN_VAL(templatename, EINA_FALSE);
1566
1567 sep = strchr(templatename, '/');
1568 if (sep)
1569 {
1570 eina_strlcpy(buffer, templatename, sizeof(buffer));
1571 }
1572 else
1573 {
1574 eina_file_path_join(buffer, sizeof(buffer),
1575 eina_environment_tmp_get(), templatename);
1576 }
1577
1578 tmpdirname = mkdtemp(buffer);
1579 if (tmpdirname == NULL)
1580 {
1581 if (path) *path = NULL;
1582 return EINA_FALSE;
1583 }
1584
1585 if (path) *path = eina_tmpstr_add(tmpdirname);
1586 return EINA_TRUE;
1587}
diff --git a/src/lib/eina/eina_file_win32.c b/src/lib/eina/eina_file_win32.c
index 9fa8e96a4d..b5c0c418c0 100644
--- a/src/lib/eina/eina_file_win32.c
+++ b/src/lib/eina/eina_file_win32.c
@@ -24,6 +24,7 @@
24#include <sys/stat.h> 24#include <sys/stat.h>
25 25
26#include <evil_private.h> 26#include <evil_private.h>
27#include <fcntl.h>
27 28
28#include "eina_config.h" 29#include "eina_config.h"
29#include "eina_private.h" 30#include "eina_private.h"
@@ -397,6 +398,114 @@ _eina_file_sep_find(char *s)
397 return NULL; 398 return NULL;
398} 399}
399 400
401static unsigned char _eina_file_random_uchar(unsigned char *c)
402{
403 /*
404 * Helper function for mktemp.
405 *
406 * Only characters from 'a' to 'z' and '0' to '9' are considered
407 * because on Windows, file system is case insensitive. That means
408 * 36 possible values.
409 * To increase randomness, we consider the greatest multiple of 36
410 * within 255 : 7*36 = 252, that is, values from 0 to 251 and choose
411 * a random value in this interval.
412 */
413 do {
414 BCryptGenRandom(_eina_bcrypt_provider, c, sizeof(UCHAR), 0);
415 } while (*c > 251);
416
417 *c = '0' + *c % 36;
418 if (*c > '9')
419 *c += 'a' - '9' - 1;
420
421 return *c;
422}
423
424static int
425_eina_file_mkstemp_init(char *__template, size_t *length, int suffixlen)
426{
427 if (!__template || (suffixlen < 0))
428 {
429 errno = EINVAL;
430 return 0;
431 }
432
433 *length = strlen(__template);
434 if ((*length < (6 + (size_t)suffixlen))
435 || (strncmp(__template + *length - 6 - suffixlen, "XXXXXX", 6) != 0))
436 {
437 errno = EINVAL;
438 return 0;
439 }
440 return 1;
441}
442
443static void
444_eina_file_tmpname(char *__template, size_t length, int suffixlen)
445{
446 unsigned char *suffix;
447
448 suffix = (unsigned char *)(__template + length - 6 - suffixlen);
449 *suffix = _eina_file_random_uchar(suffix);
450 suffix++;
451 *suffix = _eina_file_random_uchar(suffix);
452 suffix++;
453 *suffix = _eina_file_random_uchar(suffix);
454 suffix++;
455 *suffix = _eina_file_random_uchar(suffix);
456 suffix++;
457 *suffix = _eina_file_random_uchar(suffix);
458 suffix++;
459 *suffix = _eina_file_random_uchar(suffix);
460 suffix++;
461}
462
463static int
464_eina_file_mkstemps(char *__template, int suffixlen)
465{
466 size_t length;
467 int i;
468
469 if (!_eina_file_mkstemp_init(__template, &length, suffixlen))
470 return -1;
471
472 for (i = 0; i < 32768; i++)
473 {
474 int fd;
475
476 _eina_file_tmpname(__template, length, suffixlen);
477
478 fd = _open(__template,
479 _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL,
480 _S_IREAD | _S_IWRITE);
481 if (fd >= 0)
482 return fd;
483 }
484
485 errno = EEXIST;
486 return -1;
487}
488
489static char *
490_eina_file_mkdtemp(char *__template)
491{
492 size_t length;
493 int i;
494
495 if (!_eina_file_mkstemp_init(__template, &length, 0))
496 return NULL;
497
498 for (i = 0; i < 32768; i++)
499 {
500 _eina_file_tmpname(__template, length, 0);
501 if (CreateDirectory(__template, NULL) == TRUE)
502 return __template;
503 }
504
505 return NULL;
506}
507
508
400/** 509/**
401 * @endcond 510 * @endcond
402 */ 511 */
@@ -1093,3 +1202,70 @@ eina_file_statat(void *container EINA_UNUSED, Eina_File_Direct_Info *info, Eina_
1093 1202
1094 return 0; 1203 return 0;
1095} 1204}
1205
1206EAPI int
1207eina_file_mkstemp(const char *templatename, Eina_Tmpstr **path)
1208{
1209 char buffer[PATH_MAX];
1210 const char *XXXXXX = NULL, *sep;
1211 int fd, len;
1212
1213 EINA_SAFETY_ON_NULL_RETURN_VAL(templatename, -1);
1214
1215 sep = strchr(templatename, '/');
1216 if (!sep) sep = strchr(templatename, '\\');
1217 if (sep)
1218 {
1219 len = eina_strlcpy(buffer, templatename, sizeof(buffer));
1220 }
1221 else
1222 {
1223 len = eina_file_path_join(buffer, sizeof(buffer),
1224 eina_environment_tmp_get(), templatename);
1225 }
1226
1227 if ((XXXXXX = strstr(buffer, "XXXXXX.")) != NULL)
1228 fd = _eina_file_mkstemps(buffer, buffer + len - XXXXXX - 6);
1229 else
1230 fd = _eina_file_mkstemps(buffer, 0);
1231
1232 if (fd < 0)
1233 {
1234 if (path) *path = NULL;
1235 return -1;
1236 }
1237
1238 if (path) *path = eina_tmpstr_add(buffer);
1239 return fd;
1240}
1241
1242EAPI Eina_Bool
1243eina_file_mkdtemp(const char *templatename, Eina_Tmpstr **path)
1244{
1245 char buffer[PATH_MAX];
1246 char *tmpdirname, *sep;
1247
1248 EINA_SAFETY_ON_NULL_RETURN_VAL(templatename, EINA_FALSE);
1249
1250 sep = strchr(templatename, '/');
1251 if (!sep) sep = strchr(templatename, '\\');
1252 if (sep)
1253 {
1254 eina_strlcpy(buffer, templatename, sizeof(buffer));
1255 }
1256 else
1257 {
1258 eina_file_path_join(buffer, sizeof(buffer),
1259 eina_environment_tmp_get(), templatename);
1260 }
1261
1262 tmpdirname = _eina_file_mkdtemp(buffer);
1263 if (tmpdirname == NULL)
1264 {
1265 if (path) *path = NULL;
1266 return EINA_FALSE;
1267 }
1268
1269 if (path) *path = eina_tmpstr_add(tmpdirname);
1270 return EINA_TRUE;
1271}
diff --git a/src/lib/eina/eina_main.c b/src/lib/eina/eina_main.c
index 9549ab96c3..e30a850f95 100644
--- a/src/lib/eina/eina_main.c
+++ b/src/lib/eina/eina_main.c
@@ -120,6 +120,10 @@ EAPI Eina_Inlist *_eina_tracking = NULL;
120extern Eina_Lock _sysmon_lock; 120extern Eina_Lock _sysmon_lock;
121#endif 121#endif
122 122
123#ifdef _WIN32
124BCRYPT_ALG_HANDLE _eina_bcrypt_provider;
125#endif
126
123/* place module init/shutdown functions here to avoid other modules 127/* place module init/shutdown functions here to avoid other modules
124 * calling them by mistake. 128 * calling them by mistake.
125 */ 129 */
@@ -292,6 +296,10 @@ eina_init(void)
292 return ++_eina_main_count; 296 return ++_eina_main_count;
293 297
294#ifdef _WIN32 298#ifdef _WIN32
299 if (!BCRYPT_SUCCESS(BCryptOpenAlgorithmProvider(&_eina_bcrypt_provider,
300 BCRYPT_RNG_ALGORITHM,
301 NULL, 0)))
302 return 0;
295#else 303#else
296 int fd = open("/dev/urandom", O_RDONLY); 304 int fd = open("/dev/urandom", O_RDONLY);
297 if (fd >= 0) 305 if (fd >= 0)
@@ -397,6 +405,10 @@ eina_shutdown(void)
397 _mt_enabled = 0; 405 _mt_enabled = 0;
398 } 406 }
399#endif 407#endif
408
409#ifdef _WIN32
410 BCryptCloseAlgorithmProvider(_eina_bcrypt_provider, 0);
411#endif
400 } 412 }
401 413
402 return _eina_main_count; 414 return _eina_main_count;
diff --git a/src/lib/eina/eina_private.h b/src/lib/eina/eina_private.h
index 9e2954e001..9d4da033ce 100644
--- a/src/lib/eina/eina_private.h
+++ b/src/lib/eina/eina_private.h
@@ -25,6 +25,11 @@
25#include <xlocale.h> 25#include <xlocale.h>
26#endif 26#endif
27 27
28#ifdef _WIN32
29# include <windows.h>
30# include <bcrypt.h>
31#endif
32
28#include "eina_magic.h" 33#include "eina_magic.h"
29#include "eina_iterator.h" 34#include "eina_iterator.h"
30#include "eina_accessor.h" 35#include "eina_accessor.h"
@@ -152,6 +157,7 @@ Eina_Stringshare *eina_file_sanitize(const char *path);
152void eina_freeq_main_set(Eina_FreeQ *fq); 157void eina_freeq_main_set(Eina_FreeQ *fq);
153 158
154#ifdef _WIN32 159#ifdef _WIN32
160extern BCRYPT_ALG_HANDLE _eina_bcrypt_provider;
155typedef _locale_t locale_t; 161typedef _locale_t locale_t;
156#endif 162#endif
157locale_t _eina_c_locale_get(void); 163locale_t _eina_c_locale_get(void);
@@ -159,4 +165,3 @@ locale_t _eina_c_locale_get(void);
159#include "eina_inline_private.h" 165#include "eina_inline_private.h"
160 166
161#endif /* EINA_PRIVATE_H_ */ 167#endif /* EINA_PRIVATE_H_ */
162
diff --git a/src/lib/eina/meson.build b/src/lib/eina/meson.build
index 222d81b3a0..3bd869eed9 100644
--- a/src/lib/eina/meson.build
+++ b/src/lib/eina/meson.build
@@ -369,6 +369,11 @@ eina_ext_deps += [iconv]
369execinfo = cc.find_library('execinfo', required: false) 369execinfo = cc.find_library('execinfo', required: false)
370eina_ext_deps += [execinfo] 370eina_ext_deps += [execinfo]
371 371
372if sys_windows == true
373 bcrypt = cc.find_library('bcrypt', required: true)
374 eina_ext_deps += [bcrypt]
375endif
376
372eina_lib = library('eina', eina_src, 377eina_lib = library('eina', eina_src,
373 c_args : package_c_args, 378 c_args : package_c_args,
374 include_directories : config_dir, 379 include_directories : config_dir,
diff --git a/src/lib/evil/evil_stdlib.c b/src/lib/evil/evil_stdlib.c
index d6de5a4fcd..ea8f3356b7 100644
--- a/src/lib/evil/evil_stdlib.c
+++ b/src/lib/evil/evil_stdlib.c
@@ -76,115 +76,6 @@ unsetenv(const char *name)
76 * Files related functions 76 * Files related functions
77 * 77 *
78 */ 78 */
79static int
80_mkstemp_init(char *__template, char **suffix, size_t *length, DWORD *val,
81 size_t suffixlen)
82{
83 *length = strlen(__template);
84 if ((*length < (6 + suffixlen))
85 || (strncmp(__template + *length - 6 - suffixlen, "XXXXXX", 6) != 0))
86 {
87 errno = EINVAL;
88 return 0;
89 }
90
91 *suffix = __template + *length - 6 - suffixlen;
92
93 *val = GetTickCount();
94 *val += GetCurrentProcessId();
95
96 return 1;
97}
98
99static int
100_mkstemp(char *suffix, int val)
101{
102 const char lookup[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
103 DWORD v = val;
104
105 suffix[0] = lookup[v % 62];
106 v /= 62;
107 suffix[1] = lookup[v % 62];
108 v /= 62;
109 suffix[2] = lookup[v % 62];
110 v /= 62;
111 suffix[3] = lookup[v % 62];
112 v /= 62;
113 suffix[4] = lookup[v % 62];
114 v /= 62;
115 suffix[5] = lookup[v % 62];
116
117 val += 7777;
118
119 return val;
120}
121
122EAPI char *
123mkdtemp(char *__template)
124{
125 char *suffix;
126 DWORD val;
127 size_t length;
128 int i;
129
130 if (!__template)
131 {
132 errno = EINVAL;
133 return NULL;
134 }
135
136 if (!_mkstemp_init(__template, &suffix, &length, &val, 0))
137 return NULL;
138
139 for (i = 0; i < 32768; i++)
140 {
141 val = _mkstemp(suffix, val);
142
143 if (_mkdir(__template) == 0)
144 return __template;
145
146 if (errno == EFAULT ||
147 errno == ENOSPC ||
148 errno == ENOMEM ||
149 errno == ENOENT ||
150 errno == ENOTDIR ||
151 errno == EPERM ||
152 errno == EROFS)
153 return NULL;
154 }
155
156 errno = EEXIST;
157 return NULL;
158}
159
160int
161mkstemps(char *__template, int suffixlen)
162{
163 char *suffix;
164 DWORD val;
165 size_t length;
166 int i;
167
168 if (!__template || (suffixlen < 0))
169 return 0;
170
171 if (!_mkstemp_init(__template, &suffix, &length, &val, (size_t) suffixlen))
172 return -1;
173
174 for (i = 0; i < 32768; i++)
175 {
176 int fd;
177
178 val = _mkstemp(suffix, val);
179
180 fd = _open(__template, _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
181 if (fd >= 0)
182 return fd;
183 }
184
185 errno = EEXIST;
186 return -1;
187}
188 79
189char * 80char *
190realpath(const char *file_name, char *resolved_name) 81realpath(const char *file_name, char *resolved_name)
diff --git a/src/lib/evil/evil_stdlib.h b/src/lib/evil/evil_stdlib.h
index eae2fb8809..cb35a570b0 100644
--- a/src/lib/evil/evil_stdlib.h
+++ b/src/lib/evil/evil_stdlib.h
@@ -68,24 +68,6 @@ EAPI int unsetenv(const char *name);
68 */ 68 */
69 69
70/** 70/**
71 * @brief create an unique temporary directory
72 *
73 * @since 1.8.0
74 */
75EAPI char *mkdtemp(char *__template);
76
77/**
78 * @brief Create a unique temporary file name with a suffix.
79 *
80 * @param __template Template of the file to create.
81 * @param suffixlen Length of the suffix following the 'XXXXXX' placeholder.
82 * @return A file descriptor on success, -1 otherwise.
83 *
84 * @since 1.10.0
85 */
86EAPI int mkstemps(char *__template, int suffixlen);
87
88/**
89 * @brief Return an absolute or full path name for a specified relative path name. 71 * @brief Return an absolute or full path name for a specified relative path name.
90 * 72 *
91 * @param file_name The absolute path name. 73 * @param file_name The absolute path name.
diff --git a/src/modules/elementary/access_output/mod.c b/src/modules/elementary/access_output/mod.c
index f51b512a47..cabf0a6a55 100644
--- a/src/modules/elementary/access_output/mod.c
+++ b/src/modules/elementary/access_output/mod.c
@@ -19,7 +19,7 @@ static void (*cb_func) (void *data);
19static void *cb_data; 19static void *cb_data;
20static Ecore_Exe *espeak = NULL; 20static Ecore_Exe *espeak = NULL;
21static Ecore_Event_Handler *exe_exit_handler = NULL; 21static Ecore_Event_Handler *exe_exit_handler = NULL;
22static char *tmpf = NULL; 22static Eina_Tmpstr *tmpf = NULL;
23static int tmpfd = -1; 23static int tmpfd = -1;
24 24
25static Eina_Bool 25static Eina_Bool
@@ -32,7 +32,7 @@ _exe_del(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
32 if (tmpf) 32 if (tmpf)
33 { 33 {
34 unlink(tmpf); 34 unlink(tmpf);
35 free(tmpf); 35 eina_tmpstr_del(tmpf);
36 tmpf = NULL; 36 tmpf = NULL;
37 close(tmpfd); 37 close(tmpfd);
38 tmpfd = -1; 38 tmpfd = -1;
@@ -70,15 +70,12 @@ out_read(const char *txt)
70{ 70{
71 if (!tmpf) 71 if (!tmpf)
72 { 72 {
73 char buf[PATH_MAX];
74 mode_t cur_umask; 73 mode_t cur_umask;
75 74
76 snprintf(buf, sizeof(buf), "/tmp/.elm-speak-XXXXXX");
77 cur_umask = umask(S_IRWXO | S_IRWXG); 75 cur_umask = umask(S_IRWXO | S_IRWXG);
78 tmpfd = mkstemp(buf); 76 tmpfd = eina_file_mkstemp("elm-speak-XXXXXX", &tmpf);
79 umask(cur_umask); 77 umask(cur_umask);
80 if (tmpfd >= 0) tmpf = strdup(buf); 78 if (tmpfd < 0) return;
81 else return;
82 } 79 }
83 if (write(tmpfd, txt, strlen(txt)) < 0) perror("write to tmpfile (espeak)"); 80 if (write(tmpfd, txt, strlen(txt)) < 0) perror("write to tmpfile (espeak)");
84} 81}
@@ -117,7 +114,7 @@ out_cancel(void)
117 if (tmpf) 114 if (tmpf)
118 { 115 {
119 unlink(tmpf); 116 unlink(tmpf);
120 free(tmpf); 117 eina_tmpstr_del(tmpf);
121 tmpf = NULL; 118 tmpf = NULL;
122 close(tmpfd); 119 close(tmpfd);
123 tmpfd = -1; 120 tmpfd = -1;
diff --git a/src/tests/eet/eet_test_cipher.c b/src/tests/eet/eet_test_cipher.c
index c06c505b4c..09c09f2d64 100644
--- a/src/tests/eet/eet_test_cipher.c
+++ b/src/tests/eet/eet_test_cipher.c
@@ -19,15 +19,15 @@ EFL_START_TEST(eet_test_cipher_decipher_simple)
19 const char *key_bad = "This is another crypto key"; 19 const char *key_bad = "This is another crypto key";
20 Eet_File *ef; 20 Eet_File *ef;
21 char *test; 21 char *test;
22 char *file = strdup("/tmp/eet_suite_testXXXXXX"); 22 Eina_Tmpstr *tmpf = NULL;
23 int size; 23 int size;
24 int tmpfd; 24 int tmpfd;
25 25
26 fail_if(-1 == (tmpfd = mkstemp(file))); 26 fail_if(-1 == (tmpfd = eina_file_mkstemp("eet_suite_testXXXXXX", &tmpf)));
27 fail_if(!!close(tmpfd)); 27 fail_if(!!close(tmpfd));
28 28
29 /* Crypt an eet file. */ 29 /* Crypt an eet file. */
30 ef = eet_open(file, EET_FILE_MODE_WRITE); 30 ef = eet_open(tmpf, EET_FILE_MODE_WRITE);
31 fail_if(!ef); 31 fail_if(!ef);
32 32
33 fail_if(!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0, 33 fail_if(!eet_write_cipher(ef, "keys/tests", buffer, strlen(buffer) + 1, 0,
@@ -36,7 +36,7 @@ EFL_START_TEST(eet_test_cipher_decipher_simple)
36 eet_close(ef); 36 eet_close(ef);
37 37
38 /* Decrypt an eet file. */ 38 /* Decrypt an eet file. */
39 ef = eet_open(file, EET_FILE_MODE_READ); 39 ef = eet_open(tmpf, EET_FILE_MODE_READ);
40 fail_if(!ef); 40 fail_if(!ef);
41 41
42 test = eet_read_cipher(ef, "keys/tests", &size, key); 42 test = eet_read_cipher(ef, "keys/tests", &size, key);
@@ -48,7 +48,7 @@ EFL_START_TEST(eet_test_cipher_decipher_simple)
48 eet_close(ef); 48 eet_close(ef);
49 49
50 /* Decrypt an eet file. */ 50 /* Decrypt an eet file. */
51 ef = eet_open(file, EET_FILE_MODE_READ); 51 ef = eet_open(tmpf, EET_FILE_MODE_READ);
52 fail_if(!ef); 52 fail_if(!ef);
53 53
54 test = eet_read_cipher(ef, "keys/tests", &size, key_bad); 54 test = eet_read_cipher(ef, "keys/tests", &size, key_bad);
@@ -58,7 +58,9 @@ EFL_START_TEST(eet_test_cipher_decipher_simple)
58 58
59 eet_close(ef); 59 eet_close(ef);
60 60
61 fail_if(unlink(file) != 0); 61 fail_if(unlink(tmpf) != 0);
62
63 eina_tmpstr_del(tmpf);
62} 64}
63EFL_END_TEST 65EFL_END_TEST
64 66
diff --git a/src/tests/eet/eet_test_file.c b/src/tests/eet/eet_test_file.c
index 9423dc8aed..23233d7757 100644
--- a/src/tests/eet/eet_test_file.c
+++ b/src/tests/eet/eet_test_file.c
@@ -19,19 +19,17 @@ EFL_START_TEST(eet_test_file_simple_write)
19 Eet_Entry *entry; 19 Eet_Entry *entry;
20 Eet_File *ef; 20 Eet_File *ef;
21 char *test; 21 char *test;
22 char *file;
23 void *m; 22 void *m;
24 int size; 23 int size;
25 int tmpfd; 24 int tmpfd;
25 Eina_Tmpstr *tmpf = NULL;
26 26
27 file = strdup("/tmp/eet_suite_testXXXXXX"); 27 fail_if(-1 == (tmpfd = eina_file_mkstemp("eet_suite_testXXXXXX", &tmpf)));
28
29 fail_if(-1 == (tmpfd = mkstemp(file)));
30 fail_if(!!close(tmpfd)); 28 fail_if(!!close(tmpfd));
31 29
32 fail_if(eet_mode_get(NULL) != EET_FILE_MODE_INVALID); 30 fail_if(eet_mode_get(NULL) != EET_FILE_MODE_INVALID);
33 31
34 ef = eet_open(file, EET_FILE_MODE_WRITE); 32 ef = eet_open(tmpf, EET_FILE_MODE_WRITE);
35 fail_if(!ef); 33 fail_if(!ef);
36 34
37 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 1)); 35 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 1));
@@ -46,7 +44,7 @@ EFL_START_TEST(eet_test_file_simple_write)
46 eet_close(ef); 44 eet_close(ef);
47 45
48 /* Test read from buffer */ 46 /* Test read from buffer */
49 f = eina_file_open(file, EINA_FALSE); 47 f = eina_file_open(tmpf, EINA_FALSE);
50 fail_if(!f); 48 fail_if(!f);
51 49
52 m = eina_file_map_all(f, EINA_FILE_WILLNEED); 50 m = eina_file_map_all(f, EINA_FILE_WILLNEED);
@@ -83,7 +81,7 @@ EFL_START_TEST(eet_test_file_simple_write)
83 eina_file_close(f); 81 eina_file_close(f);
84 82
85 /* Test read of simple file */ 83 /* Test read of simple file */
86 ef = eet_open(file, EET_FILE_MODE_READ); 84 ef = eet_open(tmpf, EET_FILE_MODE_READ);
87 fail_if(!ef); 85 fail_if(!ef);
88 86
89 test = eet_read(ef, "keys/tests", &size); 87 test = eet_read(ef, "keys/tests", &size);
@@ -105,7 +103,7 @@ EFL_START_TEST(eet_test_file_simple_write)
105 eet_close(ef); 103 eet_close(ef);
106 104
107 /* Test eet cache system */ 105 /* Test eet cache system */
108 ef = eet_open(file, EET_FILE_MODE_READ); 106 ef = eet_open(tmpf, EET_FILE_MODE_READ);
109 fail_if(!ef); 107 fail_if(!ef);
110 108
111 test = eet_read(ef, "keys/tests", &size); 109 test = eet_read(ef, "keys/tests", &size);
@@ -116,8 +114,9 @@ EFL_START_TEST(eet_test_file_simple_write)
116 114
117 eet_close(ef); 115 eet_close(ef);
118 116
119 fail_if(unlink(file) != 0); 117 fail_if(unlink(tmpf) != 0);
120 118
119 eina_tmpstr_del(tmpf);
121} 120}
122EFL_END_TEST 121EFL_END_TEST
123 122
@@ -128,14 +127,12 @@ EFL_START_TEST(eet_test_file_data)
128 Eet_Dictionary *ed; 127 Eet_Dictionary *ed;
129 Eet_File *ef; 128 Eet_File *ef;
130 char **list; 129 char **list;
131 char *file;
132 Eet_Data_Descriptor_Class eddc; 130 Eet_Data_Descriptor_Class eddc;
133 Eet_Test_Ex_Type etbt; 131 Eet_Test_Ex_Type etbt;
134 int size; 132 int size;
135 int test; 133 int test;
136 int tmpfd; 134 int tmpfd;
137 135 Eina_Tmpstr *tmpf = NULL;
138 file = strdup("/tmp/eet_suite_testXXXXXX");
139 136
140 eet_test_ex_set(&etbt, 0); 137 eet_test_ex_set(&etbt, 0);
141 etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1)); 138 etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1));
@@ -165,14 +162,14 @@ EFL_START_TEST(eet_test_file_data)
165 162
166 eet_build_ex_descriptor(edd, EINA_FALSE); 163 eet_build_ex_descriptor(edd, EINA_FALSE);
167 164
168 fail_if(-1 == (tmpfd = mkstemp(file))); 165 fail_if(-1 == (tmpfd = eina_file_mkstemp("eet_suite_testXXXXXX", &tmpf)));
169 fail_if(!!close(tmpfd)); 166 fail_if(!!close(tmpfd));
170 167
171 /* Insert an error in etbt. */ 168 /* Insert an error in etbt. */
172 etbt.i = 0; 169 etbt.i = 0;
173 170
174 /* Save the encoded data in a file. */ 171 /* Save the encoded data in a file. */
175 ef = eet_open(file, EET_FILE_MODE_READ_WRITE); 172 ef = eet_open(tmpf, EET_FILE_MODE_READ_WRITE);
176 fail_if(!ef); 173 fail_if(!ef);
177 174
178 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); 175 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
@@ -193,7 +190,7 @@ EFL_START_TEST(eet_test_file_data)
193 /* Attempt to replace etbt by the correct one. */ 190 /* Attempt to replace etbt by the correct one. */
194 etbt.i = EET_TEST_INT; 191 etbt.i = EET_TEST_INT;
195 192
196 ef = eet_open(file, EET_FILE_MODE_READ_WRITE); 193 ef = eet_open(tmpf, EET_FILE_MODE_READ_WRITE);
197 fail_if(!ef); 194 fail_if(!ef);
198 195
199 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); 196 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
@@ -207,7 +204,7 @@ EFL_START_TEST(eet_test_file_data)
207 eet_close(ef); 204 eet_close(ef);
208 205
209 /* Read back the data. */ 206 /* Read back the data. */
210 ef = eet_open(file, EET_FILE_MODE_READ_WRITE); 207 ef = eet_open(tmpf, EET_FILE_MODE_READ_WRITE);
211 fail_if(!ef); 208 fail_if(!ef);
212 209
213 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY2, &etbt, 0)); 210 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY2, &etbt, 0));
@@ -273,8 +270,9 @@ EFL_START_TEST(eet_test_file_data)
273 270
274 eet_close(ef); 271 eet_close(ef);
275 272
276 fail_if(unlink(file) != 0); 273 fail_if(unlink(tmpf) != 0);
277 274
275 eina_tmpstr_del(tmpf);
278} 276}
279EFL_END_TEST 277EFL_END_TEST
280 278
@@ -286,11 +284,9 @@ EFL_START_TEST(eet_test_file_data_dump)
286 Eet_Test_Ex_Type etbt; 284 Eet_Test_Ex_Type etbt;
287 Eet_File *ef; 285 Eet_File *ef;
288 char *string1; 286 char *string1;
289 char *file;
290 int test; 287 int test;
291 int tmpfd; 288 int tmpfd;
292 289 Eina_Tmpstr *tmpf = NULL;
293 file = strdup("/tmp/eet_suite_testXXXXXX");
294 290
295 eet_test_ex_set(&etbt, 0); 291 eet_test_ex_set(&etbt, 0);
296 etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1)); 292 etbt.list = eina_list_prepend(etbt.list, eet_test_ex_set(NULL, 1));
@@ -318,11 +314,11 @@ EFL_START_TEST(eet_test_file_data_dump)
318 314
319 eet_build_ex_descriptor(edd, EINA_FALSE); 315 eet_build_ex_descriptor(edd, EINA_FALSE);
320 316
321 fail_if(-1 == (tmpfd = mkstemp(file))); 317 fail_if(-1 == (tmpfd = eina_file_mkstemp("eet_suite_testXXXXXX", &tmpf)));
322 fail_if(!!close(tmpfd)); 318 fail_if(!!close(tmpfd));
323 319
324 /* Save the encoded data in a file. */ 320 /* Save the encoded data in a file. */
325 ef = eet_open(file, EET_FILE_MODE_WRITE); 321 ef = eet_open(tmpf, EET_FILE_MODE_WRITE);
326 fail_if(!ef); 322 fail_if(!ef);
327 323
328 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0)); 324 fail_if(!eet_data_write(ef, edd, EET_TEST_FILE_KEY1, &etbt, 0));
@@ -330,7 +326,7 @@ EFL_START_TEST(eet_test_file_data_dump)
330 eet_close(ef); 326 eet_close(ef);
331 327
332 /* Use dump/undump in the middle */ 328 /* Use dump/undump in the middle */
333 ef = eet_open(file, EET_FILE_MODE_READ_WRITE); 329 ef = eet_open(tmpf, EET_FILE_MODE_READ_WRITE);
334 fail_if(!ef); 330 fail_if(!ef);
335 331
336 string1 = NULL; 332 string1 = NULL;
@@ -341,7 +337,7 @@ EFL_START_TEST(eet_test_file_data_dump)
341 eet_close(ef); 337 eet_close(ef);
342 338
343 /* Test the correctness of the reinsertion. */ 339 /* Test the correctness of the reinsertion. */
344 ef = eet_open(file, EET_FILE_MODE_READ); 340 ef = eet_open(tmpf, EET_FILE_MODE_READ);
345 fail_if(!ef); 341 fail_if(!ef);
346 342
347 result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1); 343 result = eet_data_read(ef, edd, EET_TEST_FILE_KEY1);
@@ -372,14 +368,14 @@ EFL_START_TEST(eet_test_file_data_dump)
372 368
373 fail_if(test != 0); 369 fail_if(test != 0);
374 370
375 fail_if(unlink(file) != 0); 371 fail_if(unlink(tmpf) != 0);
376 372
373 eina_tmpstr_del(tmpf);
377} 374}
378EFL_END_TEST 375EFL_END_TEST
379 376
380EFL_START_TEST(eet_test_file_fp) 377EFL_START_TEST(eet_test_file_fp)
381{ 378{
382 char *file;
383 Eet_Data_Descriptor_Class eddc; 379 Eet_Data_Descriptor_Class eddc;
384 Eet_Data_Descriptor *edd_5FP; 380 Eet_Data_Descriptor *edd_5FP;
385 Eet_Data_Descriptor *edd_5DBL; 381 Eet_Data_Descriptor *edd_5DBL;
@@ -388,8 +384,7 @@ EFL_START_TEST(eet_test_file_fp)
388 Eet_5DBL *convert; 384 Eet_5DBL *convert;
389 Eet_5FP *build; 385 Eet_5FP *build;
390 int tmpfd; 386 int tmpfd;
391 387 Eina_Tmpstr *tmpf = NULL;
392 file = strdup("/tmp/eet_suite_testXXXXXX");
393 388
394 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_5FP); 389 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_5FP);
395 edd_5FP = eet_data_descriptor_file_new(&eddc); 390 edd_5FP = eet_data_descriptor_file_new(&eddc);
@@ -415,10 +410,10 @@ EFL_START_TEST(eet_test_file_fp)
415 origin.f1 = eina_f32p32_int_from(1); 410 origin.f1 = eina_f32p32_int_from(1);
416 origin.f0 = 0; 411 origin.f0 = 0;
417 412
418 fail_if(-1 == (tmpfd = mkstemp(file))); 413 fail_if(-1 == (tmpfd = eina_file_mkstemp("eet_suite_testXXXXXX", &tmpf)));
419 fail_if(!!close(tmpfd)); 414 fail_if(!!close(tmpfd));
420 415
421 ef = eet_open(file, EET_FILE_MODE_READ_WRITE); 416 ef = eet_open(tmpf, EET_FILE_MODE_READ_WRITE);
422 fail_if(!ef); 417 fail_if(!ef);
423 418
424 fail_if(!eet_data_write(ef, edd_5FP, EET_TEST_FILE_KEY1, &origin, 1)); 419 fail_if(!eet_data_write(ef, edd_5FP, EET_TEST_FILE_KEY1, &origin, 1));
@@ -443,8 +438,9 @@ EFL_START_TEST(eet_test_file_fp)
443 438
444 eet_close(ef); 439 eet_close(ef);
445 440
446 fail_if(unlink(file) != 0); 441 fail_if(unlink(tmpf) != 0);
447 442
443 eina_tmpstr_del(tmpf);
448} 444}
449EFL_END_TEST 445EFL_END_TEST
450 446
diff --git a/src/tests/eet/eet_test_identity.c b/src/tests/eet/eet_test_identity.c
index b22d537021..4c54b7bcd4 100644
--- a/src/tests/eet/eet_test_identity.c
+++ b/src/tests/eet/eet_test_identity.c
@@ -60,18 +60,16 @@ EFL_START_TEST(eet_test_identity_simple)
60 Eet_Key *k; 60 Eet_Key *k;
61 FILE *noread; 61 FILE *noread;
62 char *test; 62 char *test;
63 char *file;
64 int size; 63 int size;
65 int fd; 64 int fd;
65 Eina_Tmpstr *tmpf = NULL;
66 66
67 file = strdup("/tmp/eet_suite_testXXXXXX"); 67 fail_if(-1 == (fd = eina_file_mkstemp("eet_suite_testXXXXXX", &tmpf)));
68
69 fail_if(-1 == (fd = mkstemp(file)));
70 fail_if(!!close(fd)); 68 fail_if(!!close(fd));
71 fail_if(!(noread = fopen("/dev/null", "wb"))); 69 fail_if(!(noread = fopen("/dev/null", "wb")));
72 70
73 /* Sign an eet file. */ 71 /* Sign an eet file. */
74 ef = eet_open(file, EET_FILE_MODE_WRITE); 72 ef = eet_open(tmpf, EET_FILE_MODE_WRITE);
75 fail_if(!ef); 73 fail_if(!ef);
76 74
77 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0)); 75 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0));
@@ -85,7 +83,7 @@ EFL_START_TEST(eet_test_identity_simple)
85 eet_close(ef); 83 eet_close(ef);
86 84
87 /* Open a signed file. */ 85 /* Open a signed file. */
88 ef = eet_open(file, EET_FILE_MODE_READ); 86 ef = eet_open(tmpf, EET_FILE_MODE_READ);
89 fail_if(!ef); 87 fail_if(!ef);
90 88
91 /* check that the certificates match */ 89 /* check that the certificates match */
@@ -109,7 +107,7 @@ EFL_START_TEST(eet_test_identity_simple)
109 eet_clearcache(); 107 eet_clearcache();
110 108
111 /* Corrupting the file. */ 109 /* Corrupting the file. */
112 fd = open(file, O_WRONLY | O_BINARY); 110 fd = open(tmpf, O_WRONLY | O_BINARY);
113 fail_if(fd < 0); 111 fail_if(fd < 0);
114 112
115 fail_if(lseek(fd, 200, SEEK_SET) != 200); 113 fail_if(lseek(fd, 200, SEEK_SET) != 200);
@@ -122,11 +120,12 @@ EFL_START_TEST(eet_test_identity_simple)
122 close(fd); 120 close(fd);
123 121
124 /* Attempt to open a modified file. */ 122 /* Attempt to open a modified file. */
125 ef = eet_open(file, EET_FILE_MODE_READ); 123 ef = eet_open(tmpf, EET_FILE_MODE_READ);
126 fail_if(ef); 124 fail_if(ef);
127 125
128 fail_if(unlink(file) != 0); 126 fail_if(unlink(tmpf) != 0);
129 127
128 eina_tmpstr_del(tmpf);
130} 129}
131EFL_END_TEST 130EFL_END_TEST
132 131
diff --git a/src/tests/eet/eet_test_image.c b/src/tests/eet/eet_test_image.c
index 5e35e67e54..585f39d86b 100644
--- a/src/tests/eet/eet_test_image.c
+++ b/src/tests/eet/eet_test_image.c
@@ -72,7 +72,6 @@ static const Eet_Test_Image test_alpha = {
72EFL_START_TEST(eet_test_image_normal) 72EFL_START_TEST(eet_test_image_normal)
73{ 73{
74 Eet_File *ef; 74 Eet_File *ef;
75 char *file;
76 unsigned int *data; 75 unsigned int *data;
77 int compress; 76 int compress;
78 int quality; 77 int quality;
@@ -82,14 +81,13 @@ EFL_START_TEST(eet_test_image_normal)
82 unsigned int w; 81 unsigned int w;
83 unsigned int h; 82 unsigned int h;
84 int tmpfd; 83 int tmpfd;
84 Eina_Tmpstr *tmpf = NULL;
85 85
86 file = strdup("/tmp/eet_suite_testXXXXXX"); 86 fail_if(-1 == (tmpfd = eina_file_mkstemp("eet_suite_testXXXXXX", &tmpf)));
87
88 fail_if(-1 == (tmpfd = mkstemp(file)));
89 fail_if(!!close(tmpfd)); 87 fail_if(!!close(tmpfd));
90 88
91 /* Save the encoded data in a file. */ 89 /* Save the encoded data in a file. */
92 ef = eet_open(file, EET_FILE_MODE_READ_WRITE); 90 ef = eet_open(tmpf, EET_FILE_MODE_READ_WRITE);
93 fail_if(!ef); 91 fail_if(!ef);
94 92
95 result = eet_data_image_write(ef, 93 result = eet_data_image_write(ef,
@@ -219,7 +217,7 @@ EFL_START_TEST(eet_test_image_normal)
219 eet_close(ef); 217 eet_close(ef);
220 218
221 /* Test read of image */ 219 /* Test read of image */
222 ef = eet_open(file, EET_FILE_MODE_READ); 220 ef = eet_open(tmpf, EET_FILE_MODE_READ);
223 fail_if(!ef); 221 fail_if(!ef);
224 222
225 result = eet_data_image_header_read(ef, 223 result = eet_data_image_header_read(ef,
@@ -424,14 +422,14 @@ EFL_START_TEST(eet_test_image_normal)
424 422
425 eet_close(ef); 423 eet_close(ef);
426 424
427 fail_if(unlink(file) != 0); 425 fail_if(unlink(tmpf) != 0);
428 426
427 eina_tmpstr_del(tmpf);
429} 428}
430EFL_END_TEST 429EFL_END_TEST
431 430
432EFL_START_TEST(eet_test_image_small) 431EFL_START_TEST(eet_test_image_small)
433{ 432{
434 char *file;
435 unsigned int image[4]; 433 unsigned int image[4];
436 unsigned int *data; 434 unsigned int *data;
437 Eet_File *ef; 435 Eet_File *ef;
@@ -443,18 +441,17 @@ EFL_START_TEST(eet_test_image_small)
443 Eet_Image_Encoding lossy; 441 Eet_Image_Encoding lossy;
444 int result; 442 int result;
445 int tmpfd; 443 int tmpfd;
446 444 Eina_Tmpstr *tmpf = NULL;
447 file = strdup("/tmp/eet_suite_testXXXXXX");
448 445
449 image[0] = IM0; 446 image[0] = IM0;
450 image[1] = IM1; 447 image[1] = IM1;
451 image[2] = IM2; 448 image[2] = IM2;
452 image[3] = IM3; 449 image[3] = IM3;
453 450
454 fail_if(-1 == (tmpfd = mkstemp(file))); 451 fail_if(-1 == (tmpfd = eina_file_mkstemp("/tmp/eet_suite_testXXXXXX", &tmpf)));
455 fail_if(!!close(tmpfd)); 452 fail_if(!!close(tmpfd));
456 453
457 ef = eet_open(file, EET_FILE_MODE_WRITE); 454 ef = eet_open(tmpf, EET_FILE_MODE_WRITE);
458 fail_if(!ef); 455 fail_if(!ef);
459 456
460 result = eet_data_image_write(ef, "/images/test", image, 2, 2, 1, 9, 100, 0); 457 result = eet_data_image_write(ef, "/images/test", image, 2, 2, 1, 9, 100, 0);
@@ -462,7 +459,7 @@ EFL_START_TEST(eet_test_image_small)
462 459
463 eet_close(ef); 460 eet_close(ef);
464 461
465 ef = eet_open(file, EET_FILE_MODE_READ); 462 ef = eet_open(tmpf, EET_FILE_MODE_READ);
466 fail_if(!ef); 463 fail_if(!ef);
467 464
468 data = (unsigned int *)eet_data_image_read(ef, 465 data = (unsigned int *)eet_data_image_read(ef,
@@ -477,7 +474,7 @@ EFL_START_TEST(eet_test_image_small)
477 474
478 eet_close(ef); 475 eet_close(ef);
479 476
480 fail_if(unlink(file) != 0); 477 fail_if(unlink(tmpf) != 0);
481 478
482 fail_if(data[0] != IM0); 479 fail_if(data[0] != IM0);
483 fail_if(data[1] != IM1); 480 fail_if(data[1] != IM1);
@@ -486,6 +483,7 @@ EFL_START_TEST(eet_test_image_small)
486 483
487 free(data); 484 free(data);
488 485
486 eina_tmpstr_del(tmpf);
489} 487}
490EFL_END_TEST 488EFL_END_TEST
491 489
diff --git a/src/tests/elua/elua_lib.c b/src/tests/elua/elua_lib.c
index f3d11d5023..b515d74c67 100644
--- a/src/tests/elua/elua_lib.c
+++ b/src/tests/elua/elua_lib.c
@@ -19,7 +19,6 @@ EFL_START_TEST(elua_api)
19{ 19{
20 Elua_State *st; 20 Elua_State *st;
21 lua_State *lst; 21 lua_State *lst;
22 char buf[] = "tmpXXXXXX";
23 FILE *f; 22 FILE *f;
24 int fd; 23 int fd;
25 char *cargv[2]; 24 char *cargv[2];
@@ -84,16 +83,16 @@ EFL_START_TEST(elua_api)
84 fail_if(lua_type(lst, -1) != LUA_TFUNCTION); 83 fail_if(lua_type(lst, -1) != LUA_TFUNCTION);
85 lua_pop(lst, 1); 84 lua_pop(lst, 1);
86 85
87 fd = mkstemp(buf); 86 fd = eina_file_mkstemp("tmpXXXXXX", &tmpf);
88 fail_if(fd < 0); 87 fail_if(fd < 0);
89 f = fdopen(fd, "wb"); 88 f = fdopen(fd, "wb");
90 fail_if(!f); 89 fail_if(!f);
91 fprintf(f, "return 5\n"); 90 fprintf(f, "return 5\n");
92 fclose(f); 91 fclose(f);
93 fail_if(!elua_util_file_run(st, buf)); 92 fail_if(!elua_util_file_run(st, tmpf));
94 fail_if(lua_tointeger(lst, -1) != 5); 93 fail_if(lua_tointeger(lst, -1) != 5);
95 lua_pop(lst, 1); 94 lua_pop(lst, 1);
96 fail_if(remove(buf)); 95 fail_if(remove(tmpf));
97 96
98 /* halfassed testing here, but not possible otherwise */ 97 /* halfassed testing here, but not possible otherwise */
99 fail_if(elua_util_error_report(st, 0)); 98 fail_if(elua_util_error_report(st, 0));
@@ -101,21 +100,21 @@ EFL_START_TEST(elua_api)
101 fail_if(!elua_util_error_report(st, 5)); 100 fail_if(!elua_util_error_report(st, 5));
102 fail_if(lua_gettop(lst) > 0); 101 fail_if(lua_gettop(lst) > 0);
103 102
104 f = fopen(buf, "wb"); 103 f = fopen(tmpf, "wb");
105 fail_if(!f); 104 fail_if(!f);
106 fprintf(f, "return true"); 105 fprintf(f, "return true");
107 fclose(f); 106 fclose(f);
108 cargv[1] = buf; 107 cargv[1] = tmpf;
109 fail_if(!elua_util_script_run(st, 2, cargv, 1, &quit)); 108 fail_if(!elua_util_script_run(st, 2, cargv, 1, &quit));
110 fail_if(quit != 1); 109 fail_if(quit != 1);
111 110
112 f = fopen(buf, "wb"); 111 f = fopen(tmpf, "wb");
113 fail_if(!f); 112 fail_if(!f);
114 fprintf(f, "return false"); 113 fprintf(f, "return false");
115 fclose(f); 114 fclose(f);
116 fail_if(!elua_util_script_run(st, 2, cargv, 1, &quit)); 115 fail_if(!elua_util_script_run(st, 2, cargv, 1, &quit));
117 fail_if(quit != 0); 116 fail_if(quit != 0);
118 fail_if(remove(buf)); 117 fail_if(remove(tmpf));
119 118
120 /* elua API here tries accessing files by relative path, 119 /* elua API here tries accessing files by relative path,
121 * prevent any unintentional file accesses in cwd 120 * prevent any unintentional file accesses in cwd
@@ -139,6 +138,7 @@ EFL_START_TEST(elua_api)
139 lua_pop(lst, 1); 138 lua_pop(lst, 1);
140 139
141 elua_state_free(st); 140 elua_state_free(st);
141 eina_tmpstr_del(tmpf);
142} 142}
143EFL_END_TEST 143EFL_END_TEST
144 144
diff --git a/src/tests/evil/evil_test_stdlib.c b/src/tests/evil/evil_test_stdlib.c
index c9f09813ef..57afb94fbd 100644
--- a/src/tests/evil/evil_test_stdlib.c
+++ b/src/tests/evil/evil_test_stdlib.c
@@ -169,86 +169,6 @@ EFL_START_TEST(evil_stdlib_unsetenv)
169} 169}
170EFL_END_TEST 170EFL_END_TEST
171 171
172EFL_START_TEST(evil_stdlib_mkdtemp)
173{
174 char template[] = "file_XXXXXX";
175 char *res;
176
177 res = mkdtemp(template);
178 fail_if(res == NULL);
179
180 fail_if(rmdir(res) < 0);
181}
182EFL_END_TEST
183
184EFL_START_TEST(evil_stdlib_mkdtemp_fail)
185{
186 char template[] = "file_XXX";
187 char *res;
188
189 res = mkdtemp(template);
190 fail_if(res != NULL);
191}
192EFL_END_TEST
193
194EFL_START_TEST(evil_stdlib_mkstemp)
195{
196 char template[] = "file_XXXXXX";
197 int fd;
198
199 fd = mkstemp(template);
200 fail_if(fd < 0);
201
202 fail_if(close(fd) == -1);
203
204 fail_if(unlink(template) == -1);
205}
206EFL_END_TEST
207
208EFL_START_TEST(evil_stdlib_mkstemp_fail)
209{
210 char template[] = "file_XXX";
211 int fd;
212
213 fd = mkstemp(template);
214 fail_if(fd >= 0);
215}
216EFL_END_TEST
217
218EFL_START_TEST(evil_stdlib_mkstemps)
219{
220 char template[] = "file_XXXXXX.ext";
221 int fd;
222
223 fd = mkstemps(template, 4);
224 fail_if(fd < 0);
225
226 fail_if(close(fd) == -1);
227
228 fail_if(unlink(template) == -1);
229}
230EFL_END_TEST
231
232EFL_START_TEST(evil_stdlib_mkstemps_fail_1)
233{
234 char template[] = "file_XXX.ext";
235 int fd;
236
237 fd = mkstemps(template, 4);
238 fail_if(fd >= 0);
239}
240EFL_END_TEST
241
242EFL_START_TEST(evil_stdlib_mkstemps_fail_2)
243{
244 char template[] = "file_XXX";
245 int fd;
246
247 fd = mkstemps(template, 4);
248 fail_if(fd >= 0);
249}
250EFL_END_TEST
251
252EFL_START_TEST(evil_stdlib_realpath_1) 172EFL_START_TEST(evil_stdlib_realpath_1)
253{ 173{
254 char buf[PATH_MAX]; 174 char buf[PATH_MAX];
@@ -302,14 +222,6 @@ void evil_test_stdlib(TCase *tc)
302 tcase_add_test(tc, evil_stdlib_getenv_two_swapped); 222 tcase_add_test(tc, evil_stdlib_getenv_two_swapped);
303 tcase_add_test(tc, evil_stdlib_unsetenv); 223 tcase_add_test(tc, evil_stdlib_unsetenv);
304 224
305 tcase_add_test(tc, evil_stdlib_mkdtemp);
306 tcase_add_test(tc, evil_stdlib_mkdtemp_fail);
307 tcase_add_test(tc, evil_stdlib_mkstemp);
308 tcase_add_test(tc, evil_stdlib_mkstemp_fail);
309 tcase_add_test(tc, evil_stdlib_mkstemps);
310 tcase_add_test(tc, evil_stdlib_mkstemps_fail_1);
311 tcase_add_test(tc, evil_stdlib_mkstemps_fail_2);
312
313 tcase_add_test(tc, evil_stdlib_realpath_1); 225 tcase_add_test(tc, evil_stdlib_realpath_1);
314 tcase_add_test(tc, evil_stdlib_realpath_2); 226 tcase_add_test(tc, evil_stdlib_realpath_2);
315 tcase_add_test(tc, evil_stdlib_realpath_3); 227 tcase_add_test(tc, evil_stdlib_realpath_3);