diff options
Diffstat (limited to 'procyon/source/bs/sav.c')
-rw-r--r-- | procyon/source/bs/sav.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/procyon/source/bs/sav.c b/procyon/source/bs/sav.c new file mode 100644 index 0000000..1e0b226 --- /dev/null +++ b/procyon/source/bs/sav.c @@ -0,0 +1,35 @@ +#include <acm/bs.h> + +#include <flux.h> +#include <stdio.h> + +void acm_sav(acm_pldat const * const _pldat) { + acm_log("Saving\n"); + flux_err fluxerr; + flux_fil savfil; + fluxerr = flux_mkfil(&savfil,acm_dat.savloc,0644u); + if (fluxerr) { + if (fluxerr != flux_err_exist) { + fprintf(stderr,"Unable to create save file (\"%s\"): %s\n",acm_dat.savloc,flux_errstr(fluxerr)); + acm_exit(acm_stat_err); + } + acm_log("Save file already exists, overwritting\n"); + fluxerr = flux_op(&savfil,acm_dat.savloc,flux_md_wr,flux_disc); + if (fluxerr) { + fprintf(stderr,"Unable to open save file: %s\n",flux_errstr(fluxerr)); + acm_exit(acm_stat_err); + } + } + { + uint_least64_t const savver = acm_savver; + fluxerr = flux_wr(savfil,&savver,sizeof (savver)); + } + if (!fluxerr) { + fluxerr = flux_wr(savfil,_pldat,sizeof (*_pldat)); + } + if (fluxerr) { + fprintf(stderr,"Unable to write to save file: %s\n",flux_errstr(fluxerr)); + acm_exit(acm_stat_err); + } + flux_cl(savfil); +} |