create save file, overwriting one if it already exists */
| 1156 | |
| 1157 | /* create save file, overwriting one if it already exists */ |
| 1158 | NHFILE * |
| 1159 | create_savefile(void) |
| 1160 | { |
| 1161 | const char *fq_save; |
| 1162 | NHFILE *nhfp = (NHFILE *) 0; |
| 1163 | boolean do_historical = TRUE; |
| 1164 | |
| 1165 | fq_save = fqname(gs.SAVEF, SAVEPREFIX, 0); |
| 1166 | nhfp = new_nhfile(); |
| 1167 | if (nhfp) { |
| 1168 | nhfp->ftype = NHF_SAVEFILE; |
| 1169 | nhfp->mode = WRITING; |
| 1170 | if (program_state.in_self_recover || do_historical) { |
| 1171 | nhUse(do_historical); |
| 1172 | nhfp->structlevel = TRUE; |
| 1173 | nhfp->fieldlevel = FALSE; |
| 1174 | nhfp->addinfo = FALSE; |
| 1175 | nhfp->style.deflt = FALSE; |
| 1176 | nhfp->style.binary = TRUE; |
| 1177 | nhfp->fnidx = historical; |
| 1178 | nhfp->fd = -1; |
| 1179 | nhfp->fpdef = (FILE *) 0; |
| 1180 | #ifdef SAVEFILE_DEBUGGING |
| 1181 | nhfp->fplog = fopen("create-savefile.log", "w"); |
| 1182 | #endif |
| 1183 | #if defined(MICRO) || defined(WIN32) |
| 1184 | nhfp->fd = open(fq_save, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, |
| 1185 | FCMASK); |
| 1186 | #else /* !MICRO && !WIN32 */ |
| 1187 | /* UNIX || MACOS9 implied (MACOS9 is OS9 or earlier only) */ |
| 1188 | #ifdef MACOS9 |
| 1189 | nhfp->fd = maccreat(fq_save, SAVE_TYPE); |
| 1190 | #else |
| 1191 | nhfp->fd = creat(fq_save, FCMASK); |
| 1192 | #endif |
| 1193 | #endif /* MICRO || WIN32 */ |
| 1194 | #if defined(MSDOS) || defined(WIN32) |
| 1195 | if (nhfp->fd >= 0) |
| 1196 | (void) setmode(nhfp->fd, O_BINARY); |
| 1197 | #endif |
| 1198 | } |
| 1199 | } |
| 1200 | #if defined(VMS) && !defined(SECURE) |
| 1201 | /* |
| 1202 | Make sure the save file is owned by the current process. That's |
| 1203 | the default for non-privileged users, but for priv'd users the |
| 1204 | file will be owned by the directory's owner instead of the user. |
| 1205 | */ |
| 1206 | #undef getuid |
| 1207 | (void) chown(fq_save, getuid(), getgid()); |
| 1208 | #define getuid() vms_getuid() |
| 1209 | #endif /* VMS && !SECURE */ |
| 1210 | |
| 1211 | nhfp = viable_nhfile(nhfp); |
| 1212 | return nhfp; |
| 1213 | } |
| 1214 | |
| 1215 | /* open savefile for reading */ |
no test coverage detected