summaryrefslogtreecommitdiff
path: root/librols/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'librols/stdio')
-rw-r--r--librols/stdio/cvmod.c74
-rw-r--r--librols/stdio/dat.c34
-rw-r--r--librols/stdio/fcons.c94
-rw-r--r--librols/stdio/fdown.c40
-rw-r--r--librols/stdio/fdup.c51
-rw-r--r--librols/stdio/ffileread.c51
-rw-r--r--librols/stdio/ffilewrite.c43
-rw-r--r--librols/stdio/fgetline.c84
-rw-r--r--librols/stdio/file_raise.c59
-rw-r--r--librols/stdio/fileclose.c40
-rw-r--r--librols/stdio/fileluopen.c84
-rw-r--r--librols/stdio/filemopen.c55
-rw-r--r--librols/stdio/fileopen.c50
-rw-r--r--librols/stdio/filepos.c45
-rw-r--r--librols/stdio/fileread.c105
-rw-r--r--librols/stdio/filereopen.c104
-rw-r--r--librols/stdio/fileseek.c53
-rw-r--r--librols/stdio/filesize.c47
-rw-r--r--librols/stdio/filestat.c42
-rw-r--r--librols/stdio/filewrite.c107
-rw-r--r--librols/stdio/flag.c142
-rw-r--r--librols/stdio/flush.c38
-rw-r--r--librols/stdio/fpipe.c53
-rw-r--r--librols/stdio/niread.c54
-rw-r--r--librols/stdio/niwrite.c54
-rw-r--r--librols/stdio/nixread.c69
-rw-r--r--librols/stdio/nixwrite.c69
-rw-r--r--librols/stdio/openfd.c44
-rw-r--r--librols/stdio/peekc.c47
-rw-r--r--librols/stdio/schilyio.h248
30 files changed, 2080 insertions, 0 deletions
diff --git a/librols/stdio/cvmod.c b/librols/stdio/cvmod.c
new file mode 100644
index 0000000..a825c42
--- /dev/null
+++ b/librols/stdio/cvmod.c
@@ -0,0 +1,74 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)cvmod.c 2.9 04/08/08 Copyright 1986, 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+#ifndef O_LARGEFILE
+#define O_LARGEFILE 0
+#endif
+
+EXPORT int
+_cvmod(mode, omode, flag)
+ const char *mode;
+ int *omode;
+ int *flag;
+{
+ while (*mode) {
+ switch (*mode) {
+
+ case 'r': *omode |= O_RDONLY; *flag |= FI_READ; break;
+ case 'w': *omode |= O_WRONLY; *flag |= FI_WRITE; break;
+ case 'e': *omode |= O_EXCL; break;
+ case 'c': *omode |= O_CREAT; *flag |= FI_CREATE; break;
+ case 't': *omode |= O_TRUNC; *flag |= FI_TRUNC; break;
+ case 'a': *omode |= O_APPEND; *flag |= FI_APPEND; break;
+ case 'u': *flag |= FI_UNBUF; break;
+ /* dummy on UNIX */
+ case 'b': *omode |= O_BINARY; *flag |= FI_BINARY; break;
+ /*
+ * XXX do we need this ?
+ * XXX May this be a problem?
+ */
+ case 'l': *omode |= O_LARGEFILE; break;
+ default: raisecond(_badmode, 0L);
+ return (0);
+ }
+ mode++;
+ }
+ if (*flag & FI_READ && *flag & FI_WRITE) {
+ *omode &= ~(O_RDONLY|O_WRONLY);
+ *omode |= O_RDWR;
+ }
+ return (1);
+}
diff --git a/librols/stdio/dat.c b/librols/stdio/dat.c
new file mode 100644
index 0000000..cda63cf
--- /dev/null
+++ b/librols/stdio/dat.c
@@ -0,0 +1,34 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)dat.c 1.3 03/06/15 Copyright 1986, 1996-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1996-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+char _badfile[] = "bad_file";
+char _badmode[] = "bad_file_mode";
+char _badop[] = "bad_file_op";
diff --git a/librols/stdio/fcons.c b/librols/stdio/fcons.c
new file mode 100644
index 0000000..1630248
--- /dev/null
+++ b/librols/stdio/fcons.c
@@ -0,0 +1,94 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)fcons.c 2.17 04/08/08 Copyright 1986, 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+/*
+ * Note that because of a definition in schilyio.h we are using fseeko()/ftello()
+ * instead of fseek()/ftell() if available.
+ */
+
+LOCAL char *fmtab[] = {
+ "", /* 0 FI_NONE */
+ "r", /* 1 FI_READ */
+ "w", /* 2 FI_WRITE **1) */
+ "r+", /* 3 FI_READ | FI_WRITE */
+ "b", /* 4 FI_NONE | FI_BINARY */
+ "rb", /* 5 FI_READ | FI_BINARY */
+ "wb", /* 6 FI_WRITE | FI_BINARY **1) */
+ "r+b", /* 7 FI_READ | FI_WRITE | FI_BINARY */
+
+/* + FI_APPEND */ "", /* 0 FI_NONE */
+/* ... */ "r", /* 1 FI_READ */
+ "a", /* 2 FI_WRITE **1) */
+ "a+", /* 3 FI_READ | FI_WRITE */
+ "b", /* 4 FI_NONE | FI_BINARY */
+ "rb", /* 5 FI_READ | FI_BINARY */
+ "ab", /* 6 FI_WRITE | FI_BINARY **1) */
+ "a+b", /* 7 FI_READ | FI_WRITE | FI_BINARY */
+ };
+/*
+ * NOTES:
+ * 1) fdopen() guarantees not to create/trunc files in this case
+ *
+ * "w" will create/trunc files with fopen()
+ * "a" will create files with fopen()
+ */
+
+
+EXPORT FILE *
+_fcons(fd, f, flag)
+ register FILE *fd;
+ int f;
+ int flag;
+{
+ int my_gflag = _io_glflag;
+
+ if (fd == (FILE *)NULL)
+ fd = fdopen(f,
+ fmtab[flag&(FI_READ|FI_WRITE|FI_BINARY | FI_APPEND)]);
+
+ if (fd != (FILE *)NULL) {
+ if (flag & FI_APPEND) {
+ (void) fseek(fd, (off_t)0, SEEK_END);
+ }
+ if (flag & FI_UNBUF) {
+ setbuf(fd, NULL);
+ my_gflag |= _IOUNBUF;
+ }
+ set_my_flag(fd, my_gflag); /* must clear it if fd is reused */
+ return (fd);
+ }
+ if (flag & FI_CLOSE)
+ close(f);
+
+ return ((FILE *) NULL);
+}
diff --git a/librols/stdio/fdown.c b/librols/stdio/fdown.c
new file mode 100644
index 0000000..375530f
--- /dev/null
+++ b/librols/stdio/fdown.c
@@ -0,0 +1,40 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)fdown.c 1.10 04/08/08 Copyright 1986, 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+EXPORT int
+fdown(f)
+ register FILE *f;
+{
+ down(f);
+ return (fileno(f));
+}
diff --git a/librols/stdio/fdup.c b/librols/stdio/fdup.c
new file mode 100644
index 0000000..cdb180d
--- /dev/null
+++ b/librols/stdio/fdup.c
@@ -0,0 +1,51 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)fdup.c 1.14 04/08/08 Copyright 1986, 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+/*
+ * Note that because of a definition in schilyio.h we are using fseeko()/ftello()
+ * instead of fseek()/ftell() if available.
+ */
+
+EXPORT FILE *
+fdup(f)
+ register FILE *f;
+{
+ int newfd;
+
+ down(f);
+ if ((newfd = dup(fileno(f))) < 0)
+ return ((FILE *) NULL);
+
+ lseek(newfd, ftell(f), SEEK_SET);
+ return (_fcons((FILE *)0, newfd, (FI_READ | FI_WRITE | FI_CLOSE)));
+}
diff --git a/librols/stdio/ffileread.c b/librols/stdio/ffileread.c
new file mode 100644
index 0000000..cbf8276
--- /dev/null
+++ b/librols/stdio/ffileread.c
@@ -0,0 +1,51 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)ffileread.c 1.10 04/09/25 Copyright 1986, 1996-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1996-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+#include <errno.h>
+
+EXPORT int
+ffileread(f, buf, len)
+ register FILE *f;
+ void *buf;
+ int len;
+{
+ register int fd;
+ register int ret;
+
+ down2(f, _IOREAD, _IORW);
+ fd = fileno(f);
+
+ while ((ret = read(fd, buf, len)) < 0 && geterrno() == EINTR)
+ /* LINTED */
+ ;
+ return (ret);
+}
diff --git a/librols/stdio/ffilewrite.c b/librols/stdio/ffilewrite.c
new file mode 100644
index 0000000..61f6635
--- /dev/null
+++ b/librols/stdio/ffilewrite.c
@@ -0,0 +1,43 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)ffilewrite.c 1.6 04/08/08 Copyright 1986 J. Schilling */
+/*
+ * Copyright (c) 1986 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+EXPORT int
+ffilewrite(f, buf, len)
+ register FILE *f;
+ void *buf;
+ int len;
+{
+ down2(f, _IORWT, _IORW);
+
+ return (write(fileno(f), (char *)buf, len));
+}
diff --git a/librols/stdio/fgetline.c b/librols/stdio/fgetline.c
new file mode 100644
index 0000000..910e0e6
--- /dev/null
+++ b/librols/stdio/fgetline.c
@@ -0,0 +1,84 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)fgetline.c 1.8 04/09/25 Copyright 1986, 1996-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1996-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+/*
+ * XXX should we check if HAVE_USG_STDIO is defined and
+ * XXX use something line memccpy to speed things up ???
+ */
+
+EXPORT int
+rols_fgetline(f, buf, len)
+ register FILE *f;
+ char *buf;
+ register int len;
+{
+ register int c = '\0';
+ register char *bp = buf;
+ register int nl = '\n';
+
+ down2(f, _IOREAD, _IORW);
+
+ for (;;) {
+ if ((c = getc(f)) < 0)
+ break;
+ if (c == nl)
+ break;
+ if (--len > 0) {
+ *bp++ = (char)c;
+ } else {
+ /*
+ * Read up to end of line
+ */
+ while ((c = getc(f)) >= 0 && c != nl)
+ /* LINTED */
+ ;
+ break;
+ }
+ }
+ *bp = '\0';
+ /*
+ * If buffer is empty and we hit EOF, return EOF
+ */
+ if (c < 0 && bp == buf)
+ return (c);
+
+ return (bp - buf);
+}
+
+EXPORT int
+rols_getline(buf, len)
+ char *buf;
+ int len;
+{
+ return (rols_fgetline(stdin, buf, len));
+}
diff --git a/librols/stdio/file_raise.c b/librols/stdio/file_raise.c
new file mode 100644
index 0000000..5605c8e
--- /dev/null
+++ b/librols/stdio/file_raise.c
@@ -0,0 +1,59 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)file_raise.c 1.8 04/08/08 Copyright 1986, 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+EXPORT void
+file_raise(f, flg)
+ register FILE *f;
+ int flg;
+{
+ int oflag;
+extern int _io_glflag;
+
+ if (f == (FILE *)NULL) {
+ if (flg)
+ _io_glflag &= ~_IONORAISE;
+ else
+ _io_glflag |= _IONORAISE;
+ return;
+ }
+ down(f);
+
+ oflag = my_flag(f);
+
+ if (flg)
+ oflag &= ~_IONORAISE;
+ else
+ oflag |= _IONORAISE;
+
+ set_my_flag(f, oflag);
+}
diff --git a/librols/stdio/fileclose.c b/librols/stdio/fileclose.c
new file mode 100644
index 0000000..ce78958
--- /dev/null
+++ b/librols/stdio/fileclose.c
@@ -0,0 +1,40 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)fileclose.c 1.7 04/08/08 Copyright 1986 J. Schilling */
+/*
+ * Copyright (c) 1988 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+EXPORT int
+fileclose(f)
+ FILE *f;
+{
+ down(f);
+ return (fclose(f));
+}
diff --git a/librols/stdio/fileluopen.c b/librols/stdio/fileluopen.c
new file mode 100644
index 0000000..f178d8a
--- /dev/null
+++ b/librols/stdio/fileluopen.c
@@ -0,0 +1,84 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)fileluopen.c 1.17 04/08/08 Copyright 1986, 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+/*
+ * Note that because of a definition in schilyio.h we are using fseeko()/ftello()
+ * instead of fseek()/ftell() if available.
+ */
+
+#ifndef O_NDELAY /* This is undefined on BeOS :-( */
+#define O_NDELAY 0
+#endif
+#ifndef O_CREAT
+#define O_CREAT 0
+#endif
+#ifndef O_TRUNC
+#define O_TRUNC 0
+#endif
+#ifndef O_EXCL
+#define O_EXCL 0
+#endif
+
+/*
+ * fileluopen - open a stream for lun
+ */
+EXPORT FILE *
+fileluopen(f, mode)
+ int f;
+ const char *mode;
+{
+ int omode = 0;
+ int flag = 0;
+
+ if (!_cvmod(mode, &omode, &flag))
+ return ((FILE *) NULL);
+
+ if (omode & (O_NDELAY|O_CREAT|O_TRUNC|O_EXCL)) {
+ raisecond(_badmode, 0L);
+ return ((FILE *) NULL);
+ }
+
+#ifdef F_GETFD
+ if (fcntl(f, F_GETFD, 0) < 0) {
+ raisecond(_badfile, 0L);
+ return ((FILE *) NULL);
+ }
+#endif
+
+#ifdef O_APPEND
+ if (omode & O_APPEND)
+ lseek(f, (off_t)0, SEEK_END);
+#endif
+
+ return (_fcons((FILE *)0, f, flag));
+}
diff --git a/librols/stdio/filemopen.c b/librols/stdio/filemopen.c
new file mode 100644
index 0000000..b8b7482
--- /dev/null
+++ b/librols/stdio/filemopen.c
@@ -0,0 +1,55 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)filemopen.c 1.4 05/08/18 Copyright 1986, 1995-2005 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995-2005 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+EXPORT FILE *
+#ifdef PROTOTYPES
+filemopen(const char *name, const char *mode, mode_t cmode)
+#else
+filemopen(name, mode, cmode)
+ const char *name;
+ const char *mode;
+ mode_t cmode;
+#endif
+{
+ int ret;
+ int omode = 0;
+ int flag = 0;
+
+ if (!_cvmod(mode, &omode, &flag))
+ return ((FILE *) NULL);
+
+ if ((ret = open(name, omode, cmode)) < 0)
+ return ((FILE *) NULL);
+
+ return (_fcons((FILE *)0, ret, flag | FI_CLOSE));
+}
diff --git a/librols/stdio/fileopen.c b/librols/stdio/fileopen.c
new file mode 100644
index 0000000..4b5e9a8
--- /dev/null
+++ b/librols/stdio/fileopen.c
@@ -0,0 +1,50 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)fileopen.c 1.11 05/08/18 Copyright 1986, 1995-2005 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995-2005 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+EXPORT FILE *
+fileopen(name, mode)
+ const char *name;
+ const char *mode;
+{
+ int ret;
+ int omode = 0;
+ int flag = 0;
+
+ if (!_cvmod(mode, &omode, &flag))
+ return ((FILE *) NULL);
+
+ if ((ret = _openfd(name, omode)) < 0)
+ return ((FILE *) NULL);
+
+ return (_fcons((FILE *)0, ret, flag | FI_CLOSE));
+}
diff --git a/librols/stdio/filepos.c b/librols/stdio/filepos.c
new file mode 100644
index 0000000..37f9166
--- /dev/null
+++ b/librols/stdio/filepos.c
@@ -0,0 +1,45 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)filepos.c 1.10 04/08/08 Copyright 1986, 1996-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1996-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+/*
+ * Note that because of a definition in schilyio.h we are using fseeko()/ftello()
+ * instead of fseek()/ftell() if available.
+ */
+
+EXPORT off_t
+filepos(f)
+ register FILE *f;
+{
+ down(f);
+ return (ftell(f));
+}
diff --git a/librols/stdio/fileread.c b/librols/stdio/fileread.c
new file mode 100644
index 0000000..2550f31
--- /dev/null
+++ b/librols/stdio/fileread.c
@@ -0,0 +1,105 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)fileread.c 1.14 04/08/08 Copyright 1986, 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+static char _readerr[] = "file_read_err";
+
+#ifdef HAVE_USG_STDIO
+
+EXPORT int
+fileread(f, buf, len)
+ register FILE *f;
+ void *buf;
+ int len;
+{
+ int cnt;
+ register int n;
+
+ down2(f, _IOREAD, _IORW);
+
+ if (f->_flag & _IONBF) {
+ cnt = _niread(fileno(f), buf, len);
+ if (cnt < 0) {
+ f->_flag |= _IOERR;
+ if (!(my_flag(f) & _IONORAISE))
+ raisecond(_readerr, 0L);
+ }
+ if (cnt == 0 && len)
+ f->_flag |= _IOEOF;
+ return (cnt);
+ }
+ cnt = 0;
+ while (len > 0) {
+ if (f->_cnt <= 0) {
+ if (usg_filbuf(f) == EOF)
+ break;
+ f->_cnt++;
+ f->_ptr--;
+ }
+ n = f->_cnt >= len ? len : f->_cnt;
+ buf = (void *)movebytes(f->_ptr, buf, n);
+ f->_ptr += n;
+ f->_cnt -= n;
+ cnt += n;
+ len -= n;
+ }
+ if (!ferror(f))
+ return (cnt);
+ if (!(my_flag(f) & _IONORAISE))
+ raisecond(_readerr, 0L);
+ return (-1);
+}
+
+#else
+
+EXPORT int
+fileread(f, buf, len)
+ register FILE *f;
+ void *buf;
+ int len;
+{
+ int cnt;
+
+ down2(f, _IOREAD, _IORW);
+
+ if (my_flag(f) & _IOUNBUF)
+ return (_niread(fileno(f), buf, len));
+ cnt = fread(buf, 1, len, f);
+
+ if (!ferror(f))
+ return (cnt);
+ if (!(my_flag(f) & _IONORAISE))
+ raisecond(_readerr, 0L);
+ return (-1);
+}
+
+#endif /* HAVE_USG_STDIO */
diff --git a/librols/stdio/filereopen.c b/librols/stdio/filereopen.c
new file mode 100644
index 0000000..537edfc
--- /dev/null
+++ b/librols/stdio/filereopen.c
@@ -0,0 +1,104 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)filereopen.c 1.15 04/08/08 Copyright 1986, 1995 J. Schilling */
+/*
+ * open new file on old stream
+ *
+ * Copyright (c) 1986, 1995 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+/*
+ * Note that because of a definition in schilyio.h we are using fseeko()/ftello()
+ * instead of fseek()/ftell() if available.
+ */
+
+LOCAL char *fmtab[] = {
+ "", /* 0 FI_NONE */
+ "r", /* 1 FI_READ */
+ "r+", /* 2 FI_WRITE **1) */
+ "r+", /* 3 FI_READ | FI_WRITE */
+ "b", /* 4 FI_NONE | FI_BINARY */
+ "rb", /* 5 FI_READ | FI_BINARY */
+ "r+b", /* 6 FI_WRITE | FI_BINARY **1) */
+ "r+b", /* 7 FI_READ | FI_WRITE | FI_BINARY */
+
+/* + FI_APPEND */ "", /* 0 FI_NONE */
+/* ... */ "r", /* 1 FI_READ */
+ "a", /* 2 FI_WRITE **1) */
+ "a+", /* 3 FI_READ | FI_WRITE */
+ "b", /* 4 FI_NONE | FI_BINARY */
+ "rb", /* 5 FI_READ | FI_BINARY */
+ "ab", /* 6 FI_WRITE | FI_BINARY **1) */
+ "a+b", /* 7 FI_READ | FI_WRITE | FI_BINARY */
+ };
+/*
+ * NOTES:
+ * 1) there is no fopen() mode that opens for writing
+ * without creating/truncating at the same time.
+ *
+ * "w" will create/trunc files with fopen()
+ * "a" will create files with fopen()
+ */
+
+EXPORT FILE *
+filereopen(name, mode, fp)
+ const char *name;
+ const char *mode;
+ FILE *fp;
+{
+ int ret;
+ int omode = 0;
+ int flag = 0;
+
+ if (!_cvmod(mode, &omode, &flag))
+ return ((FILE *) NULL);
+
+ /*
+ * create/truncate file if necessary
+ */
+ if ((ret = _openfd(name, omode)) < 0)
+ return ((FILE *) NULL);
+ close(ret);
+
+ fp = freopen(name,
+ fmtab[flag & (FI_READ | FI_WRITE | FI_BINARY | FI_APPEND)], fp);
+
+ if (fp != (FILE *) NULL) {
+ set_my_flag(fp, 0); /* must clear it if fp is reused */
+
+ if (flag & FI_APPEND) {
+ (void) fseek(fp, (off_t)0, SEEK_END);
+ }
+ if (flag & FI_UNBUF) {
+ setbuf(fp, NULL);
+ add_my_flag(fp, _IOUNBUF);
+ }
+ }
+ return (fp);
+}
diff --git a/librols/stdio/fileseek.c b/librols/stdio/fileseek.c
new file mode 100644
index 0000000..6ea0b17
--- /dev/null
+++ b/librols/stdio/fileseek.c
@@ -0,0 +1,53 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)fileseek.c 1.12 04/08/08 Copyright 1986, 1996-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1996-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+/*
+ * Note that because of a definition in schilyio.h we are using fseeko()/ftello()
+ * instead of fseek()/ftell() if available.
+ */
+
+static char _seekerr[] = "file_seek_err";
+
+EXPORT int
+fileseek(f, pos)
+ register FILE *f;
+ off_t pos;
+{
+ int ret;
+
+ down(f);
+ ret = fseek(f, pos, SEEK_SET);
+ if (ret < 0 && !(my_flag(f) & _IONORAISE))
+ raisecond(_seekerr, 0L);
+ return (ret);
+}
diff --git a/librols/stdio/filesize.c b/librols/stdio/filesize.c
new file mode 100644
index 0000000..cecb52b
--- /dev/null
+++ b/librols/stdio/filesize.c
@@ -0,0 +1,47 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)filesize.c 1.13 04/08/08 Copyright 1986, 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+#include <statdefs.h>
+
+EXPORT off_t
+filesize(f)
+ register FILE *f;
+{
+ struct stat buf;
+
+ down(f);
+ if (fstat(fileno(f), &buf) < 0) {
+ raisecond("filesize", 0L);
+ return (-1);
+ }
+ return (buf.st_size);
+}
diff --git a/librols/stdio/filestat.c b/librols/stdio/filestat.c
new file mode 100644
index 0000000..f9ba8db
--- /dev/null
+++ b/librols/stdio/filestat.c
@@ -0,0 +1,42 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)filestat.c 1.9 04/08/08 Copyright 1985 J. Schilling */
+/*
+ * Copyright (c) 1985 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+#include <statdefs.h>
+
+EXPORT int
+filestat(f, stbuf)
+ FILE *f;
+ struct stat *stbuf;
+{
+ down(f);
+ return (fstat(fileno(f), stbuf));
+}
diff --git a/librols/stdio/filewrite.c b/librols/stdio/filewrite.c
new file mode 100644
index 0000000..dd3603f
--- /dev/null
+++ b/librols/stdio/filewrite.c
@@ -0,0 +1,107 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)filewrite.c 1.14 04/08/08 Copyright 1986, 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+static char _writeerr[] = "file_write_err";
+
+#ifdef HAVE_USG_STDIO
+
+EXPORT int
+filewrite(f, vbuf, len)
+ register FILE *f;
+ void *vbuf;
+ int len;
+{
+ register int n;
+ int cnt;
+ char *buf = vbuf;
+
+ down2(f, _IOWRT, _IORW);
+
+ if (f->_flag & _IONBF) {
+ cnt = write(fileno(f), buf, len);
+ if (cnt < 0) {
+ f->_flag |= _IOERR;
+ if (!(my_flag(f) & _IONORAISE))
+ raisecond(_writeerr, 0L);
+ }
+ return (cnt);
+ }
+ cnt = 0;
+ while (len > 0) {
+ if (f->_cnt <= 0) {
+ if (usg_flsbuf((unsigned char) *buf++, f) == EOF)
+ break;
+ cnt++;
+ if (--len == 0)
+ break;
+ }
+ if ((n = f->_cnt >= len ? len : f->_cnt) > 0) {
+ f->_ptr = (unsigned char *)movebytes(buf, f->_ptr, n);
+ buf += n;
+ f->_cnt -= n;
+ cnt += n;
+ len -= n;
+ }
+ }
+ if (!ferror(f))
+ return (cnt);
+ if (!(my_flag(f) & _IONORAISE))
+ raisecond(_writeerr, 0L);
+ return (-1);
+}
+
+#else
+
+EXPORT int
+filewrite(f, vbuf, len)
+ register FILE *f;
+ void *vbuf;
+ int len;
+{
+ int cnt;
+ char *buf = vbuf;
+
+ down2(f, _IOWRT, _IORW);
+
+ if (my_flag(f) & _IOUNBUF)
+ return (write(fileno(f), buf, len));
+ cnt = fwrite(buf, 1, len, f);
+
+ if (!ferror(f))
+ return (cnt);
+ if (!(my_flag(f) & _IONORAISE))
+ raisecond(_writeerr, 0L);
+ return (-1);
+}
+
+#endif /* HAVE_USG_STDIO */
diff --git a/librols/stdio/flag.c b/librols/stdio/flag.c
new file mode 100644
index 0000000..a9571c6
--- /dev/null
+++ b/librols/stdio/flag.c
@@ -0,0 +1,142 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)flag.c 2.10 05/06/12 Copyright 1986-2003 J. Schilling */
+/*
+ * Copyright (c) 1986-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+#include <stdxlib.h>
+
+#ifdef DO_MYFLAG
+
+#define FL_INIT 10
+
+EXPORT int _io_glflag; /* global default flag */
+LOCAL int _fl_inc = 10; /* increment for expanding flag struct */
+EXPORT int _fl_max = FL_INIT; /* max fd currently in _io_myfl */
+LOCAL _io_fl _io_smyfl[FL_INIT]; /* initial static space */
+EXPORT _io_fl *_io_myfl = _io_smyfl; /* init to static space */
+
+LOCAL int _more_flags __PR((FILE *));
+
+LOCAL int
+_more_flags(fp)
+ FILE *fp;
+{
+ register int f = fileno(fp);
+ register int n = _fl_max;
+ register _io_fl *np;
+
+ while (n <= f)
+ n += _fl_inc;
+
+ if (_io_myfl == _io_smyfl) {
+ np = (_io_fl *) malloc(n * sizeof (*np));
+ fillbytes(np, n * sizeof (*np), '\0');
+ movebytes(_io_smyfl, np, sizeof (_io_smyfl)/sizeof (*np));
+ } else {
+ np = (_io_fl *) realloc(_io_myfl, n * sizeof (*np));
+ if (np)
+ fillbytes(&np[_fl_max], (n-_fl_max)*sizeof (*np), '\0');
+ }
+ if (np) {
+ _io_myfl = np;
+ _fl_max = n;
+ return (_io_get_my_flag(fp));
+ } else {
+ return (_IONORAISE);
+ }
+}
+
+EXPORT int
+_io_get_my_flag(fp)
+ register FILE *fp;
+{
+ register int f = fileno(fp);
+ register _io_fl *fl;
+
+ if (f >= _fl_max)
+ return (_more_flags(fp));
+
+ fl = &_io_myfl[f];
+
+ if (fl->fl_io == 0 || fl->fl_io == fp)
+ return (fl->fl_flags);
+
+ while (fl && fl->fl_io != fp)
+ fl = fl->fl_next;
+
+ if (fl == 0)
+ return (0);
+
+ return (fl->fl_flags);
+}
+
+EXPORT void
+_io_set_my_flag(fp, flag)
+ FILE *fp;
+ int flag;
+{
+ register int f = fileno(fp);
+ register _io_fl *fl;
+ register _io_fl *fl2;
+
+ if (f >= _fl_max)
+ (void) _more_flags(fp);
+
+ fl = &_io_myfl[f];
+
+ if (fl->fl_io != (FILE *)0) {
+ fl2 = fl;
+
+ while (fl && fl->fl_io != fp)
+ fl = fl->fl_next;
+ if (fl == 0) {
+ if ((fl = (_io_fl *) malloc(sizeof (*fl))) == 0)
+ return;
+ fl->fl_next = fl2->fl_next;
+ fl2->fl_next = fl;
+ }
+ }
+ fl->fl_io = fp;
+ fl->fl_flags = flag;
+}
+
+EXPORT void
+_io_add_my_flag(fp, flag)
+ FILE *fp;
+ int flag;
+{
+ int oflag = _io_get_my_flag(fp);
+
+ oflag |= flag;
+
+ _io_set_my_flag(fp, oflag);
+}
+
+#endif /* DO_MYFLAG */
diff --git a/librols/stdio/flush.c b/librols/stdio/flush.c
new file mode 100644
index 0000000..9d9f2fa
--- /dev/null
+++ b/librols/stdio/flush.c
@@ -0,0 +1,38 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)flush.c 1.7 04/08/08 Copyright 1986 J. Schilling */
+/*
+ * Copyright (c) 1986 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+EXPORT int
+flush()
+{
+ return (fflush(stdout));
+}
diff --git a/librols/stdio/fpipe.c b/librols/stdio/fpipe.c
new file mode 100644
index 0000000..72f3ee9
--- /dev/null
+++ b/librols/stdio/fpipe.c
@@ -0,0 +1,53 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)fpipe.c 1.12 04/08/08 Copyright 1986, 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+EXPORT int
+fpipe(pipef)
+ FILE *pipef[];
+{
+ int filedes[2];
+
+ if (pipe(filedes) < 0)
+ return (0);
+
+ if ((pipef[0] = _fcons((FILE *)0,
+ filedes[0], FI_READ|FI_CLOSE)) != (FILE *)0) {
+ if ((pipef[1] = _fcons((FILE *)0,
+ filedes[1], FI_WRITE|FI_CLOSE)) != (FILE *)0) {
+ return (1);
+ }
+ fclose(pipef[0]);
+ }
+ close(filedes[1]);
+ return (0);
+}
diff --git a/librols/stdio/niread.c b/librols/stdio/niread.c
new file mode 100644
index 0000000..2f025fa
--- /dev/null
+++ b/librols/stdio/niread.c
@@ -0,0 +1,54 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)niread.c 1.12 04/08/08 Copyright 1986, 1996-2003 J. Schilling */
+/*
+ * Non interruptable read
+ *
+ * Copyright (c) 1986, 1996-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+#include <errno.h>
+
+EXPORT int
+_niread(f, buf, count)
+ int f;
+ void *buf;
+ int count;
+{
+ int ret;
+ int oerrno = geterrno();
+
+ while ((ret = read(f, buf, count)) < 0 && geterrno() == EINTR) {
+ /*
+ * Set back old 'errno' so we don't change the errno visible
+ * to the outside if we did not fail.
+ */
+ seterrno(oerrno);
+ }
+ return (ret);
+}
diff --git a/librols/stdio/niwrite.c b/librols/stdio/niwrite.c
new file mode 100644
index 0000000..a5ebd85
--- /dev/null
+++ b/librols/stdio/niwrite.c
@@ -0,0 +1,54 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)niwrite.c 1.5 04/08/08 Copyright 1986, 2001-2003 J. Schilling */
+/*
+ * Non interruptable write
+ *
+ * Copyright (c) 1986, 2001-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+#include <errno.h>
+
+EXPORT int
+_niwrite(f, buf, count)
+ int f;
+ void *buf;
+ int count;
+{
+ int ret;
+ int oerrno = geterrno();
+
+ while ((ret = write(f, buf, count)) < 0 && geterrno() == EINTR) {
+ /*
+ * Set back old 'errno' so we don't change the errno visible
+ * to the outside if we did not fail.
+ */
+ seterrno(oerrno);
+ }
+ return (ret);
+}
diff --git a/librols/stdio/nixread.c b/librols/stdio/nixread.c
new file mode 100644
index 0000000..2d83987
--- /dev/null
+++ b/librols/stdio/nixread.c
@@ -0,0 +1,69 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)nixread.c 1.12 04/08/08 Copyright 1986, 1996-2003 J. Schilling */
+/*
+ * Non interruptable extended read
+ *
+ * Copyright (c) 1986, 1996-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+#include <errno.h>
+
+EXPORT int
+_nixread(f, buf, count)
+ int f;
+ void *buf;
+ int count;
+{
+ register char *p = (char *)buf;
+ register int ret;
+ register int total = 0;
+ int oerrno = geterrno();
+
+ while (count > 0) {
+ while ((ret = read(f, p, count)) < 0) {
+ if (geterrno() == EINTR) {
+ /*
+ * Set back old 'errno' so we don't change the
+ * errno visible to the outside if we did
+ * not fail.
+ */
+ seterrno(oerrno);
+ continue;
+ }
+ return (ret); /* Any other error */
+ }
+ if (ret == 0) /* Something went wrong */
+ break;
+
+ total += ret;
+ count -= ret;
+ p += ret;
+ }
+ return (total);
+}
diff --git a/librols/stdio/nixwrite.c b/librols/stdio/nixwrite.c
new file mode 100644
index 0000000..b9fa4df
--- /dev/null
+++ b/librols/stdio/nixwrite.c
@@ -0,0 +1,69 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)nixwrite.c 1.5 04/08/08 Copyright 1986, 2001-2003 J. Schilling */
+/*
+ * Non interruptable extended write
+ *
+ * Copyright (c) 1986, 2001-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+#include <errno.h>
+
+EXPORT int
+_nixwrite(f, buf, count)
+ int f;
+ void *buf;
+ int count;
+{
+ register char *p = (char *)buf;
+ register int ret;
+ register int total = 0;
+ int oerrno = geterrno();
+
+ while (count > 0) {
+ while ((ret = write(f, p, count)) < 0) {
+ if (geterrno() == EINTR) {
+ /*
+ * Set back old 'errno' so we don't change the
+ * errno visible to the outside if we did
+ * not fail.
+ */
+ seterrno(oerrno);
+ continue;
+ }
+ return (ret); /* Any other error */
+ }
+ if (ret == 0) /* EOF */
+ break;
+
+ total += ret;
+ count -= ret;
+ p += ret;
+ }
+ return (total);
+}
diff --git a/librols/stdio/openfd.c b/librols/stdio/openfd.c
new file mode 100644
index 0000000..d0e110c
--- /dev/null
+++ b/librols/stdio/openfd.c
@@ -0,0 +1,44 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)openfd.c 1.9 04/08/08 Copyright 1986, 1995 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+#if defined(_openfd) && !defined(USE_LARGEFILES)
+# undef _openfd
+#endif
+
+EXPORT int
+_openfd(name, omode)
+ const char *name;
+ int omode;
+{
+ return (open(name, omode, 0666));
+}
diff --git a/librols/stdio/peekc.c b/librols/stdio/peekc.c
new file mode 100644
index 0000000..ce98557
--- /dev/null
+++ b/librols/stdio/peekc.c
@@ -0,0 +1,47 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)peekc.c 1.7 04/08/08 Copyright 1986, 1996-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1996-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "schilyio.h"
+
+EXPORT int
+peekc(f)
+ FILE *f;
+{
+ int c;
+
+ down2(f, _IOREAD, _IORW);
+
+ if (ferror(f))
+ return (EOF);
+ if ((c = getc(f)) != EOF)
+ ungetc(c, f);
+ return (c);
+}
diff --git a/librols/stdio/schilyio.h b/librols/stdio/schilyio.h
new file mode 100644
index 0000000..c97f845
--- /dev/null
+++ b/librols/stdio/schilyio.h
@@ -0,0 +1,248 @@
+/*
+ * This file has been modified for the cdrkit suite.
+ *
+ * The behaviour and appearence of the program code below can differ to a major
+ * extent from the version distributed by the original author(s).
+ *
+ * For details, see Changelog file distributed with the cdrkit package. If you
+ * received this file from another source then ask the distributing person for
+ * a log of modifications.
+ *
+ */
+
+/* @(#)schilyio.h 2.22 04/09/04 Copyright 1986, 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 1986, 1995-2003 J. Schilling
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; see the file COPYING. If not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _STDIO_SCHILYIO_H
+#define _STDIO_SCHILYIO_H
+
+#include <mconfig.h>
+#include <stdio.h>
+#include <standard.h>
+#include <unixstd.h>
+#include <fctldefs.h>
+#include <schily.h>
+
+#ifdef NO_USG_STDIO
+# ifdef HAVE_USG_STDIO
+# undef HAVE_USG_STDIO
+# endif
+#endif
+
+/*#if _LFS_LARGEFILE*/
+#ifdef HAVE_LARGEFILES
+/*
+ * XXX We may need to put this code to a more global place to allow all
+ * XXX users of fseek()/ftell() to automaticaly use fseeko()/ftello()
+ * XXX if the latter are available.
+ *
+ * If HAVE_LARGEFILES is defined, it is guaranteed that fseeko()/ftello()
+ * both are available.
+ */
+# define fseek fseeko
+# define ftell ftello
+
+#else /* !HAVE_LARGEFILES */
+/*
+ * If HAVE_LARGEFILES is not defined, we depend on specific tests for
+ * fseeko()/ftello() which must have been done before the tests for
+ * Large File support have been done.
+ * Note that this only works if the tests used below are really done before
+ * the Large File autoconf test is run. This is because autoconf does no
+ * clean testing but instead cumulatively modifes the envivonment used for
+ * testing.
+ */
+#ifdef HAVE_FSEEKO
+# define fseek fseeko
+#endif
+#ifdef HAVE_FTELLO
+# define ftell ftello
+#endif
+
+#endif
+
+/*
+ * speed things up...
+ */
+#ifndef _OPENFD_SRC
+#ifdef _openfd
+#undef _openfd
+#endif
+#define _openfd(name, omode) (open(name, omode, 0666))
+#endif
+
+#define DO_MYFLAG /* use local flags */
+
+/*
+ * Flags used during fileopen(), ... by _fcons()/ _cvmod()
+ */
+#define FI_NONE 0x0000 /* no flags defined */
+
+#define FI_READ 0x0001 /* open for reading */
+#define FI_WRITE 0x0002 /* open for writing */
+#define FI_BINARY 0x0004 /* open in binary mode */
+#define FI_APPEND 0x0008 /* append on each write */
+
+#define FI_CREATE 0x0010 /* create if nessecary */
+#define FI_TRUNC 0x0020 /* truncate file on open */
+#define FI_UNBUF 0x0080 /* dont't buffer io */
+#define FI_CLOSE 0x1000 /* close file on error */
+
+/*
+ * local flags
+ */
+#define _IONORAISE 01 /* do no raisecond() on errors */
+#define _IOUNBUF 02 /* do unbuffered i/o */
+
+#ifdef DO_MYFLAG
+
+struct _io_flags {
+ FILE *fl_io; /* file pointer */
+ struct _io_flags /* pointer to next struct */
+ *fl_next; /* if more file pointer to same fd */
+ int fl_flags; /* my flags */
+};
+
+typedef struct _io_flags _io_fl;
+
+extern int _io_glflag; /* global default flag */
+extern _io_fl *_io_myfl; /* array of structs to hold my flags */
+extern int _fl_max; /* max fd currently in _io_myfl */
+
+/*
+ * if fileno > max
+ * expand
+ * else if map[fileno].pointer == 0
+ * return 0
+ * else if map[fileno].pointer == p
+ * return map[fileno].flags
+ * else
+ * search list
+ */
+#define flp(p) (&_io_myfl[fileno(p)])
+
+#ifdef MY_FLAG_IS_MACRO
+#define my_flag(p) ((int)fileno(p) >= _fl_max ? \
+ _io_get_my_flag(p) : \
+ ((flp(p)->fl_io == 0 || flp(p)->fl_io == p) ? \
+ flp(p)->fl_flags : \
+ _io_get_my_flag(p)))
+#else
+#define my_flag(p) _io_get_my_flag(p)
+#endif
+
+#define set_my_flag(p, v) _io_set_my_flag(p, v)
+#define add_my_flag(p, v) _io_add_my_flag(p, v)
+
+extern int _io_get_my_flag __PR((FILE *));
+extern void _io_set_my_flag __PR((FILE *, int));
+extern void _io_add_my_flag __PR((FILE *, int));
+
+#else /* DO_MYFLAG */
+
+#define my_flag(p) _IONORAISE /* Always noraise */
+#define set_my_flag(p, v) /* Ignore */
+#define add_my_flag(p, v) /* Ignore */
+
+#endif /* DO_MYFLAG */
+
+#ifdef HAVE_USG_STDIO
+
+/*
+ * Use the right filbuf()/flsbuf() function.
+ */
+#ifdef HAVE___FILBUF
+# define usg_filbuf(fp) __filbuf(fp)
+# define usg_flsbuf(c, fp) __flsbuf(c, fp)
+/*
+ * Define prototypes to verify if our interface is right
+ */
+extern int __filbuf __PR((FILE *));
+/*extern int __flsbuf __PR(());*/
+#else
+# ifdef HAVE__FILBUF
+# define usg_filbuf(fp) _filbuf(fp)
+# define usg_flsbuf(c, fp) _flsbuf(c, fp)
+/*
+ * Define prototypes to verify if our interface is right
+ */
+extern int _filbuf __PR((FILE *));
+/*extern int _flsbuf __PR(());*/
+# else
+/*
+ * no filbuf() but this will not happen on USG_STDIO systems.
+ */
+# endif
+#endif
+/*
+ * Do not check this because flsbuf()'s 1st parameter may be
+ * int SunOS
+ * unsigned int Apollo
+ * unsigned char HP-UX-11
+ *
+ * Note that the interface is now checked by autoconf.
+ */
+/*extern int _flsbuf __PR((int, FILE *));*/
+#else
+/*
+ * If we are on a non USG system we cannot down file pointers
+ */
+#undef DO_DOWN
+#endif
+
+#ifndef DO_DOWN
+/*
+ * No stream checking
+ */
+#define down(f)
+#define down1(f, fl1)
+#define down2(f, fl1, fl2)
+#else
+/*
+ * Do stream checking (works only on USG stdio)
+ *
+ * New version of USG stdio.
+ * _iob[] holds only a small amount of pointers.
+ * Aditional space is allocated.
+ * We may check only if the file pointer is != NULL
+ * and if iop->_flag refers to a stream with appropriate modes.
+ * If _iob[] gets expanded by malloc() we cannot check upper bound.
+ */
+#define down(f) ((f) == 0 || (f)->_flag == 0 ? \
+ (raisecond(_badfile, 0L), (FILE *)0) : (f))
+
+#define down1(f, fl1) ((f) == 0 || (f)->_flag == 0 ? \
+ (raisecond(_badfile, 0L), (FILE *)0) : \
+ (((f)->_flag & fl1) != fl1 ? \
+ (raisecond(_badop, 0L), (FILE *)0) : \
+ (f)))
+
+#define down2(f, fl1, fl2) ((f) == 0 || (f)->_flag == 0 ? \
+ (raisecond(_badfile, 0L), (FILE *)0) : \
+ (((f)->_flag & fl1) != fl1 && \
+ ((f)->_flag & fl2) != fl2 ? \
+ (raisecond(_badop, 0L), (FILE *)0) : \
+ (f)))
+#endif /* DO_DOWN */
+
+extern char _badfile[];
+extern char _badmode[];
+extern char _badop[];
+
+#endif /* _STDIO_SCHILYIO_H */