2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)filereopen.c 1.15 04/08/08 Copyright 1986, 1995 J. Schilling */
15 * open new file on old stream
17 * Copyright (c) 1986, 1995 J. Schilling
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License version 2
22 * as published by the Free Software Foundation.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License along with
30 * this program; see the file COPYING. If not, write to the Free Software
31 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 * Note that because of a definition in schilyio.h we are using fseeko()/ftello()
38 * instead of fseek()/ftell() if available.
41 LOCAL char *fmtab[] = {
44 "r+", /* 2 FI_WRITE **1) */
45 "r+", /* 3 FI_READ | FI_WRITE */
46 "b", /* 4 FI_NONE | FI_BINARY */
47 "rb", /* 5 FI_READ | FI_BINARY */
48 "r+b", /* 6 FI_WRITE | FI_BINARY **1) */
49 "r+b", /* 7 FI_READ | FI_WRITE | FI_BINARY */
51 /* + FI_APPEND */ "", /* 0 FI_NONE */
52 /* ... */ "r", /* 1 FI_READ */
53 "a", /* 2 FI_WRITE **1) */
54 "a+", /* 3 FI_READ | FI_WRITE */
55 "b", /* 4 FI_NONE | FI_BINARY */
56 "rb", /* 5 FI_READ | FI_BINARY */
57 "ab", /* 6 FI_WRITE | FI_BINARY **1) */
58 "a+b", /* 7 FI_READ | FI_WRITE | FI_BINARY */
62 * 1) there is no fopen() mode that opens for writing
63 * without creating/truncating at the same time.
65 * "w" will create/trunc files with fopen()
66 * "a" will create files with fopen()
70 filereopen(name, mode, fp)
79 if (!_cvmod(mode, &omode, &flag))
80 return ((FILE *) NULL);
83 * create/truncate file if necessary
85 if ((ret = _openfd(name, omode)) < 0)
86 return ((FILE *) NULL);
90 fmtab[flag & (FI_READ | FI_WRITE | FI_BINARY | FI_APPEND)], fp);
92 if (fp != (FILE *) NULL) {
93 set_my_flag(fp, 0); /* must clear it if fp is reused */
95 if (flag & FI_APPEND) {
96 (void) fseek(fp, (off_t)0, SEEK_END);
98 if (flag & FI_UNBUF) {
100 add_my_flag(fp, _IOUNBUF);