/* * Opens a file. If we have read access (r or a+) then it loads the entire * file into memory. If We have write access then the pathname is stored. * We do not actually write until an mfclose, which then checks this pathname. */ mFILE *mfopen(const char *path, const char *mode) { FILE *fp; if (mode) if (mode[0]=='m') /*memory only mode*/ return mfreopen(path, mode, 0); if (NULL == (fp = fopen(path, mode))) return NULL; return mfreopen(path, mode, fp); }
/* * Opens a file. If we have read access (r or a+) then it loads the entire * file into memory. If We have write access then the pathname is stored. * We do not actually write until an mfclose, which then checks this pathname. */ mFILE *mfopen(const char *path, const char *mode) { FILE *fp; if (NULL == (fp = fopen(path, mode))) return NULL; return mfreopen(path, mode, fp); }
void exp_print_file(FILE *fp, Exp_info *e) { mFILE *mf; if (NULL == (mf = mfreopen(NULL, "w", fp))) return; exp_print_mfile(mf, e); mfclose(mf); }
int fwrite_scf(Scf *s, FILE *fp) { mFILE *mf; int r; if (NULL == (mf = mfreopen(NULL, "w", fp))) return -1; r = mfwrite_scf(s, mf); mfclose(mf); return r; }
Scf *fread_scf(FILE *fp) { Scf *s; mFILE *mf; if (NULL == (mf = mfreopen(NULL, "r", fp))) return NULL; s = mfread_scf(mf); mfclose(mf); return s; }
int fwrite_ztr(FILE *fp, ztr_t *z) { mFILE *mf; int r; if (NULL == (mf = mfreopen(NULL, "w", fp))) return -1; r = mfwrite_ztr(mf, z); mfclose(mf); return r; }
ztr_t *fread_ztr(FILE *fp) { ztr_t *z; mFILE *mf; if (NULL == (mf = mfreopen(NULL, "r", fp))) return NULL; z = mfread_ztr(mf); mfclose(mf); return z; }
void exp_print_file(FILE *fp, Exp_info *e) { mFILE *mf; if (NULL == (mf = mfreopen(NULL, "wbx", fp))) return; exp_print_mfile(mf, e); mfflush(mf); mf->fp = NULL; /* Don't want this closed here */ mfclose(mf); }
Exp_info *exp_fread_info(FILE *fp) { Exp_info *e; mFILE *mf; if (NULL == (mf = mfreopen(NULL, "r", fp))) return NULL; e = exp_mfread_info(mf); mfclose(mf); return e; }
/* * Creates a new mFILE to contain the contents of the FILE pointer. * This mFILE is purely for in-memory operations and has no links to the * original FILE* it came from. It also doesn't close the FILE pointer. * Consider using mfreopen() is you need different behaviour. * * Returns mFILE * on success * NULL on failure. */ mFILE *mfcreate_from(const char *path, const char *mode_str, FILE *fp) { mFILE *mf; /* Open using mfreopen() */ if (NULL == (mf = mfreopen(path, mode_str, fp))) return NULL; /* Disassociate from the input stream */ mf->fp = NULL; return mf; }
Exp_info *exp_fread_info(FILE *fp) { Exp_info *e; mFILE *mf; if (NULL == (mf = mfreopen(NULL, "rb", fp))) return NULL; e = exp_mfread_info(mf); mf->fp = NULL; /* Don't want this closed here */ mfclose(mf); return e; }
Scf *fread_scf(FILE *fp) { Scf *s; mFILE *mf; if (NULL == (mf = mfreopen(NULL, "rb", fp))) return NULL; s = mfread_scf(mf); mf->fp = NULL; /* Don't want this closed here */ mfclose(mf); return s; }
int fwrite_ztr(FILE *fp, ztr_t *z) { mFILE *mf; int r; if (NULL == (mf = mfreopen(NULL, "wbx", fp))) return -1; r = mfwrite_ztr(mf, z); mfflush(mf); mf->fp = NULL; /* Don't want this closed here */ mfclose(mf); return r; }
int fwrite_scf(Scf *s, FILE *fp) { mFILE *mf; int r; if (NULL == (mf = mfreopen(NULL, "wbx", fp))) return -1; r = mfwrite_scf(s, mf); mfflush(mf); mf->fp = NULL; /* Don't want this closed here */ mfclose(mf); return r; }
/*! * Write a sequence to a FILE *fp of format "format". If "format" is 0, * we choose our favourite - SCF. * * Returns: * 0 for success * -1 for failure */ int fwrite_reading(FILE *fp, Read *read, int format) { int ret; mFILE *mf = mfreopen(NULL, "wbx", fp); if (mf) { ret = mfwrite_reading(mf, read, format); mfflush(mf); mf->fp = NULL; /* Don't want this closed here */ mfclose(mf); } else { return -1; } return ret; }
/* * Opens a file. If we have read access (r or a+) then it loads the entire * file into memory. If We have write access then the pathname is stored. * We do not actually write until an mfclose, which then checks this pathname. */ mFILE *mfopen(const char *path, const char *mode) { FILE *fp; char mode2[11]; int i1 = 0, i2 = 0; /* Remove the 'm' mmap symbol from mode before calling fopen() as * MS Visual Studio dislikes it remaining. */ while (i1 < 10 && mode[i1]) { if (mode[i1] != 'm') mode2[i2++] = mode[i1]; i1++; } mode2[i2] = 0; if (NULL == (fp = fopen(path, mode2))) return NULL; return mfreopen(path, mode, fp); }
int fwrite_reading(FILE *fp, Read *read, int format) { return mfwrite_reading(mfreopen(NULL, "w", fp), read, format); }
Read *fread_reading(FILE *fp, char *fn, int format) { return mfread_reading(mfreopen(fn, "r", fp), fn, format); }