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 /* @(#)xio.c 1.11 04/07/11 Copyright 2003-2004 J. Schilling */
15 * EXtended I/O functions for cdrecord
17 * Copyright (c) 2003-2004 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.
42 #include <io.h> /* for setmode() prototype */
47 static xio_t x_stdin = {
51 STDIN_FILENO, /* x_file */
53 O_RDONLY, /* x_oflag */
57 static xio_t *x_root = &x_stdin;
58 static xio_t **x_tail = NULL;
61 static xio_t *xnewnode(char *name);
62 void *xopen(char *name, int oflag, int mode);
70 if ((xp = malloc(sizeof (xio_t))) == NULL)
71 return ((xio_t *) NULL);
73 xp->x_next = (xio_t *) NULL;
74 xp->x_name = strdup(name);
75 if (xp->x_name == NULL) {
77 return ((xio_t *) NULL);
88 xopen(char *name, int oflag, int mode)
95 x_tail = &x_stdin.x_next;
100 if ((oflag & O_BINARY) != 0) {
101 setmode(STDIN_FILENO, O_BINARY);
106 for (; pp; pp = pp->x_next) {
107 if (pp->x_name == NULL) /* stdin avoid core dump in strcmp() */
109 if ((strcmp(pp->x_name, name) == 0) &&
110 (pp->x_oflag == oflag) && (pp->x_omode == mode)) {
118 if ((f = open(name, oflag, mode)) < 0)
121 if ((xp = xnewnode(name)) == NULL) {
129 x_tail = &xp->x_next;
143 x_tail = &x_stdin.x_next;
145 if (--xp->x_refcnt <= 0) {
146 ret = close(xp->x_file);
148 if (pp->x_next == xp)
150 if (pp->x_next == NULL)
154 if (pp->x_next == xp) {
155 if (x_tail == &xp->x_next)
156 x_tail = &pp->x_next;
157 pp->x_next = xp->x_next;