/*
 * 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);
}
Exemple #2
0
/*
 * 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);
}
Exemple #3
0
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);
}
Exemple #4
0
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;
}
Exemple #5
0
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;
}
Exemple #6
0
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;
}
Exemple #7
0
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;
}
Exemple #8
0
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);
}
Exemple #9
0
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;
}
Exemple #11
0
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;
}
Exemple #12
0
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;
}
Exemple #13
0
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;
}
Exemple #14
0
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;
}
Exemple #15
0
/*! 
 * 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;
}
Exemple #16
0
/*
 * 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);
}
Exemple #17
0
int fwrite_reading(FILE *fp, Read *read, int format) {
    return mfwrite_reading(mfreopen(NULL, "w", fp), read, format);
}
Exemple #18
0
Read *fread_reading(FILE *fp, char *fn, int format) {
    return mfread_reading(mfreopen(fn, "r", fp), fn, format);
}