summaryrefslogtreecommitdiff
path: root/src/examples
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/examples
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/examples')
-rw-r--r--src/examples/eet/eet-data-cipher_decipher.c29
1 files changed, 15 insertions, 14 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();