Mercurial > geeqie
comparison src/secure_save.c @ 699:9873d695a9c1
Do not use glib posix wrappers since they were introduced in 2.6
and we want 2.4 compatibility.
author | zas_ |
---|---|
date | Tue, 20 May 2008 20:11:29 +0000 |
parents | 2700db14aaa6 |
children | 4fe8f9656107 |
comparison
equal
deleted
inserted
replaced
698:2700db14aaa6 | 699:9873d695a9c1 |
---|---|
92 goto free_f; | 92 goto free_f; |
93 } | 93 } |
94 | 94 |
95 /* Check properties of final file. */ | 95 /* Check properties of final file. */ |
96 #ifndef NO_UNIX_SOFTLINKS | 96 #ifndef NO_UNIX_SOFTLINKS |
97 if (g_lstat(ssi->file_name, &st)) { | 97 if (lstat(ssi->file_name, &st)) { |
98 #else | 98 #else |
99 if (g_stat(ssi->file_name, &st)) { | 99 if (stat(ssi->file_name, &st)) { |
100 #endif | 100 #endif |
101 /* We ignore error caused by file inexistence. */ | 101 /* We ignore error caused by file inexistence. */ |
102 if (errno != ENOENT) { | 102 if (errno != ENOENT) { |
103 /* lstat() error. */ | 103 /* lstat() error. */ |
104 ssi->err = errno; | 104 ssi->err = errno; |
121 FILE *f1; | 121 FILE *f1; |
122 | 122 |
123 /* We still have a race condition here between | 123 /* We still have a race condition here between |
124 * [l]stat() and fopen() */ | 124 * [l]stat() and fopen() */ |
125 | 125 |
126 f1 = g_fopen(ssi->file_name, "rb+"); | 126 f1 = fopen(ssi->file_name, "rb+"); |
127 if (f1) { | 127 if (f1) { |
128 fclose(f1); | 128 fclose(f1); |
129 } else { | 129 } else { |
130 ssi->err = errno; | 130 ssi->err = errno; |
131 secsave_errno = SS_ERR_OPEN_READ; | 131 secsave_errno = SS_ERR_OPEN_READ; |
165 } | 165 } |
166 | 166 |
167 ssi->tmp_file_name = randname; | 167 ssi->tmp_file_name = randname; |
168 } else { | 168 } else { |
169 /* No need to create a temporary file here. */ | 169 /* No need to create a temporary file here. */ |
170 ssi->fp = g_fopen(ssi->file_name, "wb"); | 170 ssi->fp = fopen(ssi->file_name, "wb"); |
171 if (!ssi->fp) { | 171 if (!ssi->fp) { |
172 secsave_errno = SS_ERR_OPEN_WRITE; | 172 secsave_errno = SS_ERR_OPEN_WRITE; |
173 ssi->err = errno; | 173 ssi->err = errno; |
174 goto free_file_name; | 174 goto free_file_name; |
175 } | 175 } |
265 /* FIXME: Race condition on ssi->file_name. The file | 265 /* FIXME: Race condition on ssi->file_name. The file |
266 * named ssi->file_name may have changed since | 266 * named ssi->file_name may have changed since |
267 * secure_open() call (where we stat() file and | 267 * secure_open() call (where we stat() file and |
268 * more..). */ | 268 * more..). */ |
269 #ifndef NO_UNIX_SOFTLINKS | 269 #ifndef NO_UNIX_SOFTLINKS |
270 if (g_lstat(ssi->file_name, &st) == 0) | 270 if (lstat(ssi->file_name, &st) == 0) |
271 #else | 271 #else |
272 if (g_stat(ssi->file_name, &st) == 0) | 272 if (stat(ssi->file_name, &st) == 0) |
273 #endif | 273 #endif |
274 { | 274 { |
275 /* set the dest file attributes to that of source (ignoring errors) */ | 275 /* set the dest file attributes to that of source (ignoring errors) */ |
276 if (ssi->preserve_perms) | 276 if (ssi->preserve_perms) |
277 { | 277 { |
287 tb.modtime = st.st_mtime; | 287 tb.modtime = st.st_mtime; |
288 utime(ssi->tmp_file_name, &tb); | 288 utime(ssi->tmp_file_name, &tb); |
289 } | 289 } |
290 } | 290 } |
291 DEBUG_3("rename %s -> %s", ssi->tmp_file_name, ssi->file_name); | 291 DEBUG_3("rename %s -> %s", ssi->tmp_file_name, ssi->file_name); |
292 if (g_rename(ssi->tmp_file_name, ssi->file_name) == -1) { | 292 if (rename(ssi->tmp_file_name, ssi->file_name) == -1) { |
293 ret = errno; | 293 ret = errno; |
294 secsave_errno = SS_ERR_RENAME; | 294 secsave_errno = SS_ERR_RENAME; |
295 goto free; | 295 goto free; |
296 } | 296 } |
297 } | 297 } |