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; }
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 mfwrite_reading(mFILE *fp, Read *read, int format) { int r = -1; int no_compress = 0; #ifdef _WIN32 /* * jkb 09/06/00 comment below * * On windows "prog > file.scf" will work wrongly (compared to * "prog file.scf") because windows is rather stupid. It treats ascii * and binary streams differently, it considers stdout to be ascii unless * told otherwise, and it can only be told otherwise by using non-ansi * windows-specific function calls. */ if (format != TT_EXP && format != TT_PLN && fp->fp) _setmode(_fileno(fp->fp), _O_BINARY); #endif switch (format) { default: /* Defaults to ZTR type */ #ifdef IOLIB_ZTR case TT_ZTR: case TT_ZTR2: { ztr_t *ztr; ztr = read2ztr(read); compress_ztr(ztr, 2); r = mfwrite_ztr(fp, ztr); delete_ztr(ztr); no_compress = 1; break; } case TT_ZTR1: { ztr_t *ztr; ztr = read2ztr(read); compress_ztr(ztr, 1); r = mfwrite_ztr(fp, ztr); delete_ztr(ztr); break; } case TT_ZTR3: { ztr_t *ztr; ztr = read2ztr(read); compress_ztr(ztr, 3); r = mfwrite_ztr(fp, ztr); delete_ztr(ztr); no_compress = 1; break; } #endif #ifdef IOLIB_SCF case TT_SCF: { Scf *scf; scf = read2scf(read); r = mfwrite_scf(scf, fp); scf_deallocate(scf); break; } #endif #ifdef IOLIB_CTF case TT_CTF: r = mfwrite_ctf(fp, read); break; #endif #ifdef IOLIB_ABI case TT_ABI: /*return mfwrite_abi(fp, read); */ break; #endif #ifdef IOLIB_ALF case TT_ALF: /* return mfwrite_alf(fp, read); */ break; #endif #ifdef IOLIB_EXP case TT_EXP: { Exp_info *e = read2exp(read, read->ident ? read->ident : "unknown"); if (NULL == e) { fprintf(stderr, "Failed to create experiment file.\n"); r = -1; } else { exp_print_mfile(fp, e); exp_destroy_info(e); r = 0; } break; } #endif #ifdef IOLIB_PLN case TT_PLN: r = mfwrite_pln(fp, read); break; #endif } mftruncate(fp, -1); if (r == 0 && !no_compress) { fcompress_file(fp); } mfflush(fp); return r; }