Mercurial > hg > early-roguelike
comparison srogue/save.c @ 37:34d7a614855e
srogue: add support for SAVEDIR
author | elwin |
---|---|
date | Thu, 25 Nov 2010 17:28:29 +0000 |
parents | 2128c7dc8a40 |
children | 8a9525231fb6 |
comparison
equal
deleted
inserted
replaced
36:2128c7dc8a40 | 37:34d7a614855e |
---|---|
134 dosave() | 134 dosave() |
135 { | 135 { |
136 FILE *savef; | 136 FILE *savef; |
137 | 137 |
138 ignore(); | 138 ignore(); |
139 setuid(playuid); | 139 if (!use_savedir) |
140 setgid(playgid); | 140 { |
141 setuid(playuid); | |
142 setgid(playgid); | |
143 } | |
141 umask(022); | 144 umask(022); |
142 | 145 |
143 if (file_name[0] != '\0') { | 146 if (file_name[0] != '\0') { |
144 if ((savef = fopen(file_name,"w")) != NULL) | 147 if ((savef = fopen(file_name,"w")) != NULL) |
145 { | 148 { |
207 char buf[LINLEN]; | 210 char buf[LINLEN]; |
208 STAT sbuf2; | 211 STAT sbuf2; |
209 int slines, scols; | 212 int slines, scols; |
210 | 213 |
211 if ((inf = open(file, O_RDONLY)) < 0) { | 214 if ((inf = open(file, O_RDONLY)) < 0) { |
212 printf("Cannot read save game %s\n",file); | 215 if (use_savedir && errno == ENOENT) |
213 return FALSE; | 216 return TRUE; |
217 else { | |
218 printf("Cannot read save game %s\n",file); | |
219 return FALSE; | |
220 } | |
214 } | 221 } |
215 | 222 |
216 encread(buf, strlen(version) + 1, inf); | 223 encread(buf, strlen(version) + 1, inf); |
217 | 224 |
218 if (strcmp(buf, version) != 0) { | 225 if (strcmp(buf, version) != 0) { |
295 #endif | 302 #endif |
296 if (!wizard) | 303 if (!wizard) |
297 { | 304 { |
298 #ifndef __DJGPP__ | 305 #ifndef __DJGPP__ |
299 endwin(); | 306 endwin(); |
300 while((pid = fork()) < 0) | 307 if (!use_savedir) |
301 sleep(1); | |
302 | |
303 /* set id to unlink file */ | |
304 if(pid == 0) | |
305 { | 308 { |
306 setuid(playuid); | 309 while((pid = fork()) < 0) |
307 setgid(playgid); | 310 sleep(1); |
308 unlink(file); | 311 |
309 exit(0); | 312 /* set id to unlink file */ |
313 if(pid == 0) | |
314 { | |
315 setuid(playuid); | |
316 setgid(playgid); | |
317 unlink(file); | |
318 exit(0); | |
319 } | |
320 /* wait for unlink to finish */ | |
321 else | |
322 { | |
323 while(wait(&ret_status) != pid) | |
324 continue; | |
325 if (ret_status < 0) | |
326 { | |
327 printf("Cannot unlink file\n"); | |
328 return FALSE; | |
329 } | |
330 } | |
310 } | 331 } |
311 /* wait for unlink to finish */ | |
312 else | 332 else |
313 { | 333 { |
314 while(wait(&ret_status) != pid) | 334 /* Don't drop privileges, they're needed |
315 continue; | 335 * for the unlink. */ |
316 if (ret_status < 0) | 336 if (unlink(file) < 0) |
317 { | 337 { |
318 printf("Cannot unlink file\n"); | 338 printf("Cannot unlink file\n"); |
319 return FALSE; | 339 return FALSE; |
320 } | 340 } |
321 } | 341 } |