comparison srogue/save.c @ 279:d3968e9cb98d

Use C stdio functions for score files and save files. Switching from Unix file descriptor operations to C standard FILE* functions will reduce portability problems.
author John "Elwin" Edwards
date Fri, 15 Sep 2017 19:57:54 -0400
parents 3d4252fa2ed3
children 70aa5808c782
comparison
equal deleted inserted replaced
278:c222f9d56776 279:d3968e9cb98d
189 * Restore a saved game from a file 189 * Restore a saved game from a file
190 */ 190 */
191 bool 191 bool
192 restore(char *file, char **envp) 192 restore(char *file, char **envp)
193 { 193 {
194 register int inf, pid; 194 register int pid;
195 int ret_status; 195 int ret_status;
196 #ifndef _AIX 196 #ifndef _AIX
197 extern char **environ; 197 extern char **environ;
198 #endif 198 #endif
199 #ifdef __DJGPP__ /* st_ino w/ DJGPP under WinXP broken */ 199 #ifdef __DJGPP__ /* st_ino w/ DJGPP under WinXP broken */
200 _djstat_flags |= _STAT_INODE; /* so turn off computing it for now */ 200 _djstat_flags |= _STAT_INODE; /* so turn off computing it for now */
201 #endif 201 #endif
202 FILE *inf;
202 char buf[LINLEN]; 203 char buf[LINLEN];
203 STAT sbuf2; 204 STAT sbuf2;
204 int slines, scols; 205 int slines, scols;
205 206
206 if ((inf = open(file, O_RDONLY)) < 0) { 207 if ((inf = fopen(file, "r")) == NULL) {
207 if (use_savedir && errno == ENOENT) 208 if (use_savedir && errno == ENOENT)
208 return TRUE; 209 return TRUE;
209 else { 210 else {
210 printf("Cannot read save game %s\n",file); 211 printf("Cannot read save game %s\n",file);
211 return FALSE; 212 return FALSE;
217 if (strcmp(buf, version) != 0) { 218 if (strcmp(buf, version) != 0) {
218 printf("Sorry, saved game version is out of date.\n"); 219 printf("Sorry, saved game version is out of date.\n");
219 return FALSE; 220 return FALSE;
220 } 221 }
221 222
222 fstat(inf, &sbuf2); 223 stat(file, &sbuf2);
223 224
224 encread(&slines,sizeof(slines),inf); 225 encread(&slines,sizeof(slines),inf);
225 encread(&scols,sizeof(scols),inf); 226 encread(&scols,sizeof(scols),inf);
226 227
227 /* 228 /*
277 printf("Cannot restore file\n"); 278 printf("Cannot restore file\n");
278 return(FALSE); 279 return(FALSE);
279 } 280 }
280 281
281 #if defined(__CYGWIN__) || defined(__DJGPP__) 282 #if defined(__CYGWIN__) || defined(__DJGPP__)
282 close(inf); 283 fclose(inf);
283 #endif 284 #endif
284 if (!wizard) 285 if (!wizard)
285 { 286 {
286 if (md_unlink_open_file(file, md_fdopen(inf, "r")) < 0) 287 if (md_unlink_open_file(file, inf) < 0)
287 { 288 {
288 endwin(); 289 endwin();
289 printf("Cannot unlink file\n"); 290 printf("Cannot unlink file\n");
290 return FALSE; 291 return FALSE;
291 } 292 }