summaryrefslogtreecommitdiff
path: root/librols
diff options
context:
space:
mode:
Diffstat (limited to 'librols')
-rw-r--r--librols/CMakeLists.txt7
-rw-r--r--librols/astoi.c151
-rw-r--r--librols/astoll.c120
-rw-r--r--librols/astoull.c182
-rw-r--r--librols/breakline.c77
-rw-r--r--librols/cmpbytes.c122
-rw-r--r--librols/comerr.c268
-rw-r--r--librols/default.c179
-rw-r--r--librols/error.c62
-rw-r--r--librols/fexec.c421
-rw-r--r--librols/fillbytes.c110
-rw-r--r--librols/findbytes.c164
-rw-r--r--librols/getargs.c838
-rw-r--r--librols/getav0.c155
-rw-r--r--librols/getdomainname.c115
-rw-r--r--librols/geterrno.c51
-rw-r--r--librols/gethostid.c77
-rw-r--r--librols/gethostname.c78
-rw-r--r--librols/getpagesize.c65
-rw-r--r--librols/handlecond.c287
-rw-r--r--librols/movebytes.c136
-rw-r--r--librols/raisecond.c179
-rw-r--r--librols/rename.c144
-rw-r--r--librols/saveargs.c135
-rw-r--r--librols/seterrno.c54
-rw-r--r--librols/snprintf.c102
-rw-r--r--librols/spawn.c170
-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
-rw-r--r--librols/strcatl.c74
-rw-r--r--librols/strdup.c62
-rw-r--r--librols/streql.c53
-rw-r--r--librols/swabbytes.c55
-rw-r--r--librols/usleep.c139
62 files changed, 6912 insertions, 0 deletions
diff --git a/librols/CMakeLists.txt b/librols/CMakeLists.txt
new file mode 100644
index 0000000..9aabc7c
--- /dev/null
+++ b/librols/CMakeLists.txt
@@ -0,0 +1,7 @@
+PROJECT (LIBROLS C)
+INCLUDE_DIRECTORIES(../include ../libhfs_iso ${CMAKE_BINARY_DIR} ../wodim ${CMAKE_BINARY_DIR}/include)
+
+SET(LIBROLS_SRCS astoi.c astoll.c astoull.c breakline.c cmpbytes.c comerr.c error.c fexec.c fillbytes.c getargs.c getav0.c getdomainname.c geterrno.c gethostid.c gethostname.c getpagesize.c handlecond.c movebytes.c raisecond.c rename.c saveargs.c seterrno.c spawn.c strcatl.c strdup.c streql.c swabbytes.c usleep.c stdio/cvmod.c stdio/dat.c stdio/fcons.c stdio/fdown.c stdio/fdup.c stdio/ffileread.c stdio/ffilewrite.c stdio/fgetline.c stdio/file_raise.c stdio/fileclose.c stdio/fileluopen.c stdio/filemopen.c stdio/fileopen.c stdio/filepos.c stdio/fileread.c stdio/filereopen.c stdio/fileseek.c stdio/filesize.c stdio/filestat.c stdio/filewrite.c stdio/flag.c stdio/flush.c stdio/fpipe.c stdio/niread.c stdio/niwrite.c stdio/nixread.c stdio/nixwrite.c stdio/openfd.c stdio/peekc.c default.c)
+
+ADD_LIBRARY (rols STATIC ${CMAKE_CURRENT_SOURCE_DIR}/../include/xconfig.h ${CMAKE_CURRENT_SOURCE_DIR}/../include/align.h ${LIBROLS_SRCS})
+
diff --git a/librols/astoi.c b/librols/astoi.c
new file mode 100644
index 0000000..94c14a3
--- /dev/null
+++ b/librols/astoi.c
@@ -0,0 +1,151 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)astoi.c 1.8 03/06/15 Copyright 1985, 1995-2003 J. Schilling */
+/*
+ * astoi() converts a string to int
+ * astol() converts a string to long
+ *
+ * Leading tabs and spaces are ignored.
+ * Both return pointer to the first char that has not been used.
+ * Caller must check if this means a bad conversion.
+ *
+ * leading "+" is ignored
+ * leading "0" makes conversion octal (base 8)
+ * leading "0x" makes conversion hex (base 16)
+ *
+ * Copyright (c) 1985, 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 <standard.h>
+#include <schily.h>
+
+#define is_space(c) ((c) == ' ' || (c) == '\t')
+#define is_digit(c) ((c) >= '0' && (c) <= '9')
+#define is_hex(c) (\
+ ((c) >= 'a' && (c) <= 'f') || \
+ ((c) >= 'A' && (c) <= 'F'))
+
+#define to_lower(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A'+'a' : (c))
+
+#ifdef notdef
+EXPORT int
+atoi(s)
+ char *s;
+{
+ long l;
+
+ (void) astol(s, &l);
+ return ((int) l);
+}
+
+EXPORT long
+atol(s)
+ char *s;
+{
+ long l;
+
+ (void) astol(s, &l);
+ return (l);
+}
+#endif
+
+EXPORT char *
+astoi(s, i)
+ const char *s;
+ int *i;
+{
+ long l;
+ char *ret;
+
+ ret = astol(s, &l);
+ *i = l;
+ return (ret);
+}
+
+EXPORT char *
+astol(s, l)
+ register const char *s;
+ long *l;
+{
+ return (astolb(s, l, 0));
+}
+
+EXPORT char *
+astolb(s, l, base)
+ register const char *s;
+ long *l;
+ register int base;
+{
+ int neg = 0;
+ register long ret = 0L;
+ register int digit;
+ register char c;
+
+ while (is_space(*s))
+ s++;
+
+ if (*s == '+') {
+ s++;
+ } else if (*s == '-') {
+ s++;
+ neg++;
+ }
+
+ if (base == 0) {
+ if (*s == '0') {
+ base = 8;
+ s++;
+ if (*s == 'x' || *s == 'X') {
+ s++;
+ base = 16;
+ }
+ } else {
+ base = 10;
+ }
+ }
+ for (; (c = *s) != 0; s++) {
+
+ if (is_digit(c)) {
+ digit = c - '0';
+ } else if (is_hex(c)) {
+ digit = to_lower(c) - 'a' + 10;
+ } else {
+ break;
+ }
+
+ if (digit < base) {
+ ret *= base;
+ ret += digit;
+ } else {
+ break;
+ }
+ }
+ if (neg)
+ ret = -ret;
+ *l = ret;
+ return ((char *)s);
+}
diff --git a/librols/astoll.c b/librols/astoll.c
new file mode 100644
index 0000000..1e35808
--- /dev/null
+++ b/librols/astoll.c
@@ -0,0 +1,120 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)astoll.c 1.3 03/06/15 Copyright 1985, 2000-2003 J. Schilling */
+/*
+ * astoll() converts a string to long long
+ *
+ * Leading tabs and spaces are ignored.
+ * Both return pointer to the first char that has not been used.
+ * Caller must check if this means a bad conversion.
+ *
+ * leading "+" is ignored
+ * leading "0" makes conversion octal (base 8)
+ * leading "0x" makes conversion hex (base 16)
+ *
+ * Llong is silently reverted to long if the compiler does not
+ * support long long.
+ *
+ * Copyright (c) 1985, 2000-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 <mconfig.h>
+#include <standard.h>
+#include <utypes.h>
+#include <schily.h>
+
+#define is_space(c) ((c) == ' ' || (c) == '\t')
+#define is_digit(c) ((c) >= '0' && (c) <= '9')
+#define is_hex(c) (\
+ ((c) >= 'a' && (c) <= 'f') || \
+ ((c) >= 'A' && (c) <= 'F'))
+
+#define to_lower(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A'+'a' : (c))
+
+char *
+astoll(s, l)
+ register const char *s;
+ Llong *l;
+{
+ return (astollb(s, l, 0));
+}
+
+char *
+astollb(s, l, base)
+ register const char *s;
+ Llong *l;
+ register int base;
+{
+ int neg = 0;
+ register Llong ret = (Llong)0;
+ register int digit;
+ register char c;
+
+ while (is_space(*s))
+ s++;
+
+ if (*s == '+') {
+ s++;
+ } else if (*s == '-') {
+ s++;
+ neg++;
+ }
+
+ if (base == 0) {
+ if (*s == '0') {
+ base = 8;
+ s++;
+ if (*s == 'x' || *s == 'X') {
+ s++;
+ base = 16;
+ }
+ } else {
+ base = 10;
+ }
+ }
+ for (; (c = *s) != 0; s++) {
+
+ if (is_digit(c)) {
+ digit = c - '0';
+ } else if (is_hex(c)) {
+ digit = to_lower(c) - 'a' + 10;
+ } else {
+ break;
+ }
+
+ if (digit < base) {
+ ret *= base;
+ ret += digit;
+ } else {
+ break;
+ }
+ }
+ if (neg)
+ ret = -ret;
+ *l = ret;
+ return ((char *)s);
+}
diff --git a/librols/astoull.c b/librols/astoull.c
new file mode 100644
index 0000000..6ab6920
--- /dev/null
+++ b/librols/astoull.c
@@ -0,0 +1,182 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)astoll.c 1.3 03/06/15 Copyright 1985, 2000-2005 J. Schilling */
+/*
+ * astoll() converts a string to long long
+ *
+ * Leading tabs and spaces are ignored.
+ * Both return pointer to the first char that has not been used.
+ * Caller must check if this means a bad conversion.
+ *
+ * leading "+" is ignored
+ * leading "0" makes conversion octal (base 8)
+ * leading "0x" makes conversion hex (base 16)
+ *
+ * Llong is silently reverted to long if the compiler does not
+ * support long long.
+ *
+ * Copyright (c) 1985, 2000-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 <mconfig.h>
+#include <standard.h>
+#include <utypes.h>
+#include <schily.h>
+#include <errno.h>
+#ifndef HAVE_ERRNO_DEF
+extern int errno;
+#endif
+
+#define is_space(c) ((c) == ' ' || (c) == '\t')
+#define is_digit(c) ((c) >= '0' && (c) <= '9')
+#define is_hex(c) (\
+ ((c) >= 'a' && (c) <= 'f') || \
+ ((c) >= 'A' && (c) <= 'F'))
+
+#define is_lower(c) ((c) >= 'a' && (c) <= 'z')
+#define is_upper(c) ((c) >= 'A' && (c) <= 'Z')
+#define to_lower(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A'+'a' : (c))
+
+#if ('i' + 1) < 'j'
+#define BASE_MAX ('i' - 'a' + 10 + 1) /* This is EBCDIC */
+#else
+#define BASE_MAX ('z' - 'a' + 10 + 1) /* This is ASCII */
+#endif
+
+
+
+EXPORT char *astoull __PR((const char *s, Ullong *l));
+EXPORT char *astoullb __PR((const char *s, Ullong *l, int base));
+
+EXPORT char *
+astoull(s, l)
+ register const char *s;
+ Ullong *l;
+{
+ return (astoullb(s, l, 0));
+}
+
+EXPORT char *
+astoullb(s, l, base)
+ register const char *s;
+ Ullong *l;
+ register int base;
+{
+#ifdef DO_SIGNED
+ int neg = 0;
+#endif
+ register Ullong ret = (Ullong)0;
+ Ullong maxmult;
+ register int digit;
+ register char c;
+
+ if (base > BASE_MAX || base == 1 || base < 0) {
+ errno = EINVAL;
+ return ((char *)s);
+ }
+
+ while (is_space(*s))
+ s++;
+
+ if (*s == '+') {
+ s++;
+ } else if (*s == '-') {
+#ifndef DO_SIGNED
+ errno = EINVAL;
+ return ((char *)s);
+#else
+ s++;
+ neg++;
+#endif
+ }
+
+ if (base == 0) {
+ if (*s == '0') {
+ base = 8;
+ s++;
+ if (*s == 'x' || *s == 'X') {
+ s++;
+ base = 16;
+ }
+ } else {
+ base = 10;
+ }
+ }
+ maxmult = TYPE_MAXVAL(Ullong) / base;
+ for (; (c = *s) != 0; s++) {
+
+ if (is_digit(c)) {
+ digit = c - '0';
+#ifdef OLD
+ } else if (is_hex(c)) {
+ digit = to_lower(c) - 'a' + 10;
+#else
+ } else if (is_lower(c)) {
+ digit = c - 'a' + 10;
+ } else if (is_upper(c)) {
+ digit = c - 'A' + 10;
+#endif
+ } else {
+ break;
+ }
+
+ if (digit < base) {
+ if (ret > maxmult)
+ goto overflow;
+ ret *= base;
+ if (TYPE_MAXVAL(Ullong) - ret < digit)
+ goto overflow;
+ ret += digit;
+ } else {
+ break;
+ }
+ }
+#ifdef DO_SIGNED
+ if (neg)
+ ret = -ret;
+#endif
+ *l = ret;
+ return ((char *)s);
+overflow:
+ for (; (c = *s) != 0; s++) {
+
+ if (is_digit(c)) {
+ digit = c - '0';
+ } else if (is_lower(c)) {
+ digit = c - 'a' + 10;
+ } else if (is_upper(c)) {
+ digit = c - 'A' + 10;
+ } else {
+ break;
+ }
+ if (digit >= base)
+ break;
+ }
+ *l = TYPE_MAXVAL(Ullong);
+ errno = ERANGE;
+ return ((char *)s);
+}
diff --git a/librols/breakline.c b/librols/breakline.c
new file mode 100644
index 0000000..fe0ab9a
--- /dev/null
+++ b/librols/breakline.c
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)breakline.c 1.10 04/09/25 Copyright 1985, 1995-2003 J. Schilling */
+/*
+ * break a line pointed to by *buf into fields
+ * returns the number of tokens, the line was broken into (>= 1)
+ *
+ * delim is the delimiter to break at
+ * array[0 .. found-1] point to strings from broken line
+ * array[found ... len] point to '\0'
+ * len is the size of the array
+ *
+ * Copyright (c) 1985, 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 <mconfig.h>
+#include <standard.h>
+#include <schily.h>
+
+#ifdef PROTOTYPES
+EXPORT int
+breakline(char *buf,
+ register char delim,
+ register char *array[],
+ register int len)
+#else
+EXPORT int
+breakline(buf, delim, array, len)
+ char *buf;
+ register char delim;
+ register char *array[];
+ register int len;
+#endif
+{
+ register char *bp = buf;
+ register char *dp;
+ register int i;
+ register int found;
+
+ for (i = 0, found = 1; i < len; i++) {
+ for (dp = bp; *dp != '\0' && *dp != delim; dp++)
+ /* LINTED */
+ ;
+
+ array[i] = bp;
+ if (*dp == delim) {
+ *dp++ = '\0';
+ found++;
+ }
+ bp = dp;
+ }
+ return (found);
+}
diff --git a/librols/cmpbytes.c b/librols/cmpbytes.c
new file mode 100644
index 0000000..360635f
--- /dev/null
+++ b/librols/cmpbytes.c
@@ -0,0 +1,122 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)cmpbytes.c 1.15 03/06/15 Copyright 1988, 1995-2003 J. Schilling */
+/*
+ * compare data
+ *
+ * Copyright (c) 1988, 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 <standard.h>
+#include <align.h>
+#include <schily.h>
+
+#define DO8(a) a; a; a; a; a; a; a; a;
+
+EXPORT int
+cmpbytes(fromp, top, cnt)
+ const void *fromp;
+ const void *top;
+ int cnt;
+{
+ register const char *from = (char *)fromp;
+ register const char *to = (char *)top;
+ register int n;
+ register int i;
+
+ /*
+ * If we change cnt to be unsigned, check for == instead of <=
+ */
+ if ((n = cnt) <= 0)
+ return (cnt);
+
+ /*
+ * Compare byte-wise until properly aligned for a long pointer.
+ */
+ i = sizeof (long) - 1;
+ while (--n >= 0 && --i >= 0 && !l2aligned(from, to)) {
+ if (*to++ != *from++)
+ goto cdiff;
+ }
+ n++;
+
+ if (n >= (int)(8 * sizeof (long))) {
+ if (l2aligned(from, to)) {
+ register const long *froml = (const long *)from;
+ register const long *tol = (const long *)to;
+ register int rem = n % (8 * sizeof (long));
+
+ n /= (8 * sizeof (long));
+ do {
+ DO8(
+ if (*tol++ != *froml++)
+ break;
+ );
+ } while (--n > 0);
+
+ if (n > 0) {
+ --froml;
+ --tol;
+ to = (const char *)tol;
+ from = (const char *)froml;
+ goto ldiff;
+ }
+ to = (const char *)tol;
+ from = (const char *)froml;
+ n = rem;
+ }
+
+ if (n >= 8) {
+ n -= 8;
+ do {
+ DO8(
+ if (*to++ != *from++)
+ goto cdiff;
+ );
+ } while ((n -= 8) >= 0);
+ n += 8;
+ }
+ if (n > 0) do {
+ if (*to++ != *from++)
+ goto cdiff;
+ } while (--n > 0);
+ return (cnt);
+ }
+ if (n > 0) do {
+ if (*to++ != *from++)
+ goto cdiff;
+ } while (--n > 0);
+ return (cnt);
+ldiff:
+ n = sizeof (long);
+ do {
+ if (*to++ != *from++)
+ goto cdiff;
+ } while (--n > 0);
+cdiff:
+ return (--from - (char *)fromp);
+}
diff --git a/librols/comerr.c b/librols/comerr.c
new file mode 100644
index 0000000..7100fef
--- /dev/null
+++ b/librols/comerr.c
@@ -0,0 +1,268 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)comerr.c 1.29 03/06/15 Copyright 1985-1989, 1995-2003 J. Schilling */
+/*
+ * Routines for printing command errors
+ *
+ * Copyright (c) 1985-1989, 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 <mconfig.h>
+#include <unixstd.h> /* include <sys/types.h> try to get size_t */
+#include <stdio.h> /* Try again for size_t */
+#include <stdxlib.h> /* Try again for size_t */
+#include <standard.h>
+#include <vadefs.h>
+#include <strdefs.h>
+#include <schily.h>
+#include <errno.h>
+#ifndef HAVE_STRERROR
+extern char *sys_errlist[];
+extern int sys_nerr;
+#endif
+
+EXPORT int on_comerr __PR((void (*fun)(int, void *), void *arg));
+EXPORT void comerr __PR((const char *, ...));
+EXPORT void comerrno __PR((int, const char *, ...));
+EXPORT int errmsg __PR((const char *, ...));
+EXPORT int errmsgno __PR((int, const char *, ...));
+LOCAL int _comerr __PR((int, int, const char *, va_list));
+EXPORT void comexit __PR((int));
+EXPORT char *errmsgstr __PR((int));
+
+typedef struct ex {
+ struct ex *next;
+ void (*func) __PR((int, void *));
+ void *arg;
+} ex_t;
+
+LOCAL ex_t *exfuncs;
+
+EXPORT int
+on_comerr(func, arg)
+ void (*func) __PR((int, void *));
+ void *arg;
+{
+ ex_t *fp;
+
+ fp = malloc(sizeof (*fp));
+ if (fp == NULL)
+ return (-1);
+
+ fp->func = func;
+ fp->arg = arg;
+ fp->next = exfuncs;
+ exfuncs = fp;
+ return (0);
+}
+
+/* VARARGS1 */
+#ifdef PROTOTYPES
+EXPORT void
+comerr(const char *msg, ...)
+#else
+EXPORT void
+comerr(msg, va_alist)
+ char *msg;
+ va_dcl
+#endif
+{
+ va_list args;
+
+#ifdef PROTOTYPES
+ va_start(args, msg);
+#else
+ va_start(args);
+#endif
+ (void) _comerr(TRUE, geterrno(), msg, args);
+ /* NOTREACHED */
+ va_end(args);
+}
+
+/* VARARGS2 */
+#ifdef PROTOTYPES
+EXPORT void
+comerrno(int err, const char *msg, ...)
+#else
+EXPORT void
+comerrno(err, msg, va_alist)
+ int err;
+ char *msg;
+ va_dcl
+#endif
+{
+ va_list args;
+
+#ifdef PROTOTYPES
+ va_start(args, msg);
+#else
+ va_start(args);
+#endif
+ (void) _comerr(TRUE, err, msg, args);
+ /* NOTREACHED */
+ va_end(args);
+}
+
+/* VARARGS1 */
+#ifdef PROTOTYPES
+EXPORT int
+errmsg(const char *msg, ...)
+#else
+EXPORT int
+errmsg(msg, va_alist)
+ char *msg;
+ va_dcl
+#endif
+{
+ va_list args;
+ int ret;
+
+#ifdef PROTOTYPES
+ va_start(args, msg);
+#else
+ va_start(args);
+#endif
+ ret = _comerr(FALSE, geterrno(), msg, args);
+ va_end(args);
+ return (ret);
+}
+
+/* VARARGS2 */
+#ifdef PROTOTYPES
+EXPORT int
+errmsgno(int err, const char *msg, ...)
+#else
+EXPORT int
+errmsgno(err, msg, va_alist)
+ int err;
+ char *msg;
+ va_dcl
+#endif
+{
+ va_list args;
+ int ret;
+
+#ifdef PROTOTYPES
+ va_start(args, msg);
+#else
+ va_start(args);
+#endif
+ ret = _comerr(FALSE, err, msg, args);
+ va_end(args);
+ return (ret);
+}
+
+#ifdef __BEOS__
+ /*
+ * On BeOS errno is a big negative number (0x80000000 + small number).
+ * We assume that small negative numbers are safe to be used as special
+ * values that prevent printing the errno text.
+ *
+ * We tried to use #if EIO < 0 but this does not work because EIO is
+ * defined to a enum. ENODEV may work as ENODEV is defined to a number
+ * directly.
+ */
+#define silent_schily_error(e) ((e) < 0 && (e) >= -1024)
+#else
+ /*
+ * On UNIX errno is a small non-negative number, so we assume that
+ * negative values cannot be a valid errno and don't print the error
+ * string in this case. However the value may still be used as exit()
+ * code if 'exflg' is set.
+ */
+#define silent_schily_error(e) ((e) < 0)
+#endif
+LOCAL int
+_comerr(exflg, err, msg, args)
+ int exflg;
+ int err;
+ const char *msg;
+ va_list args;
+{
+ char errbuf[20];
+ char *errnam;
+ char *prognam = get_progname();
+
+ if (silent_schily_error(err)) {
+ fprintf(stderr, "%s: ", prognam);
+ vfprintf(stderr, msg, args);
+ } else {
+ errnam = errmsgstr(err);
+ if (errnam == NULL) {
+ (void) snprintf(errbuf, sizeof (errbuf),
+ "Error %d", err);
+ errnam = errbuf;
+ }
+ fprintf(stderr, "%s: %s. ", prognam, errnam);
+ vfprintf(stderr, msg, args);
+ }
+ if (exflg) {
+ comexit(err);
+ /* NOTREACHED */
+ }
+ return (err);
+}
+
+EXPORT void
+comexit(err)
+ int err;
+{
+ while (exfuncs) {
+ (*exfuncs->func)(err, exfuncs->arg);
+ exfuncs = exfuncs->next;
+ }
+ exit(err);
+ /* NOTREACHED */
+}
+
+EXPORT char *
+errmsgstr(err)
+ int err;
+{
+#ifdef HAVE_STRERROR
+ /*
+ * POSIX compliance may look strange...
+ */
+ int errsav = geterrno();
+ char *ret;
+
+ seterrno(0);
+ ret = strerror(err);
+ err = geterrno();
+ seterrno(errsav);
+
+ if (ret == NULL || err)
+ return (NULL);
+ return (ret);
+#else
+ if (err < 0 || err >= sys_nerr) {
+ return (NULL);
+ } else {
+ return (sys_errlist[err]);
+ }
+#endif
+}
diff --git a/librols/default.c b/librols/default.c
new file mode 100644
index 0000000..10878c3
--- /dev/null
+++ b/librols/default.c
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2006 Eduard Bloch
+ *
+ * Uses my config parser code and small wrappers to provide the old interface.
+ *
+ */
+/*
+ * 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 <mconfig.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+
+enum parstate {
+ KEYBEGINSEARCH,
+ KEYCOMPARE,
+ EQSIGNSEARCH,
+ VALBEGINSEARCH,
+ LASTCHARSEARCH
+};
+
+#define GETVAL_BUF_LEN 512
+#define isUspace(x) isspace( (int) (unsigned char) x)
+
+static FILE *glob_cfg_ptr = NULL;
+
+/*
+ * Warning, uses static line buffer, not reentrant. NULL returned if the key isn't found.
+ */
+static char *get_value(FILE *srcfile, const char *key, int dorewind) {
+ static char linebuf[GETVAL_BUF_LEN];
+
+ if(!srcfile)
+ return ((char *) NULL);
+
+ if(dorewind)
+ rewind(srcfile);
+
+ if(!key)
+ return NULL;
+
+next_line:
+ while(fgets(linebuf, sizeof(linebuf)-1, srcfile)) {
+ int i;
+ int keybeg=0;
+ int s=KEYBEGINSEARCH;
+ char *ret=NULL;
+ int lastchar=0;
+
+ /* simple state machine, char position moved by the states (or not),
+ * state change is done by the state (or not) */
+ for( i=0 ; i<sizeof(linebuf) ; ) {
+ /* printf("key: %s, %s, s: %d\n", key, linebuf, s); */
+ switch(s) {
+ case(KEYBEGINSEARCH):
+ {
+ if(isUspace(linebuf[i]))
+ i++;
+ else if(linebuf[i] == '#' || linebuf[i]=='\0')
+ goto next_line;
+ else {
+ s=KEYCOMPARE;
+ keybeg=i;
+ }
+ }
+ break;
+ case(KEYCOMPARE): /* compare the key */
+ {
+ if(key[i-keybeg]=='\0')
+ /* end of key, next state decides what to do on this position */
+ s=EQSIGNSEARCH;
+ else {
+ if(linebuf[i-keybeg]!=key[i-keybeg])
+ goto next_line;
+ else
+ i++;
+ }
+ }
+ break;
+ case(EQSIGNSEARCH): /* skip whitespace, stop on =, break on anything else */
+ {
+ if(isUspace(linebuf[i]))
+ i++;
+ else if(linebuf[i]=='=') {
+ s=VALBEGINSEARCH;
+ i++;
+ }
+ else
+ goto next_line;
+ }
+ break;
+ case(VALBEGINSEARCH):
+ {
+ if(isUspace(linebuf[i]))
+ i++;
+ else {
+ /* possible at EOF */
+ if(linebuf[i] == '\0')
+ return NULL;
+
+ lastchar=i-1; /* lastchar can be a space, see below */
+ ret= & linebuf[i];
+ s=LASTCHARSEARCH;
+ }
+ }
+ break;
+ case(LASTCHARSEARCH):
+ {
+ if(linebuf[i]) {
+ if(!isUspace(linebuf[i]))
+ lastchar=i;
+ }
+ else { /* got string end, terminate after the last seen char */
+ if(linebuf+lastchar < ret) /* no non-space found */
+ return NULL;
+ linebuf[lastchar+1]='\0';
+ return ret;
+ }
+ i++;
+ }
+ break;
+ }
+ }
+ }
+ return NULL;
+}
+
+int cfg_open(const char *name)
+{
+ if(glob_cfg_ptr) {
+ fclose(glob_cfg_ptr);
+ glob_cfg_ptr=NULL;
+ }
+ if(!name) {
+ glob_cfg_ptr=NULL;
+ return 0;
+ }
+ glob_cfg_ptr = fopen(name, "r");
+ return (glob_cfg_ptr ? 0 : -1);
+}
+
+int cfg_close()
+{
+ int r;
+ if(!glob_cfg_ptr)
+ return 0;
+ r=fclose(glob_cfg_ptr);
+ glob_cfg_ptr=NULL;
+ return r;
+}
+
+void cfg_restart()
+{
+ get_value(glob_cfg_ptr, NULL, 1);
+}
+
+char *cfg_get(const char *key)
+{
+ return get_value(glob_cfg_ptr, key, 1);
+}
+
+char *cfg_get_next(const char *key)
+{
+ return get_value(glob_cfg_ptr, key, 0);
+}
diff --git a/librols/error.c b/librols/error.c
new file mode 100644
index 0000000..d0f1e12
--- /dev/null
+++ b/librols/error.c
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)error.c 1.13 03/06/15 Copyright 1985, 1989, 1995-2003 J. Schilling */
+/*
+ * fprintf() on standard error stdio stream
+ *
+ * Copyright (c) 1985, 1989, 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 <mconfig.h>
+#include <stdio.h>
+#include <standard.h>
+#include <vadefs.h>
+#include <schily.h>
+
+/* VARARGS1 */
+#ifdef PROTOTYPES
+EXPORT int
+schily_error(const char *fmt, ...)
+#else
+EXPORT int
+schily_error(fmt, va_alist)
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list args;
+ int ret;
+
+#ifdef PROTOTYPES
+ va_start(args, fmt);
+#else
+ va_start(args);
+#endif
+ ret = vfprintf(stderr, fmt, args);
+ va_end(args);
+ return (ret);
+}
diff --git a/librols/fexec.c b/librols/fexec.c
new file mode 100644
index 0000000..9136402
--- /dev/null
+++ b/librols/fexec.c
@@ -0,0 +1,421 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)fexec.c 1.24 04/06/06 Copyright 1985, 1995-2004 J. Schilling */
+/*
+ * Execute a program with stdio redirection
+ *
+ * Copyright (c) 1985, 1995-2004 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 <mconfig.h>
+#include <stdio.h>
+#include <standard.h>
+#define rols_fexecl __nothing_1_ /* prototype in schily.h is wrong */
+#define rols_fexecle __nothing_2_ /* prototype in schily.h is wrong */
+#include <schily.h>
+#undef rols_fexecl
+#undef rols_fexecle
+ int rols_fexecl __PR((const char *, FILE *, FILE *, FILE *, ...));
+ int rols_fexecle __PR((const char *, FILE *, FILE *, FILE *, ...));
+#include <unixstd.h>
+#include <stdxlib.h>
+#include <strdefs.h>
+#include <vadefs.h>
+
+#ifdef JOS
+# include <error.h>
+#else
+# include <errno.h>
+#endif
+#include <fctldefs.h>
+#include <dirdefs.h>
+#include <maxpath.h>
+
+#define MAX_F_ARGS 16
+
+extern char **environ;
+
+LOCAL void fdcopy __PR((int, int));
+LOCAL void fdmove __PR((int, int));
+LOCAL const char *chkname __PR((const char *, const char *));
+LOCAL const char *getpath __PR((char * const *));
+
+#ifdef PROTOTYPES
+EXPORT int
+rols_fexecl(const char *name, FILE *in, FILE *out, FILE *err, ...)
+#else
+EXPORT int
+rols_fexecl(name, in, out, err, va_alist)
+ char *name;
+ FILE *in;
+ FILE *out;
+ FILE *err;
+ va_dcl
+#endif
+{
+ va_list args;
+ int ac = 0;
+ char *xav[MAX_F_ARGS];
+ char **av;
+ char **pav;
+ char *p;
+ int ret;
+
+#ifdef PROTOTYPES
+ va_start(args, err);
+#else
+ va_start(args);
+#endif
+ while (va_arg(args, char *) != NULL)
+ ac++;
+ va_end(args);
+
+ if (ac < MAX_F_ARGS) {
+ pav = av = xav;
+ } else {
+ pav = av = (char **)malloc((ac+1)*sizeof (char *));
+ if (av == 0)
+ return (-1);
+ }
+
+#ifdef PROTOTYPES
+ va_start(args, err);
+#else
+ va_start(args);
+#endif
+ do {
+ p = va_arg(args, char *);
+ *pav++ = p;
+ } while (p != NULL);
+ va_end(args);
+
+ ret = rols_fexecv(name, in, out, err, ac, av);
+ if (av != xav)
+ free(av);
+ return (ret);
+}
+
+#ifdef PROTOTYPES
+EXPORT int
+rols_fexecle(const char *name, FILE *in, FILE *out, FILE *err, ...)
+#else
+EXPORT int
+rols_fexecle(name, in, out, err, va_alist)
+ char *name;
+ FILE *in;
+ FILE *out;
+ FILE *err;
+ va_dcl
+#endif
+{
+ va_list args;
+ int ac = 0;
+ char *xav[MAX_F_ARGS];
+ char **av;
+ char **pav;
+ char *p;
+ char **env;
+ int ret;
+
+#ifdef PROTOTYPES
+ va_start(args, err);
+#else
+ va_start(args);
+#endif
+ while (va_arg(args, char *) != NULL)
+ ac++;
+ env = va_arg(args, char **);
+ va_end(args);
+
+ if (ac < MAX_F_ARGS) {
+ pav = av = xav;
+ } else {
+ pav = av = (char **)malloc((ac+1)*sizeof (char *));
+ if (av == 0)
+ return (-1);
+ }
+
+#ifdef PROTOTYPES
+ va_start(args, err);
+#else
+ va_start(args);
+#endif
+ do {
+ p = va_arg(args, char *);
+ *pav++ = p;
+ } while (p != NULL);
+ va_end(args);
+
+ ret = rols_fexecve(name, in, out, err, av, env);
+ if (av != xav)
+ free(av);
+ return (ret);
+}
+
+EXPORT int
+rols_fexecv(name, in, out, err, ac, av)
+ const char *name;
+ FILE *in, *out, *err;
+ int ac;
+ char *av[];
+{
+ av[ac] = NULL; /* force list to be null terminated */
+ return (rols_fexecve(name, in, out, err, av, environ));
+}
+
+EXPORT int
+rols_fexecve(name, in, out, err, av, env)
+ const char *name;
+ FILE *in, *out, *err;
+ char * const av[], * const env[];
+{
+ char nbuf[MAXPATHNAME+1];
+ char *np;
+ const char *path;
+ int ret;
+ int fin;
+ int fout;
+ int ferr;
+#ifndef JOS
+ int o[3];
+ int f[3];
+ int errsav;
+
+ o[0] = o[1] = o[2] = f[0] = f[1] = f[2] = 0;
+#endif
+
+ fflush(out);
+ fflush(err);
+ fin = fdown(in);
+ fout = fdown(out);
+ ferr = fdown(err);
+#ifdef JOS
+
+ /*
+ * If name contains a pathdelimiter ('/' on unix)
+ * or name is too long ...
+ * try exec without path search.
+ */
+ if (find('/', name) || strlen(name) > MAXFILENAME) {
+ ret = exec_env(name, fin, fout, ferr, av, env);
+
+ } else if ((path = getpath(env)) == NULL) {
+ ret = exec_env(name, fin, fout, ferr, av, env);
+ if ((ret == ENOFILE) && strlen(name) <= (sizeof (nbuf) - 6)) {
+ strcatl(nbuf, "/bin/", name, (char *)NULL);
+ ret = exec_env(nbuf, fin, fout, ferr, av, env);
+ if (ret == EMISSDIR)
+ ret = ENOFILE;
+ }
+ } else {
+ int nlen = strlen(name);
+
+ for (;;) {
+ np = nbuf;
+ /*
+ * JOS always uses ':' as PATH Environ separator
+ */
+ while (*path != ':' && *path != '\0' &&
+ np < &nbuf[MAXPATHNAME-nlen-2]) {
+
+ *np++ = *path++;
+ }
+ *np = '\0';
+ if (*nbuf == '\0')
+ strcatl(nbuf, name, (char *)NULL);
+ else
+ strcatl(nbuf, nbuf, "/", name, (char *)NULL);
+ ret = exec_env(nbuf, fin, fout, ferr, av, env);
+ if (ret == EMISSDIR)
+ ret = ENOFILE;
+ if (ret != ENOFILE || *path == '\0')
+ break;
+ path++;
+ }
+ }
+ return (ret);
+
+#else /* JOS */
+
+ if (fin != 0) {
+ f[0] = fcntl(0, F_GETFD, 0);
+ o[0] = dup(0);
+ fcntl(o[0], F_SETFD, 1);
+ fdcopy(fin, 0);
+ }
+ if (fout != 1) {
+ f[1] = fcntl(1, F_GETFD, 0);
+ o[1] = dup(1);
+ fcntl(o[1], F_SETFD, 1);
+ fdcopy(fout, 1);
+ }
+ if (ferr != 2) {
+ f[2] = fcntl(2, F_GETFD, 0);
+ o[2] = dup(2);
+ fcntl(o[2], F_SETFD, 1);
+ fdcopy(ferr, 2);
+ }
+ if (fin != 0)
+ close(fin);
+ if (fout != 1)
+ close(fout);
+ if (ferr != 2)
+ close(ferr);
+
+ /*
+ * If name contains a pathdelimiter ('/' on unix)
+ * or name is too long ...
+ * try exec without path search.
+ */
+#ifdef FOUND_MAXFILENAME
+ if (strchr(name, '/') || strlen(name) > (unsigned)MAXFILENAME) {
+#else
+ if (strchr(name, '/')) {
+#endif
+ ret = execve(name, av, env);
+
+ } else if ((path = getpath(env)) == NULL) {
+ ret = execve(name, av, env);
+ if ((geterrno() == ENOENT) && strlen(name) <= (sizeof (nbuf) - 6)) {
+ strcatl(nbuf, "/bin/", name, (char *)NULL);
+ ret = execve(nbuf, av, env);
+ }
+ } else {
+ int nlen = strlen(name);
+
+ for (;;) {
+ np = nbuf;
+ while (*path != PATH_ENV_DELIM && *path != '\0' &&
+ np < &nbuf[MAXPATHNAME-nlen-2]) {
+
+ *np++ = *path++;
+ }
+ *np = '\0';
+ if (*nbuf == '\0')
+ strcatl(nbuf, name, (char *)NULL);
+ else
+ strcatl(nbuf, nbuf, "/", name, (char *)NULL);
+ ret = execve(nbuf, av, env);
+ if (geterrno() != ENOENT || *path == '\0')
+ break;
+ path++;
+ }
+ }
+ errsav = geterrno();
+ /* reestablish old files */
+ if (ferr != 2) {
+ fdmove(2, ferr);
+ fdmove(o[2], 2);
+ if (f[2] == 0)
+ fcntl(2, F_SETFD, 0);
+ }
+ if (fout != 1) {
+ fdmove(1, fout);
+ fdmove(o[1], 1);
+ if (f[1] == 0)
+ fcntl(1, F_SETFD, 0);
+ }
+ if (fin != 0) {
+ fdmove(0, fin);
+ fdmove(o[0], 0);
+ if (f[0] == 0)
+ fcntl(0, F_SETFD, 0);
+ }
+ seterrno(errsav);
+ return (ret);
+
+#endif /* JOS */
+}
+
+#ifndef JOS
+
+LOCAL void
+fdcopy(fd1, fd2)
+ int fd1;
+ int fd2;
+{
+ close(fd2);
+ fcntl(fd1, F_DUPFD, fd2);
+}
+
+LOCAL void
+fdmove(fd1, fd2)
+ int fd1;
+ int fd2;
+{
+ fdcopy(fd1, fd2);
+ close(fd1);
+}
+
+#endif
+
+/*----------------------------------------------------------------------------
+|
+| get PATH from env
+|
++----------------------------------------------------------------------------*/
+
+LOCAL const char *
+getpath(env)
+ char * const *env;
+{
+ char * const *p = env;
+ const char *p2;
+
+ if (p != NULL) {
+ while (*p != NULL) {
+ if ((p2 = chkname("PATH", *p)) != NULL)
+ return (p2);
+ p++;
+ }
+ }
+ return (NULL);
+}
+
+
+/*----------------------------------------------------------------------------
+|
+| Check if name is in environment.
+| Return pointer to value name is found.
+|
++----------------------------------------------------------------------------*/
+
+LOCAL const char *
+chkname(name, ev)
+ const char *name;
+ const char *ev;
+{
+ for (;;) {
+ if (*name != *ev) {
+ if (*ev == '=' && *name == '\0')
+ return (++ev);
+ return (NULL);
+ }
+ name++;
+ ev++;
+ }
+}
diff --git a/librols/fillbytes.c b/librols/fillbytes.c
new file mode 100644
index 0000000..8d500e9
--- /dev/null
+++ b/librols/fillbytes.c
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)fillbytes.c 1.13 03/06/15 Copyright 1987, 1995-2003 J. Schilling */
+/*
+ * fill memory with data
+ *
+ * Copyright (c) 1987, 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 <standard.h>
+#include <align.h>
+#include <schily.h>
+
+#define DO8(a) a; a; a; a; a; a; a; a;
+
+#define cval ((char) lval)
+
+#ifdef PROTOTYPES
+EXPORT char *
+fillbytes(void *tov, int cnt, char val)
+#else
+EXPORT char *
+fillbytes(tov, cnt, val)
+ void *tov;
+ int cnt;
+ char val;
+#endif
+{
+ register char *to = (char *)tov;
+ register int n;
+ register long lval;
+
+ /*
+ * If we change cnt to be unsigned, check for == instead of <=
+ */
+ if ((n = cnt) <= 0)
+ return (to);
+
+ lval = val & 0xFF;
+
+ /*
+ * Assign byte-wise until properly aligned for a long pointer.
+ */
+ while (--n >= 0 && !laligned(to)) {
+ *to++ = cval;
+ }
+ n++;
+
+ if (n >= (int)(8 * sizeof (long))) {
+ register int rem = n % (8 * sizeof (long));
+
+ lval |= (lval<<8);
+ lval |= (lval<<16);
+#if SIZE_LONG > SIZE_INT
+ lval |= (lval<<32);
+#endif
+
+ n /= (8 * sizeof (long));
+ {
+ register long *tol = (long *)to;
+
+ do {
+ DO8 (*tol++ = lval);
+ } while (--n > 0);
+
+ to = (char *)tol;
+ }
+ n = rem;
+
+ if (n >= 8) {
+ n -= 8;
+ do {
+ DO8 (*to++ = cval);
+ } while ((n -= 8) >= 0);
+ n += 8;
+ }
+ if (n > 0) do {
+ *to++ = cval;
+ } while (--n > 0);
+ return (to);
+ }
+ if (n > 0) do {
+ *to++ = cval;
+ } while (--n > 0);
+ return (to);
+}
diff --git a/librols/findbytes.c b/librols/findbytes.c
new file mode 100644
index 0000000..0b56597
--- /dev/null
+++ b/librols/findbytes.c
@@ -0,0 +1,164 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)findbytes.c 1.2 03/06/15 Copyright 2000-2003 J. Schilling */
+/*
+ * Find a byte with specific value in memory.
+ *
+ * Copyright (c) 2000-2003 J. Schilling
+ *
+ * Based on a strlen() idea from Torbjorn Granlund (tege@sics.se) and
+ * Dan Sahlin (dan@sics.se) and the memchr() suggestion
+ * from Dick Karpinski (dick@cca.ucsf.edu).
+ */
+/*
+ * 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 <mconfig.h>
+#include <stdxlib.h>
+#include <utypes.h>
+#include <align.h>
+#include <standard.h>
+#include <strdefs.h>
+#include <schily.h>
+
+#ifdef PROTOTYPES
+EXPORT char *
+findbytes(const void *vp, int cnt, char val)
+#else
+EXPORT char *
+findbytes(vp, cnt, val)
+ const void *vp;
+ register int cnt;
+ char val;
+#endif
+{
+ register Uchar uval = (Uchar)val;
+ register const Uchar *cp = (Uchar *)vp;
+ register const Ulong *lp;
+ register Ulong lval;
+ register Ulong lmask;
+ register Ulong magic_mask;
+
+ /*
+ * Test byte-wise until cp is properly aligned for a long pointer.
+ */
+ while (--cnt >= 0 && !laligned(cp)) {
+ if (*cp++ == uval)
+ return ((char *)--cp);
+ }
+ cnt++;
+
+ /*
+ * The magic mask is a long word where all carry bits a clear.
+ * This are bits 8, 16, 24 ...
+ * In addition, the top bit is not set (e.g bit 31 or 63). The magic
+ * mask will look this way:
+ *
+ * bits: 01111110 11111110 ... 11111110 11111111
+ * bytes: AAAAAAAA BBBBBBBB ... CCCCCCCC DDDDDDDD
+ *
+ * If we add anything to this magic number, no carry bit will change if
+ * it is the first carry bit left to a 0 byte. Adding anything != 0
+ * to the magic number will just turn the carry bit left to the byte
+ * but does not propagate any further.
+ */
+#if SIZE_LONG == 4
+ magic_mask = 0x7EFEFEFFL;
+#else
+#if SIZE_LONG == 8
+ magic_mask = 0x7EFEFEFEFEFEFEFFL;
+#else
+ /*
+ * #error will not work for all compilers (e.g. sunos4)
+ * The following line will abort compilation on all compilers
+ * if none of the above is defines. And that's what we want.
+ */
+ error SIZE_LONG has unknown value
+#endif
+#endif
+
+ lmask = val & 0xFF;
+ lmask |= lmask << 8;
+ lmask |= lmask << 16;
+#if SIZE_LONG > 4
+ lmask |= lmask << 32;
+#endif
+#if SIZE_LONG > 8
+ error SIZE_LONG has unknown value
+#endif
+ for (lp = (const Ulong *)cp; cnt >= sizeof (long); cnt -= sizeof (long)) {
+ /*
+ * We are not looking for 0 bytes so we need to xor with the
+ * long mask of repeated bytes. If any of the bytes matches our
+ * wanted char, we will create a 0 byte in the current long.
+ * But how will we find if at least one byte in a long is zero?
+ *
+ * If we add 'magic_mask' and any of the holes in the magic
+ * mask do not change, we most likely found a 0 byte in the
+ * long word. It is only a most likely match because if bits
+ * 24..30 (ot bits 56..62) are 0 but bit 31 (or bit 63) is set
+ * we will believe that we found a match but there is none.
+ * This will happen if there is 0x80nnnnnn / 0x80nnnnnnnnnnnnnn
+ */
+ lval = (*lp++ ^ lmask); /* create 0 byte on match */
+ lval = (lval + magic_mask) ^ ~lval; /* set bits unchanged by +*/
+ if ((lval & ~magic_mask) != 0) { /* a magic hole was set */
+ /*
+ * If any of the hole bits did not change by addition,
+ * we most likely had a match.
+ * If this was a correct match, find the matching byte.
+ */
+ cp = (const Uchar *)(lp - 1);
+
+ if (cp[0] == uval)
+ return ((char *)cp);
+ if (cp[1] == uval)
+ return ((char *)&cp[1]);
+ if (cp[2] == uval)
+ return ((char *)&cp[2]);
+ if (cp[3] == uval)
+ return ((char *)&cp[3]);
+#if SIZE_LONG > 4
+ if (cp[4] == uval)
+ return ((char *)&cp[4]);
+ if (cp[5] == uval)
+ return ((char *)&cp[5]);
+ if (cp[6] == uval)
+ return ((char *)&cp[6]);
+ if (cp[7] == uval)
+ return ((char *)&cp[7]);
+#endif
+#if SIZE_LONG > 8
+ error SIZE_LONG has unknown value
+#endif
+ }
+ }
+
+ for (cp = (const Uchar *)lp; --cnt >= 0; ) {
+ if (*cp++ == uval)
+ return ((char *)--cp);
+ }
+ return ((char *)NULL);
+}
diff --git a/librols/getargs.c b/librols/getargs.c
new file mode 100644
index 0000000..76f1a88
--- /dev/null
+++ b/librols/getargs.c
@@ -0,0 +1,838 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)getargs.c 2.37 04/09/25 Copyright 1985, 1988, 1994-2003 J. Schilling */
+#define NEW
+/*
+ * Copyright (c) 1985, 1988, 1994-2003 J. Schilling
+ *
+ * 1.3.88 Start implementation of release 2
+ */
+/*
+ * Parse arguments on a command line.
+ * Format string type specifier (appearing directly after flag name):
+ * '' BOOL
+ * '!' BOOL with size modifier +++ NEU +++ (XXX nicht fertig)
+ * '*' string
+ * '?' char
+ * '#' number
+ * '&' call function
+ * '+' inctype +++ NEU +++
+ *
+ * The '#' and '+' types may have size modifiers added:
+ * 'c'/'C' char
+ * 's'/'S' short
+ * 'i'/'I' int (default)
+ * 'l'/'L' long
+ * 'll'/'LL' long long
+ *
+ * The format string 'f* ' may be used to disallow -ffoo for f*
+ *
+ * XXX This is currently only implemented for the '*' format
+ */
+/*
+ * 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.
+ */
+/* LINTLIBRARY */
+#include <mconfig.h>
+#include <standard.h>
+#include <utypes.h>
+#include <getargs.h>
+#include <vadefs.h>
+#include <strdefs.h>
+#include <schily.h>
+#include <ctype.h>
+
+#define NOARGS 0 /* No more args */
+#define NOTAFLAG 1 /* Not a flag type argument */
+#define BADFLAG (-1) /* Not a valid flag argument */
+#define BADFMT (-2) /* Error in format string */
+#define NOTAFILE (-3) /* Seems to be a flag type arg */
+
+
+ int _getargs __PR((int *, char *const **, const char *,
+ BOOL, va_list));
+LOCAL int dofile __PR((int *, char *const **, const char **));
+LOCAL int doflag __PR((int *, char *const **, const char *,
+ const char *, BOOL, va_list));
+LOCAL int dosflags __PR((const char *, const char *, BOOL, va_list));
+LOCAL int checkfmt __PR((const char *));
+LOCAL int checkeql __PR((const char *));
+
+LOCAL va_list va_dummy;
+
+LOCAL char fmtspecs[] = "#?*&+";
+/*LOCAL char fmtspecs[] = "#?*&+!";*/
+
+#define isfmtspec(c) (strchr(fmtspecs, c) != NULL)
+
+/*---------------------------------------------------------------------------
+|
+| get flags until a non flag type argument is reached
+|
++---------------------------------------------------------------------------*/
+/* VARARGS3 */
+#ifdef PROTOTYPES
+EXPORT int
+getargs(int *pac, char *const **pav, const char *fmt, ...)
+#else
+EXPORT int
+getargs(pac, pav, fmt, va_alist)
+ int *pac;
+ char **pav[];
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list args;
+ int ret;
+
+#ifdef PROTOTYPES
+ va_start(args, fmt);
+#else
+ va_start(args);
+#endif
+ ret = _getargs(pac, pav, fmt, TRUE, args);
+ va_end(args);
+ return (ret);
+}
+
+
+/*---------------------------------------------------------------------------
+|
+| get all flags on the command line, do not stop on files
+|
++---------------------------------------------------------------------------*/
+/* VARARGS3 */
+#ifdef PROTOTYPES
+EXPORT int
+getallargs(int *pac, char *const **pav, const char *fmt, ...)
+#else
+EXPORT int
+getallargs(pac, pav, fmt, va_alist)
+ int *pac;
+ char **pav[];
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list args;
+ int ret;
+
+#ifdef PROTOTYPES
+ va_start(args, fmt);
+#else
+ va_start(args);
+#endif
+ for (; ; (*pac)--, (*pav)++) {
+ if ((ret = _getargs(pac, pav, fmt, TRUE, args)) != NOTAFLAG)
+ break;
+ }
+ va_end(args);
+ return (ret);
+}
+
+
+/*---------------------------------------------------------------------------
+|
+| get next non flag type argument (i.e. a file)
+|
++---------------------------------------------------------------------------*/
+EXPORT int
+getfiles(pac, pav, fmt)
+ int *pac;
+ char *const *pav[];
+ const char *fmt;
+{
+ return (_getargs(pac, pav, fmt, FALSE, va_dummy));
+}
+
+
+/*---------------------------------------------------------------------------
+|
+| check args until the next non flag type argmument is reached
+| *pac is decremented, *pav is incremented so that the
+| non flag type argument is at *pav[0]
+|
+| return code:
+| NOARGS no more args
+| NOTAFLAG not a flag type argument
+| BADFLAG a non-matching flag type argument
+| BADFMT bad syntax in format string
+|
+|
++---------------------------------------------------------------------------*/
+/*LOCAL*/ int
+_getargs(pac, pav, fmt, setargs, args)
+ register int *pac;
+ register char *const **pav;
+ const char *fmt;
+ BOOL setargs;
+ va_list args;
+{
+ const char *argp;
+ int ret;
+
+
+ for (; *pac > 0; (*pac)--, (*pav)++) {
+ argp = **pav;
+
+ ret = dofile(pac, pav, &argp);
+
+ if (ret != NOTAFILE)
+ return (ret);
+
+ ret = doflag(pac, pav, argp, fmt, setargs, args);
+
+ if (ret != NOTAFLAG)
+ return (ret);
+ }
+ return (NOARGS);
+}
+
+
+/*---------------------------------------------------------------------------
+|
+| check if *pargp is a file type argument
+|
++---------------------------------------------------------------------------*/
+LOCAL int
+dofile(pac, pav, pargp)
+ register int *pac;
+ register char *const **pav;
+ const char **pargp;
+{
+ register const char *argp = *pargp;
+
+
+ if (argp[0] == '-') {
+ /*
+ * "-" is a special non flag type argument
+ * that usually means take stdin instead of a named file
+ */
+ if (argp[1] == '\0')
+ return (NOTAFLAG);
+ /*
+ * "--" is a prefix to take the next argument
+ * as non flag type argument
+ * NOTE: Posix requires "--" to indicate the end of the
+ * flags on the command line. But we are currently not
+ * Posix.
+ */
+ if (argp[1] == '-' && argp[2] == '\0') {
+ if (--(*pac) > 0) {
+ (*pav)++;
+ return (NOTAFLAG);
+ } else {
+ return (NOARGS);
+ }
+ }
+ }
+
+ /*
+ * now check if it may be flag type argument
+ * flag type arguments begin with a '-', a '+' or contain a '='
+ * i.e. -flag +flag or flag=
+ */
+ if (argp[0] != '-' && argp[0] != '+' && (!checkeql(argp)))
+ return (NOTAFLAG);
+
+ return (NOTAFILE);
+}
+
+
+/*---------------------------------------------------------------------------
+|
+| compare argp with the format string
+| if a match is found store the result a la scanf in one of the
+| arguments pointed to in the va_list
+|
+| If setargs is FALSE, only check arguments for getfiles()
+| in this case, va_list may be a dummy arg.
+|
++---------------------------------------------------------------------------*/
+LOCAL int
+doflag(pac, pav, argp, fmt, setargs, oargs)
+ int *pac;
+ char *const **pav;
+ register const char *argp;
+ register const char *fmt;
+ BOOL setargs;
+ va_list oargs;
+{
+ char argstr[2];
+ long val;
+ Llong llval;
+ int singlecharflag = 0;
+ BOOL isspec;
+ BOOL hasdash = FALSE;
+ BOOL doubledash = FALSE;
+ BOOL haseql = checkeql(argp);
+ const char *sargp;
+ const char *sfmt = fmt;
+ va_list args;
+ char *const *spav = *pav;
+ int spac = *pac;
+ void *curarg = (void *)0;
+
+ /*
+ * flags beginning with '-' don't have to include the '-' in
+ * the format string.
+ * flags beginning with '+' have to include it in the format string.
+ */
+ if (argp[0] == '-') {
+ argp++;
+ hasdash = TRUE;
+ /*
+ * Implement legacy support for --longopt
+ * If we find a double dash, we do not look for combinations
+ * of boolean single char flags.
+ */
+ if (argp[0] == '-') {
+ argp++;
+ doubledash = TRUE;
+ /*
+ * Allow -- only for long options.
+ */
+ if (argp[1] == '\0') {
+ return (BADFLAG);
+ }
+ }
+ }
+ sargp = argp;
+
+ /*
+ * Initialize 'args' to the start of the argument list.
+ * I don't know any portable way to copy an arbitrary
+ * C object so I use a system-specific routine
+ * (probably a macro) from stdarg.h. (Remember that
+ * if va_list is an array, 'args' will be a pointer
+ * and '&args' won't be what I would need for memcpy.)
+ * It is a system requirement for SVr4 compatibility
+ * to be able to do this assgignement. If your system
+ * defines va_list to be an array but does not define
+ * va_copy() you are lost.
+ * This is needed to make sure, that 'oargs' will not
+ * be clobbered.
+ */
+ va_copy(args, oargs);
+
+ if (setargs)
+ curarg = va_arg(args, void *);
+
+ /*
+ * check if the first flag in format string is a singlechar flag
+ */
+ if (fmt[1] == ',' || fmt[1] == '+' || fmt[1] == '\0')
+ singlecharflag++;
+ /*
+ * check the whole format string for a match
+ */
+ for (;;) {
+ for (; *fmt; fmt++, argp++) {
+ if (*fmt == '\\') {
+ /*
+ * Allow "#?*&+" to appear inside a flag.
+ * NOTE: they must be escaped by '\\' only
+ * inside the the format string.
+ */
+ fmt++;
+ isspec = FALSE;
+ } else {
+ isspec = isfmtspec(*fmt);
+ }
+ /*
+ * If isspec is TRUE, the arg beeing checked starts
+ * like a valid flag. Argp now points to the rest.
+ */
+ if (isspec) {
+ /*
+ * If *argp is '+' and we are on the
+ * beginning of the arg that is currently
+ * checked, this cannot be an inc type flag.
+ */
+ if (*argp == '+' && argp == sargp)
+ continue;
+ /*
+ * skip over to arg of flag
+ */
+ if (*argp == '=') {
+ argp++;
+ } else if (*argp != '\0' && haseql) {
+ /*
+ * Flag and arg are not separated by a
+ * space.
+ * Check here for:
+ * xxxxx=yyyyy match on '&'
+ * Checked before:
+ * abc=yyyyy match on 'abc&'
+ * or 'abc*'
+ * or 'abc#'
+ * We come here if 'argp' starts with
+ * the same sequence as a valid flag
+ * and contains an equal sign.
+ * We have tested before if the text
+ * before 'argp' matches exactly.
+ * At this point we have no exact match
+ * and we only allow to match
+ * the special pattern '&'.
+ * We need this e.g. for 'make'.
+ * We allow any flag type argument to
+ * match the format string "&" to set
+ * up a function that handles all odd
+ * stuff that getargs will not grok.
+ * In addition, to allow getargs to be
+ * used for CPP type flags we allow to
+ * match -Dabc=xyz on 'D&'. Note that
+ * Dabc=xyz will not match 'D&'.
+ */
+ if ((!hasdash && argp != sargp) || *fmt != '&')
+ goto nextarg;
+ }
+
+ /*
+ * The format string 'f* ' may be used
+ * to disallow -ffoo for f*
+ *
+ * XXX This is currently only implemented for
+ * XXX the '*' format
+ */
+ if (!haseql && *argp != '\0' && fmt[0] == '*' && fmt[1] == ' ')
+ goto nextarg;
+ /*
+ * *arpp == '\0' || !haseql
+ * We come here if 'argp' starts with
+ * the same sequence as a valid flag.
+ * This will match on the following args:
+ * -farg match on 'f*'
+ * -f12 match on 'f#'
+ * +12 match on '+#'
+ * -12 match on '#'
+ * and all args that are separated from
+ * their flags.
+ * In the switch statement below, we check
+ * if the text after 'argp' (if *argp != 0) or
+ * the next arg is a valid arg for this flag.
+ */
+ break;
+ } else if (*fmt == *argp) {
+ if (argp[1] == '\0' &&
+ (fmt[1] == '\0' || fmt[1] == ',')) {
+
+ if (setargs)
+ *((int *)curarg) = TRUE;
+
+
+ return (checkfmt(fmt)); /* XXX */
+ }
+ } else {
+ /*
+ * skip over to next format identifier
+ * & reset arg pointer
+ */
+ nextarg:
+ while (*fmt != ',' && *fmt != '\0') {
+ /* function has extra arg on stack */
+ if (*fmt == '&' && setargs)
+ curarg = va_arg(args, void *);
+ fmt++;
+ }
+ argp = sargp;
+ break;
+ }
+ }
+ switch (*fmt) {
+
+ case '\0':
+ /*
+ * Boolean type has been tested before.
+ */
+ if (singlecharflag && !doubledash &&
+ (val = dosflags(sargp, sfmt, setargs, oargs)) !=
+ BADFLAG)
+ return (val);
+
+
+ return (BADFLAG);
+
+ case ',':
+ fmt++;
+ if (fmt[1] == ',' || fmt[1] == '+' || fmt[1] == '\0')
+ singlecharflag++;
+ if (setargs)
+ curarg = va_arg(args, void *);
+ continue;
+
+ case '*':
+ if (*argp == '\0') {
+ if (*pac > 1) {
+ (*pac)--;
+ (*pav)++;
+ argp = **pav;
+ } else {
+ return (BADFLAG);
+ }
+ }
+ if (fmt[1] == ' ') /* To disallow -ffoo for f* */
+ fmt++;
+ if (setargs)
+ *((const char **)curarg) = argp;
+
+
+ return (checkfmt(fmt));
+
+ case '?':
+ /*
+ * If more than one char arg, it
+ * cannot be a character argument.
+ */
+ if (argp[1] != '\0')
+ goto nextchance;
+ if (setargs)
+ *((char *)curarg) = *argp;
+
+
+ return (checkfmt(fmt));
+
+ case '+':
+ /*
+ * inc type is similar to boolean,
+ * there is no arg in argp to convert.
+ */
+ if (*argp != '\0')
+ goto nextchance;
+ /*
+ * If *fmt is '+' and we are on the beginning
+ * of the format desciptor that is currently
+ * checked, this cannot be an inc type flag.
+ */
+ if (fmt == sfmt || fmt[-1] == ',')
+ goto nextchance;
+
+ if (fmt[1] == 'l' || fmt[1] == 'L') {
+ if (fmt[2] == 'l' || fmt[2] == 'L') {
+ if (setargs)
+ *((Llong *)curarg) += 1;
+ fmt += 2;
+ } else {
+ if (setargs)
+ *((long *)curarg) += 1;
+ fmt++;
+ }
+ } else if (fmt[1] == 's' || fmt[1] == 'S') {
+ if (setargs)
+ *((short *)curarg) += 1;
+ fmt++;
+ } else if (fmt[1] == 'c' || fmt[1] == 'C') {
+ if (setargs)
+ *((char *)curarg) += 1;
+ fmt++;
+ } else {
+ if (fmt[1] == 'i' || fmt[1] == 'I')
+ fmt++;
+ if (setargs)
+ *((int *)curarg) += 1;
+ }
+
+ argstr[0] = *fmt;
+ argstr[1] = '\0';
+
+ return (checkfmt(fmt));
+
+ case '#':
+ if (*argp == '\0') {
+ if (*pac > 1) {
+ (*pac)--;
+ (*pav)++;
+ argp = **pav;
+ } else {
+ return (BADFLAG);
+ }
+ }
+ if (*astoll(argp, &llval) != '\0') {
+ /*
+ * arg is not a valid number!
+ * go to next format in the format string
+ * and check if arg matches any other type
+ * in the format specs.
+ */
+ nextchance:
+ while (*fmt != ',' && *fmt != '\0') {
+ if (*fmt == '&' && setargs)
+ curarg = va_arg(args, void *);
+ fmt++;
+ }
+ argp = sargp;
+ *pac = spac;
+ *pav = spav;
+ continue;
+ }
+ val = (long)llval;
+ if (fmt[1] == 'l' || fmt[1] == 'L') {
+ if (fmt[2] == 'l' || fmt[2] == 'L') {
+ if (setargs)
+ *((Llong *)curarg) = llval;
+ fmt += 2;
+ } else {
+ if (setargs)
+ *((long *)curarg) = val;
+ fmt++;
+ }
+ } else if (fmt[1] == 's' || fmt[1] == 'S') {
+ if (setargs)
+ *((short *)curarg) = (short)val;
+ fmt++;
+ } else if (fmt[1] == 'c' || fmt[1] == 'C') {
+ if (setargs)
+ *((char *)curarg) = (char)val;
+ fmt++;
+ } else {
+ if (fmt[1] == 'i' || fmt[1] == 'I')
+ fmt++;
+ if (setargs)
+ *((int *)curarg) = (int)val;
+ }
+ argstr[0] = *fmt;
+ argstr[1] = '\0';
+
+ return (checkfmt(fmt));
+
+ case '&':
+ if (*argp == '\0') {
+ if (*pac > 1) {
+ (*pac)--;
+ (*pav)++;
+ argp = **pav;
+ } else {
+ return (BADFLAG);
+ }
+ }
+
+ if ((val = checkfmt(fmt)) != NOTAFLAG)
+ return (val);
+
+ if (setargs) {
+ int ret;
+ void *funarg = va_arg(args, void *);
+
+ ret = ((*(getargfun)curarg) (argp, funarg));
+ if (ret != NOTAFILE)
+ return (ret);
+ fmt++;
+ } else {
+ return (val);
+ }
+ /*
+ * Called function returns NOTAFILE: try next format.
+ */
+ }
+ }
+}
+
+
+/*---------------------------------------------------------------------------
+|
+| parse args for combined single char flags
+|
++---------------------------------------------------------------------------*/
+typedef struct {
+ void *curarg; /* The pointer to the arg to modify */
+ short count; /* The number of times a sc flag appears */
+ char c; /* The single char flag character */
+ char type; /* The type of the single char flag */
+} sflags;
+
+LOCAL int
+dosflags(argp, fmt, setargs, oargs)
+ register const char *argp;
+ register const char *fmt;
+ BOOL setargs;
+ va_list oargs;
+{
+#define MAXSF 32
+ sflags sf[MAXSF];
+ va_list args;
+ register sflags *rsf = sf;
+ register int nsf = 0;
+ register const char *p = argp;
+ register int i;
+ register void *curarg = (void *)0;
+ char type;
+
+ /*
+ * Initialize 'args' to the start of the argument list.
+ * I don't know any portable way to copy an arbitrary
+ * C object so I use a system-specific routine
+ * (probably a macro) from stdarg.h. (Remember that
+ * if va_list is an array, 'args' will be a pointer
+ * and '&args' won't be what I would need for memcpy.)
+ * It is a system requirement for SVr4 compatibility
+ * to be able to do this assgignement. If your system
+ * defines va_list to be an array but does not define
+ * va_copy() you are lost.
+ * This is needed to make sure, that 'oargs' will not
+ * be clobbered.
+ */
+ va_copy(args, oargs);
+
+ if (setargs)
+ curarg = va_arg(args, void *);
+
+ while (*p) {
+ for (i = 0; i < nsf; i++) {
+ if (rsf[i].c == *p)
+ break;
+ }
+ if (i >= MAXSF)
+ return (BADFLAG);
+ if (i == nsf) {
+ rsf[i].curarg = (void *)0;
+ rsf[i].count = 0;
+ rsf[i].c = *p;
+ rsf[i].type = (char)-1;
+ nsf++;
+ }
+ rsf[i].count++;
+ p++;
+ }
+
+ while (*fmt) {
+ if (!isfmtspec(*fmt) &&
+ (fmt[1] == ',' || fmt[1] == '+' || fmt[1] == '\0') &&
+ strchr(argp, *fmt)) {
+ for (i = 0; i < nsf; i++) {
+ if (rsf[i].c == *fmt) {
+ if (fmt[1] == '+') {
+ fmt++;
+ if (fmt[1] == ',' ||
+ fmt[1] == '\0') {
+ rsf[i].type = 'i';
+ } else if ((fmt[1] == 'l' ||
+ fmt[1] == 'L') &&
+ (fmt[2] == 'l' ||
+ fmt[2] == 'L')) {
+ /*
+ * Type 'Q'uad (ll)
+ */
+ rsf[i].type = 'Q';
+ fmt++;
+ } else {
+ /*
+ * Type 'l','i','s','c'
+ */
+ rsf[i].type = fmt[1];
+ }
+ } else {
+ /*
+ * ',' or '\0' for BOOL
+ */
+ rsf[i].type = fmt[1];
+ }
+ rsf[i].curarg = curarg;
+ break;
+ }
+ }
+ }
+ while (*fmt != ',' && *fmt != '\0') {
+ /* function has extra arg on stack */
+ if (*fmt == '&' && setargs)
+ curarg = va_arg(args, void *);
+ fmt++;
+ }
+ if (*fmt != '\0')
+ fmt++;
+
+ if (setargs)
+ curarg = va_arg(args, void *);
+ }
+ for (i = 0; i < nsf; i++) {
+ type = rsf[i].type;
+ if (type == (char)-1) {
+ return (BADFLAG);
+ }
+ if (rsf[i].curarg) {
+ if (type == ',' || type == '\0') {
+ *((int *)rsf[i].curarg) = TRUE;
+ } else if (type == 'i' || type == 'I') {
+ *((int *)rsf[i].curarg) += rsf[i].count;
+ } else if (type == 'l' || type == 'L') {
+ *((long *)rsf[i].curarg) += rsf[i].count;
+ } else if (type == 'Q') {
+ *((Llong *)rsf[i].curarg) += rsf[i].count;
+ } else if (type == 's' || type == 'S') {
+ *((short *)rsf[i].curarg) += rsf[i].count;
+ } else if (type == 'c' || type == 'C') {
+ *((char *)rsf[i].curarg) += rsf[i].count;
+ } else {
+ return (BADFLAG);
+ }
+ }
+ }
+ return (NOTAFLAG);
+}
+
+/*---------------------------------------------------------------------------
+|
+| If the next format character is a comma or the string delimiter,
+| there are no invalid format specifiers. Return success.
+| Otherwise raise the getarg_bad_format condition.
+|
++---------------------------------------------------------------------------*/
+LOCAL int
+checkfmt(fmt)
+ const char *fmt;
+{
+ char c;
+
+ c = *(++fmt); /* non constant expression */
+
+
+ if (c == ',' || c == '\0') {
+ return (NOTAFLAG);
+ } else {
+ raisecond("getarg_bad_format", (long)fmt);
+ return (BADFMT);
+ }
+}
+
+/*---------------------------------------------------------------------------
+|
+| Parse the string as long as valid characters can be found.
+| Valid flag identifiers are chosen from the set of
+| alphanumeric characters, '-' and '_'.
+| If the next character is an equal sign the string
+| contains a valid flag identifier.
+|
++---------------------------------------------------------------------------*/
+LOCAL int
+checkeql(str)
+ register const char *str;
+{
+ register unsigned char c;
+
+ for (c = (unsigned char)*str;
+ isalnum(c) || c == '_' || c == '-'; c = *str++)
+ /* LINTED */
+ ;
+ return (c == '=');
+}
diff --git a/librols/getav0.c b/librols/getav0.c
new file mode 100644
index 0000000..3b7e2f4
--- /dev/null
+++ b/librols/getav0.c
@@ -0,0 +1,155 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)getav0.c 1.16 04/05/09 Copyright 1985, 1995-2004 J. Schilling */
+/*
+ * Get arg vector by scanning the stack
+ *
+ * Copyright (c) 1985, 1995-2004 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 <mconfig.h>
+#include <sigblk.h>
+#include <avoffset.h>
+#include <standard.h>
+#include <schily.h>
+
+#if !defined(AV_OFFSET) || !defined(FP_INDIR)
+# ifdef HAVE_SCANSTACK
+# undef HAVE_SCANSTACK
+# endif
+#endif
+
+#ifdef HAVE_SCANSTACK
+
+#include <stkframe.h>
+
+#define is_even(p) ((((long)(p)) & 1) == 0)
+#define even(p) (((long)(p)) & ~1L)
+#ifdef __future__
+#define even(p) (((long)(p)) - 1) /* will this work with 64 bit ?? */
+#endif
+
+EXPORT char **getmainfp __PR((void));
+EXPORT char **getavp __PR((void));
+EXPORT char *getav0 __PR((void));
+
+
+EXPORT char **
+getmainfp()
+{
+ register struct frame *fp;
+ char **av;
+#if FP_INDIR > 0
+ register int i = 0;
+#endif
+
+ /*
+ * As the SCO OpenServer C-Compiler has a bug that may cause
+ * the first function call to getfp() been done before the
+ * new stack frame is created, we call getfp() twice.
+ */
+ (void) getfp();
+ fp = (struct frame *)getfp();
+ if (fp == NULL)
+ return (NULL);
+
+ while (fp->fr_savfp) {
+ if (fp->fr_savpc == NULL)
+ break;
+
+ if (!is_even(fp->fr_savfp)) {
+ fp = (struct frame *)even(fp->fr_savfp);
+ if (fp == NULL)
+ break;
+ fp = (struct frame *)((SIGBLK *)fp)->sb_savfp;
+ continue;
+ }
+ fp = (struct frame *)fp->fr_savfp;
+
+#if FP_INDIR > 0
+ i++;
+#endif
+ }
+
+#if FP_INDIR > 0
+ i -= FP_INDIR;
+ fp = (struct frame *)getfp();
+ if (fp == NULL)
+ return (NULL);
+
+ while (fp->fr_savfp) {
+ if (fp->fr_savpc == NULL)
+ break;
+
+ if (!is_even(fp->fr_savfp)) {
+ fp = (struct frame *)even(fp->fr_savfp);
+ if (fp == NULL)
+ break;
+ fp = (struct frame *)((SIGBLK *)fp)->sb_savfp;
+ continue;
+ }
+ fp = (struct frame *)fp->fr_savfp;
+
+ if (--i <= 0)
+ break;
+ }
+#endif
+
+ av = (char **)fp;
+ return (av);
+}
+
+EXPORT char **
+getavp()
+{
+ register struct frame *fp;
+ char **av;
+
+ fp = (struct frame *)getmainfp();
+ if (fp == NULL)
+ return (NULL);
+
+ av = (char **)(((char *)fp) + AV_OFFSET); /* aus avoffset.h */
+ /* -> avoffset.c */
+ return (av);
+}
+
+EXPORT char *
+getav0()
+{
+ return (getavp()[0]);
+}
+
+#else
+
+EXPORT char *
+getav0()
+{
+ return ("???");
+}
+
+#endif /* HAVE_SCANSTACK */
diff --git a/librols/getdomainname.c b/librols/getdomainname.c
new file mode 100644
index 0000000..8338770
--- /dev/null
+++ b/librols/getdomainname.c
@@ -0,0 +1,115 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)getdomainname.c 1.16 03/06/15 Copyright 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 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 <mconfig.h>
+#include <standard.h>
+#include <stdxlib.h>
+#ifdef HAVE_SYS_SYSTEMINFO_H
+#include <sys/systeminfo.h>
+#endif
+#include <libport.h>
+
+#ifndef HAVE_GETDOMAINNAME
+EXPORT int getdomainname __PR((char *name, int namelen));
+#endif
+
+
+/*#undef HAVE_GETDOMAINNAME*/
+/*#undef SI_SRPC_DOMAIN*/
+
+#if !defined(HAVE_GETDOMAINNAME) && defined(SI_SRPC_DOMAIN)
+#define FUNC_GETDOMAINNAME
+
+EXPORT int
+getdomainname(name, namelen)
+ char *name;
+ int namelen;
+{
+ if (sysinfo(SI_SRPC_DOMAIN, name, namelen) < 0)
+ return (-1);
+ return (0);
+}
+#endif
+
+#if !defined(HAVE_GETDOMAINNAME) && !defined(FUNC_GETDOMAINNAME)
+#define FUNC_GETDOMAINNAME
+
+#include <stdio.h>
+#include <strdefs.h>
+#include <schily.h>
+
+EXPORT int
+getdomainname(name, namelen)
+ char *name;
+ int namelen;
+{
+ FILE *f;
+ char name1[1024];
+ char *p;
+ char *p2;
+
+ name[0] = '\0';
+
+ f = fileopen("/etc/resolv.conf", "r");
+
+ if (f == NULL)
+ return (-1);
+
+ while (rols_fgetline(f, name1, sizeof (name1)) >= 0) {
+ if ((p = strchr(name1, '#')) != NULL)
+ *p = '\0';
+
+ /*
+ * Skip leading whitespace.
+ */
+ p = name1;
+ while (*p != '\0' && (*p == ' ' || *p == '\t'))
+ p++;
+
+ if (strncmp(p, "domain", 6) == 0) {
+ p += 6;
+ while (*p != '\0' && (*p == ' ' || *p == '\t'))
+ p++;
+ if ((p2 = strchr(p, ' ')) != NULL)
+ *p2 = '\0';
+ if ((p2 = strchr(p, '\t')) != NULL)
+ *p2 = '\0';
+
+ strncpy(name, p, namelen);
+
+ fclose(f);
+ return (0);
+ }
+ }
+ fclose(f);
+ return (0);
+}
+#endif
diff --git a/librols/geterrno.c b/librols/geterrno.c
new file mode 100644
index 0000000..8e60e78
--- /dev/null
+++ b/librols/geterrno.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.
+ *
+ */
+
+/* @(#)geterrno.c 1.9 03/06/15 Copyright 1985, 1995-2003 J. Schilling */
+/*
+ * Get error number
+ *
+ * Copyright (c) 1985, 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 <errno.h>
+#include <standard.h>
+#include <schily.h>
+
+#ifndef HAVE_ERRNO_DEF
+extern int errno;
+#endif
+
+#ifdef geterrno
+#undef geterrno
+#endif
+
+EXPORT int
+geterrno()
+
+{
+ return (errno);
+}
diff --git a/librols/gethostid.c b/librols/gethostid.c
new file mode 100644
index 0000000..1b4fe02
--- /dev/null
+++ b/librols/gethostid.c
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)gethostid.c 1.15 03/06/15 Copyright 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 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 <mconfig.h>
+#include <standard.h>
+#include <stdxlib.h>
+#include <utypes.h>
+#ifdef HAVE_SYS_SYSTEMINFO_H
+#include <sys/systeminfo.h>
+#endif
+#include <libport.h>
+
+#ifndef HAVE_GETHOSTID
+EXPORT long gethostid __PR((void));
+#endif
+
+
+#if !defined(HAVE_GETHOSTID)
+
+#if defined(SI_HW_SERIAL)
+
+EXPORT long
+gethostid()
+{
+ long id;
+
+ char hbuf[257];
+ sysinfo(SI_HW_SERIAL, hbuf, sizeof (hbuf));
+ id = atoi(hbuf);
+ return (id);
+}
+#else
+
+#include <errno.h>
+EXPORT long
+gethostid()
+{
+ long id = -1L;
+
+#ifdef ENOSYS
+ seterrno(ENOSYS);
+#else
+ seterrno(EINVAL);
+#endif
+ return (id);
+}
+#endif
+
+#endif
diff --git a/librols/gethostname.c b/librols/gethostname.c
new file mode 100644
index 0000000..483ee7f
--- /dev/null
+++ b/librols/gethostname.c
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)gethostname.c 1.15 03/10/04 Copyright 1995 J. Schilling */
+/*
+ * Copyright (c) 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 <mconfig.h>
+#include <standard.h>
+#include <stdxlib.h>
+#ifdef HAVE_SYS_SYSTEMINFO_H
+#include <sys/systeminfo.h>
+#endif
+#include <libport.h>
+
+#ifndef HAVE_GETHOSTNAME
+EXPORT int gethostname __PR((char *name, int namelen));
+
+
+#ifdef SI_HOSTNAME
+
+EXPORT int
+gethostname(name, namelen)
+ char *name;
+ int namelen;
+{
+ if (sysinfo(SI_HOSTNAME, name, namelen) < 0)
+ return (-1);
+ return (0);
+}
+#else
+
+#if defined(HAVE_UNAME) && defined(HAVE_SYS_UTSNAME_H)
+#include <sys/utsname.h>
+#include <strdefs.h>
+
+EXPORT int
+gethostname(name, namelen)
+ char *name;
+ int namelen;
+{
+ struct utsname uts;
+
+ if (uname(&uts) < 0)
+ return (-1);
+
+ strncpy(name, uts.nodename, namelen);
+ return (0);
+}
+#endif
+
+#endif
+
+#endif /* HAVE_GETHOSTNAME */
diff --git a/librols/getpagesize.c b/librols/getpagesize.c
new file mode 100644
index 0000000..8a98edd
--- /dev/null
+++ b/librols/getpagesize.c
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)getpagesize.c 1.1 01/11/28 Copyright 2001 J. Schilling */
+/*
+ * Copyright (c) 2001 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 <mconfig.h>
+
+#ifndef HAVE_GETPAGESIZE
+
+#include <unixstd.h>
+#include <standard.h>
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#include <libport.h>
+
+#ifdef HAVE_OS_H
+#include <OS.h> /* BeOS for B_PAGE_SIZE */
+#endif
+
+int getpagesize(void)
+{
+#ifdef _SC_PAGESIZE
+ return sysconf(_SC_PAGESIZE);
+#else
+# ifdef PAGESIZE /* Traditional UNIX page size from param.h */
+ return PAGESIZE;
+# else
+
+# ifdef B_PAGE_SIZE /* BeOS page size from OS.h */
+ return B_PAGE_SIZE;
+# else
+ return 512;
+# endif
+# endif
+#endif
+}
+
+#endif /* HAVE_GETPAGESIZE */
diff --git a/librols/handlecond.c b/librols/handlecond.c
new file mode 100644
index 0000000..06668b8
--- /dev/null
+++ b/librols/handlecond.c
@@ -0,0 +1,287 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)handlecond.c 1.22 04/05/09 Copyright 1985-2004 J. Schilling */
+/*
+ * setup/clear a condition handler for a software signal
+ */
+/*
+ * 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.
+ */
+/*
+ * A procedure frame is marked to have handlers if the
+ * previous freme pointer for this procedure is odd.
+ * The even base value, in this case actually points to a SIGBLK which
+ * holds the saved "real" frame pointer.
+ * The SIGBLK mentioned above may me the start of a chain of SIGBLK's,
+ * containing different handlers.
+ *
+ * This will work on processors which support a frame pointer chain
+ * on the stack.
+ * On a processor which doesn't support this I think of a method
+ * where handlecond() has an own chain of frames, holding chains of
+ * SIGBLK's.
+ * In this case, a parameter has to be added to handlecond() and
+ * unhandlecond(). This parameter will be an opaque cookie which is zero
+ * on the first call to handlecond() in a procedure.
+ * A new cookie will be returned by handlecond() which must be used on
+ * each subsequent call to handlecond() and unhandlecond() in the same
+ * procedure.
+ *
+ * Copyright (c) 1985-2004 J. Schilling
+ */
+#include <mconfig.h>
+#include <sigblk.h>
+#include <standard.h>
+#include <stdxlib.h>
+#include <strdefs.h>
+#include <avoffset.h>
+#include <utypes.h>
+#include <schily.h>
+
+#if !defined(AV_OFFSET) || !defined(FP_INDIR)
+# ifdef HAVE_SCANSTACK
+# undef HAVE_SCANSTACK
+# endif
+#endif
+
+#ifdef HAVE_SCANSTACK
+#include <stkframe.h>
+#else
+extern SIGBLK *__roothandle;
+#endif /* HAVE_SCANSTACK */
+
+#define is_even(p) ((((long)(p)) & 1) == 0)
+#define even(p) (((long)(p)) & ~1L)
+#if defined(__sun) && defined(__i386)
+/*
+ * Solaris x86 has a broken frame.h which defines the frame ptr to int.
+ */
+#define odd(p) (((Intptr_t)(p)) | 1)
+#else
+#define odd(p) (void *)(((Intptr_t)(p)) | 1)
+#endif
+
+#ifdef __future__
+#define even(p) (((long)(p)) - 1) /* will this work with 64 bit ?? */
+#endif
+
+EXPORT void starthandlecond __PR((SIGBLK *sp));
+
+#ifdef PROTOTYPES
+EXPORT void
+handlecond(const char *signame,
+ register SIGBLK *sp,
+ int (*func)(const char *, long, long),
+ long arg1)
+#else
+EXPORT void
+handlecond(signame, sp, func, arg1)
+ char *signame;
+ register SIGBLK *sp;
+ BOOL (*func)();
+ long arg1;
+#endif
+{
+ register SIGBLK *this;
+ register SIGBLK *last = (SIGBLK *)NULL;
+#ifdef HAVE_SCANSTACK
+ struct frame *fp = (struct frame *)NULL;
+#endif
+ int slen;
+
+ if (signame == NULL || (slen = strlen(signame)) == 0) {
+ raisecond("handle_bad_name", (long)signame);
+ abort();
+ }
+
+#ifdef HAVE_SCANSTACK
+ fp = (struct frame *)getfp();
+ fp = (struct frame *)fp->fr_savfp; /* point to frame of caller */
+ if (is_even(fp->fr_savfp)) {
+ /*
+ * Easy case: no handlers yet
+ * save real framepointer in sp->sb_savfp
+ */
+ sp->sb_savfp = (long **)fp->fr_savfp;
+ this = (SIGBLK *)NULL;
+ } else {
+ this = (SIGBLK *)even(fp->fr_savfp);
+ }
+#else
+ this = __roothandle;
+#endif
+
+ for (; this; this = this->sb_signext) {
+ if (this == sp) {
+ /*
+ * If a SIGBLK is reused, the name must not change.
+ */
+ if (this->sb_signame != NULL &&
+ !streql(this->sb_signame, signame)) {
+ raisecond("handle_reused_block", (long)signame);
+ abort();
+ }
+ sp->sb_sigfun = func;
+ sp->sb_sigarg = arg1;
+ return;
+ }
+ if (this->sb_signame != NULL &&
+ streql(this->sb_signame, signame)) {
+ if (last == (SIGBLK *)NULL) {
+ /*
+ * 'this' is the first entry in chain
+ */
+ if (this->sb_signext == (SIGBLK *)NULL) {
+ /*
+ * only 'this' entry is in chain, copy
+ * saved real frame pointer into new sp
+ */
+ sp->sb_savfp = this->sb_savfp;
+ } else {
+#ifdef HAVE_SCANSTACK
+ /*
+ * make second entry first link in chain
+ */
+ this->sb_signext->sb_savfp =
+ this->sb_savfp;
+ fp->fr_savfp = odd(this->sb_signext);
+#else
+ /*
+ * Cannot happen if scanning the stack
+ * is not possible...
+ */
+ raisecond("handle_is_empty", (long)0);
+ abort();
+#endif
+ }
+ continue; /* don't trash 'last' ptr */
+ } else {
+ last->sb_signext = this->sb_signext;
+ }
+ }
+ last = this;
+ }
+ sp->sb_signext = (SIGBLK *)NULL;
+ sp->sb_signame = signame;
+ sp->sb_siglen = slen;
+ sp->sb_sigfun = func;
+ sp->sb_sigarg = arg1;
+ /*
+ * If there is a chain append to end of the chain, else make it first
+ */
+ if (last)
+ last->sb_signext = sp;
+#ifdef HAVE_SCANSTACK
+ else
+ fp->fr_savfp = odd(sp);
+#else
+ /*
+ * Cannot happen if scanning the stack is not possible...
+ */
+ else {
+ raisecond("handle_is_empty", (long)0);
+ abort();
+ }
+#endif
+}
+
+EXPORT void
+starthandlecond(sp)
+ register SIGBLK *sp;
+{
+#ifdef HAVE_SCANSTACK
+ struct frame *fp = NULL;
+
+ /*
+ * As the SCO OpenServer C-Compiler has a bug that may cause
+ * the first function call to getfp() been done before the
+ * new stack frame is created, we call getfp() twice.
+ */
+ (void) getfp();
+#endif
+
+ sp->sb_signext = (SIGBLK *)NULL;
+ sp->sb_signame = NULL;
+ sp->sb_siglen = 0;
+ sp->sb_sigfun = (handlefunc_t)NULL;
+ sp->sb_sigarg = 0;
+
+#ifdef HAVE_SCANSTACK
+ fp = (struct frame *)getfp();
+ fp = (struct frame *)fp->fr_savfp; /* point to frame of caller */
+
+ if (is_even(fp->fr_savfp)) {
+ /*
+ * Easy case: no handlers yet
+ * save real framepointer in sp
+ */
+ sp->sb_savfp = (long **)fp->fr_savfp;
+ fp->fr_savfp = odd(sp);
+ } else {
+ raisecond("handle_not_empty", (long)0);
+ abort();
+ }
+#else
+ sp->sb_savfp = (long **)__roothandle;
+ __roothandle = sp;
+#endif
+}
+
+EXPORT void
+unhandlecond(sp)
+ register SIGBLK *sp;
+{
+#ifdef HAVE_SCANSTACK
+ register struct frame *fp;
+ register SIGBLK *sps;
+
+ /*
+ * As the SCO OpenServer C-Compiler has a bug that may cause
+ * the first function call to getfp() been done before the
+ * new stack frame is created, we call getfp() twice.
+ */
+ (void) getfp();
+ fp = (struct frame *)getfp();
+ fp = (struct frame *)fp->fr_savfp; /* point to frame of caller */
+
+ if (!is_even(fp->fr_savfp)) { /* if handlers */
+ sps = (SIGBLK *)even(fp->fr_savfp); /* point to SIGBLK */
+ /* real framepointer */
+#if defined(__sun) && defined(__i386)
+ fp->fr_savfp = (intptr_t)sps->sb_savfp;
+#else
+ fp->fr_savfp = (struct frame *)sps->sb_savfp;
+#endif
+ }
+#else
+ if (__roothandle == NULL) {
+ raisecond("handle_is_empty", (long)0);
+ abort();
+ }
+ /*
+ * Pop top level handler chain.
+ */
+ __roothandle = (SIGBLK *)__roothandle->sb_savfp;
+#endif
+}
diff --git a/librols/movebytes.c b/librols/movebytes.c
new file mode 100644
index 0000000..3724c99
--- /dev/null
+++ b/librols/movebytes.c
@@ -0,0 +1,136 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)movebytes.c 1.13 03/06/15 Copyright 1985, 1989, 1995-2003 J. Schilling */
+/*
+ * move data
+ *
+ * Copyright (c) 1985, 1989, 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 <standard.h>
+#include <align.h>
+#include <schily.h>
+
+#define DO8(a) a; a; a; a; a; a; a; a;
+
+EXPORT char *
+movebytes(fromv, tov, cnt)
+ const void *fromv;
+ void *tov;
+ int cnt;
+{
+ register const char *from = fromv;
+ register char *to = tov;
+ register int n;
+
+ /*
+ * If we change cnt to be unsigned, check for == instead of <=
+ */
+ if ((n = cnt) <= 0)
+ return (to);
+
+ if (from >= to) {
+ /*
+ * source is on higher adresses than destination:
+ * move bytes forwards
+ */
+ if (n >= (int)(8 * sizeof (long))) {
+ if (l2aligned(from, to)) {
+ register const long *froml = (const long *)from;
+ register long *tol = (long *)to;
+ register int rem = n % (8 * sizeof (long));
+
+ n /= (8 * sizeof (long));
+ do {
+ DO8 (*tol++ = *froml++);
+ } while (--n > 0);
+
+ from = (const char *)froml;
+ to = (char *)tol;
+ n = rem;
+ }
+
+ if (n >= 8) {
+ n -= 8;
+ do {
+ DO8 (*to++ = *from++);
+ } while ((n -= 8) >= 0);
+ n += 8;
+ }
+
+ if (n > 0) do {
+ *to++ = *from++;
+ } while (--n > 0);
+ return (to);
+ }
+ if (n > 0) do {
+ *to++ = *from++;
+ } while (--n > 0);
+ return (to);
+ } else {
+ char *ep;
+
+ /*
+ * source is on lower adresses than destination:
+ * move bytes backwards
+ */
+ to += n;
+ from += n;
+ ep = to;
+ if (n >= (int)(8 * sizeof (long))) {
+ if (l2aligned(from, to)) {
+ register const long *froml = (const long *)from;
+ register long *tol = (long *)to;
+ register int rem = n % (8 * sizeof (long));
+
+ n /= (8 * sizeof (long));
+ do {
+ DO8 (*--tol = *--froml);
+ } while (--n > 0);
+
+ from = (const char *)froml;
+ to = (char *)tol;
+ n = rem;
+ }
+ if (n >= 8) {
+ n -= 8;
+ do {
+ DO8 (*--to = *--from);
+ } while ((n -= 8) >= 0);
+ n += 8;
+ }
+ if (n > 0) do {
+ *--to = *--from;
+ } while (--n > 0);
+ return (ep);
+ }
+ if (n > 0) do {
+ *--to = *--from;
+ } while (--n > 0);
+ return (ep);
+ }
+}
diff --git a/librols/raisecond.c b/librols/raisecond.c
new file mode 100644
index 0000000..01cef9c
--- /dev/null
+++ b/librols/raisecond.c
@@ -0,0 +1,179 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)raisecond.c 1.18 04/05/09 Copyright 1985, 1989, 1995-2004 J. Schilling */
+/*
+ * raise a condition (software signal)
+ */
+/*
+ * 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.
+ */
+/*
+ * Check for installed condition handlers.
+ * If a handler is found, the function is called with the appropriate args.
+ * If no handler is found or no handler signals success,
+ * the program will be aborted.
+ *
+ * Copyright (c) 1985, 1989, 1995-2004 J. Schilling
+ */
+#include <mconfig.h>
+#include <stdio.h>
+#include <standard.h>
+#include <sigblk.h>
+#include <unixstd.h>
+#include <stdxlib.h>
+#include <strdefs.h>
+#include <avoffset.h>
+#include <schily.h>
+
+#if !defined(AV_OFFSET) || !defined(FP_INDIR)
+# ifdef HAVE_SCANSTACK
+# undef HAVE_SCANSTACK
+# endif
+#endif
+
+/*
+ * Macros to print to stderr without stdio, to avoid screwing up.
+ */
+#ifndef STDERR_FILENO
+#define STDERR_FILENO 2
+#endif
+#define eprints(a) do { int ret; ret = write(STDERR_FILENO, (a), sizeof (a)-1); } while (0)
+#define eprintl(a) do { int ret; ret = write(STDERR_FILENO, (a), strlen(a)); } while (0)
+
+#define is_even(p) ((((long)(p)) & 1) == 0)
+#define even(p) (((long)(p)) & ~1L)
+#ifdef __future__
+#define even(p) (((long)(p)) - 1) /* will this work with 64 bit ?? */
+#endif
+
+
+LOCAL void raiseabort __PR((const char *));
+
+#ifdef HAVE_SCANSTACK
+#include <stkframe.h>
+#define next_frame(vp) do { \
+ if (((struct frame *)(vp))->fr_savfp == 0) { \
+ vp = (void *)0; \
+ break; \
+ } \
+ if (((struct frame *)(vp))->fr_savpc == 0) { \
+ vp = (void *)0; \
+ break; \
+ } \
+ vp = \
+ (void *)((struct frame *)(vp))->fr_savfp; \
+ } while (vp != NULL && is_even(vp)); \
+ vp = (struct frame *)even(vp);
+#else
+EXPORT SIGBLK *__roothandle;
+
+#define next_frame(vp) vp = (((SIGBLK *)(vp))->sb_savfp);
+#endif
+
+LOCAL BOOL framehandle __PR((SIGBLK *, const char *, const char *, long));
+
+/*
+ * Loop through the chain of procedure frames on the stack.
+ *
+ * Frame pointers normally have even values.
+ * Frame pointers of procedures with an installed handler are marked odd.
+ * The even base value, in this case actually points to a SIGBLK which
+ * holds the saved "real" frame pointer.
+ * The SIGBLK mentioned above may me the start of a chain of SIGBLK's,
+ * containing different handlers.
+ */
+EXPORT void
+raisecond(signame, arg2)
+ const char *signame;
+ long arg2;
+{
+ register void *vp = NULL;
+
+#ifdef HAVE_SCANSTACK
+ /*
+ * As the SCO OpenServer C-Compiler has a bug that may cause
+ * the first function call to getfp() been done before the
+ * new stack frame is created, we call getfp() twice.
+ */
+ (void) getfp();
+ vp = getfp();
+ next_frame(vp);
+#else
+ vp = __roothandle;
+#endif
+
+ while (vp) {
+ if (framehandle((SIGBLK *)vp, signame, signame, arg2))
+ return;
+ else if (framehandle((SIGBLK *)vp, "any_other", signame, arg2))
+ return;
+#ifdef HAVE_SCANSTACK
+ vp = (struct frame *)((SIGBLK *)vp)->sb_savfp;
+#endif
+ next_frame(vp);
+ }
+ /*
+ * No matching handler that signals success found.
+ * Print error message and abort.
+ */
+ raiseabort(signame);
+ /* NOTREACHED */
+}
+
+/*
+ * Loop through the handler chain for a procedure frame.
+ *
+ * If no handler with matching name is found, return FALSE,
+ * otherwise the first handler with matching name is called.
+ * The return value in the latter case depends on the called function.
+ */
+LOCAL BOOL
+framehandle(sp, handlename, signame, arg2)
+ register SIGBLK *sp;
+ const char *handlename;
+ const char *signame;
+ long arg2;
+{
+ for (; sp; sp = sp->sb_signext) {
+ if (sp->sb_signame != NULL &&
+ streql(sp->sb_signame, handlename)) {
+ if (sp->sb_sigfun == NULL) { /* deactivated */
+ return (FALSE);
+ } else {
+ return (*sp->sb_sigfun)(signame,
+ sp->sb_sigarg, arg2);
+ }
+ }
+ }
+ return (FALSE);
+}
+
+LOCAL void
+raiseabort(signame)
+ const char *signame;
+{
+ eprints("Condition not caught: "); eprintl(signame); eprints(".\n");
+ abort();
+ /* NOTREACHED */
+}
diff --git a/librols/rename.c b/librols/rename.c
new file mode 100644
index 0000000..dca60ea
--- /dev/null
+++ b/librols/rename.c
@@ -0,0 +1,144 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)rename.c 1.6 04/09/04 Copyright 1998-2003 J. Schilling */
+/*
+ * rename() for old systems that don't have it.
+ *
+ * Copyright (c) 1998-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.
+ */
+
+#define rename __nothing__
+#include <mconfig.h>
+
+#ifndef HAVE_RENAME
+
+#include <stdio.h> /* XXX not OK but needed for js_xx() in schily.h */
+#include <unixstd.h>
+#include <strdefs.h>
+#include <statdefs.h>
+#include <maxpath.h>
+#include <standard.h>
+#include <utypes.h>
+#include <schily.h>
+#include <errno.h>
+#undef rename
+#include <libport.h>
+
+#ifndef MAXPATHNAME
+#define MAXPATHNAME 1024
+#endif
+
+#if MAXPATHNAME < 1024
+#undef MAXPATHNAME
+#define MAXPATHNAME 1024
+#endif
+
+#define MAXNAME MAXPATHNAME
+
+#define FILEDESC struct stat
+
+#ifndef HAVE_LSTAT
+#define lstat stat
+#endif
+
+EXPORT int
+rename(old, new)
+ const char *old;
+ const char *new;
+{
+ char nname[MAXNAME];
+ char bakname[MAXNAME];
+ char strpid[32];
+ int strplen;
+ BOOL savpresent = FALSE;
+ BOOL newpresent = FALSE;
+ int serrno;
+ FILEDESC ostat;
+ FILEDESC xstat;
+
+ serrno = geterrno();
+
+ if (lstat(old, &ostat) < 0)
+ return (-1);
+
+ if (lstat(new, &xstat) >= 0) {
+ newpresent = TRUE;
+ if (ostat.st_dev == xstat.st_dev &&
+ ostat.st_ino == xstat.st_ino)
+ return (0); /* old == new we are done */
+ }
+
+ strplen = snprintf(strpid, sizeof (strpid), ".%lld",
+ (Llong)getpid());
+
+ if (strlen(new) <= (MAXNAME-strplen) ||
+ strchr(&new[MAXNAME-strplen], '/') == NULL) {
+ /*
+ * Save old version of file 'new'.
+ */
+ strncpy(nname, new, MAXNAME-strplen);
+ nname[MAXNAME-strplen] = '\0';
+ snprintf(bakname, sizeof (bakname), "%s%s", nname, strpid);
+ unlink(bakname);
+ if (link(new, bakname) >= 0)
+ savpresent = TRUE;
+ }
+
+ if (newpresent) {
+ if (rmdir(new) < 0) {
+ if (geterrno() == ENOTDIR) {
+ if (unlink(new) < 0)
+ return (-1);
+ } else {
+ return (-1);
+ }
+ }
+ }
+
+ /*
+ * Now add 'new' name to 'old'.
+ */
+ if (link(old, new) < 0) {
+ serrno = geterrno();
+ /*
+ * Make sure not to loose old version of 'new'.
+ */
+ if (savpresent) {
+ unlink(new);
+ link(bakname, new);
+ unlink(bakname);
+ }
+ seterrno(serrno);
+ return (-1);
+ }
+ if (unlink(old) < 0)
+ return (-1);
+ unlink(bakname); /* Fails in most cases... */
+ seterrno(serrno); /* ...so restore errno */
+ return (0);
+}
+#endif /* HAVE_RENAME */
diff --git a/librols/saveargs.c b/librols/saveargs.c
new file mode 100644
index 0000000..c3a0b3c
--- /dev/null
+++ b/librols/saveargs.c
@@ -0,0 +1,135 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)saveargs.c 1.11 03/07/13 Copyright 1995-2003 J. Schilling */
+/*
+ * save argc, argv for command error printing routines
+ *
+ * Copyright (c) 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 <mconfig.h>
+#include <standard.h>
+#include <strdefs.h>
+#include <stdxlib.h>
+#include <avoffset.h>
+#include <schily.h>
+
+#if !defined(AV_OFFSET) || !defined(FP_INDIR)
+# ifdef HAVE_SCANSTACK
+# undef HAVE_SCANSTACK
+# endif
+#endif
+
+static int ac_saved;
+static char **av_saved;
+static char *av0_saved;
+static char *progname_saved;
+
+static char av0_sp[32]; /* av0 space, avoid malloc() in most cases */
+static char prn_sp[32]; /* name space, avoid malloc() in most cases */
+static char dfl_str[] = "?";
+
+EXPORT void
+save_args(ac, av)
+ int ac;
+ char *av[];
+{
+ int slen;
+
+ ac_saved = ac;
+ av_saved = av;
+
+ if (av0_saved && av0_saved != av0_sp)
+ free(av0_saved);
+
+ slen = strlen(av[0]) + 1;
+
+ if (slen <= (int)sizeof (av0_sp))
+ av0_saved = av0_sp;
+ else
+ av0_saved = malloc(slen);
+
+ if (av0_saved)
+ strcpy(av0_saved, av[0]);
+}
+
+EXPORT int
+saved_ac()
+{
+ return (ac_saved);
+}
+
+EXPORT char **
+saved_av()
+{
+ return (av_saved);
+}
+
+EXPORT char *
+saved_av0()
+{
+ return (av0_saved);
+}
+
+EXPORT void
+set_progname(name)
+ const char *name;
+{
+ int slen;
+
+ if (progname_saved && progname_saved != prn_sp)
+ free(progname_saved);
+
+ slen = strlen(name) + 1;
+
+ if (slen <= sizeof (prn_sp))
+ progname_saved = prn_sp;
+ else
+ progname_saved = malloc(slen);
+
+ if (progname_saved)
+ strcpy(progname_saved, name);
+}
+
+EXPORT char *
+get_progname()
+{
+#ifdef HAVE_SCANSTACK
+ char *progname;
+#endif
+
+ if (progname_saved)
+ return (progname_saved);
+ if (av0_saved)
+ return (av0_saved);
+#ifdef HAVE_SCANSTACK
+ progname = getav0(); /* scan stack to get argv[0] */
+ if (progname)
+ return (progname);
+#endif
+ return (dfl_str);
+}
diff --git a/librols/seterrno.c b/librols/seterrno.c
new file mode 100644
index 0000000..39c2c81
--- /dev/null
+++ b/librols/seterrno.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.
+ *
+ */
+
+/* @(#)seterrno.c 1.8 03/06/15 Copyright 1985, 1995-2003 J. Schilling */
+/*
+ * Set error number
+ *
+ * Copyright (c) 1985, 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 <standard.h>
+#include <errno.h>
+#include <schily.h>
+
+#ifndef HAVE_ERRNO_DEF
+extern int errno;
+#endif
+
+#ifdef seterrno
+#undef seterrno
+#endif
+
+EXPORT int
+seterrno(err)
+ int err;
+{
+ int old = errno;
+
+ errno = err;
+ return (old);
+}
diff --git a/librols/snprintf.c b/librols/snprintf.c
new file mode 100644
index 0000000..87b7364
--- /dev/null
+++ b/librols/snprintf.c
@@ -0,0 +1,102 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)snprintf.c 1.9 04/05/09 Copyright 1985, 1996-2004 J. Schilling */
+/*
+ * Copyright (c) 1985, 1996-2004 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.
+ */
+
+#define snprintf __nothing__ /* prototype may be wrong (e.g. IRIX) */
+#include <mconfig.h>
+#include <unixstd.h> /* include <sys/types.h> try to get size_t */
+#include <stdio.h> /* Try again for size_t */
+#include <stdxlib.h> /* Try again for size_t */
+#include <vadefs.h>
+#include <standard.h>
+#include <schily.h>
+#undef snprintf
+
+EXPORT int snprintf __PR((char *, size_t maxcnt, const char *, ...));
+
+typedef struct {
+ char *ptr;
+ int count;
+} *BUF, _BUF;
+
+#ifdef PROTOTYPES
+static void _cput(char c, long l)
+#else
+static void _cput(c, l)
+ char c;
+ long l;
+#endif
+{
+ register BUF bp = (BUF)l;
+
+ if (--bp->count > 0) {
+ *bp->ptr++ = c;
+ } else {
+ /*
+ * Make sure that there will never be a negative overflow.
+ */
+ bp->count++;
+ }
+}
+
+/* VARARGS2 */
+#ifdef PROTOTYPES
+EXPORT int
+snprintf(char *buf, size_t maxcnt, const char *form, ...)
+#else
+EXPORT int
+snprintf(buf, maxcnt, form, va_alist)
+ char *buf;
+ unsigned maxcnt;
+ char *form;
+ va_dcl
+#endif
+{
+ va_list args;
+ int cnt;
+ _BUF bb;
+
+ bb.ptr = buf;
+ bb.count = maxcnt;
+
+#ifdef PROTOTYPES
+ va_start(args, form);
+#else
+ va_start(args);
+#endif
+ cnt = format(_cput, (long)&bb, form, args);
+ va_end(args);
+ if (maxcnt > 0)
+ *(bb.ptr) = '\0';
+ if (bb.count < 0)
+ return (-1);
+
+ return (cnt);
+}
diff --git a/librols/spawn.c b/librols/spawn.c
new file mode 100644
index 0000000..011e92f
--- /dev/null
+++ b/librols/spawn.c
@@ -0,0 +1,170 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)spawn.c 1.17 04/09/25 Copyright 1985, 1989, 1995-2003 J. Schilling */
+/*
+ * Spawn another process/ wait for child process
+ *
+ * Copyright (c) 1985, 1989, 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 <mconfig.h>
+#include <stdio.h>
+#include <standard.h>
+#define fspawnl __nothing__ /* prototype in schily.h is wrong */
+#define spawnl __nothing__ /* prototype in schily.h is wrong */
+#include <schily.h>
+#undef fspawnl
+#undef spawnl
+#include <unixstd.h>
+#include <stdxlib.h>
+#include <vadefs.h>
+#include <waitdefs.h>
+#include <errno.h>
+
+#define MAX_F_ARGS 16
+
+EXPORT int fspawnl __PR((FILE *, FILE *, FILE *, ...));
+
+EXPORT int
+fspawnv(in, out, err, argc, argv)
+ FILE *in;
+ FILE *out;
+ FILE *err;
+ int argc;
+ char * const argv[];
+{
+ int pid;
+
+ if ((pid = fspawnv_nowait(in, out, err, argv[0], argc, argv)) < 0)
+ return (pid);
+
+ return (wait_chld(pid));
+}
+
+/* VARARGS3 */
+#ifdef PROTOTYPES
+EXPORT int
+fspawnl(FILE *in, FILE *out, FILE *err, ...)
+#else
+EXPORT int
+fspawnl(in, out, err, va_alist)
+ FILE *in;
+ FILE *out;
+ FILE *err;
+ va_dcl
+#endif
+{
+ va_list args;
+ int ac = 0;
+ char *xav[MAX_F_ARGS];
+ char **av;
+ char **pav;
+ char *p;
+ int ret;
+
+#ifdef PROTOTYPES
+ va_start(args, err);
+#else
+ va_start(args);
+#endif
+ while (va_arg(args, char *) != NULL)
+ ac++;
+ va_end(args);
+
+ if (ac < MAX_F_ARGS) {
+ pav = av = xav;
+ } else {
+ pav = av = (char **)malloc((ac+1)*sizeof (char *));
+ if (av == 0)
+ return (-1);
+ }
+
+#ifdef PROTOTYPES
+ va_start(args, err);
+#else
+ va_start(args);
+#endif
+ do {
+ p = va_arg(args, char *);
+ *pav++ = p;
+ } while (p != NULL);
+ va_end(args);
+
+ ret = fspawnv(in, out, err, ac, av);
+ if (av != xav)
+ free(av);
+ return (ret);
+}
+
+EXPORT int
+fspawnv_nowait(in, out, err, name, argc, argv)
+ FILE *in;
+ FILE *out;
+ FILE *err;
+ const char *name;
+ int argc;
+ char * const argv[];
+{
+ int pid = -1; /* Initialization needed to make GCC happy */
+ int i;
+
+ for (i = 1; i < 64; i *= 2) {
+ if ((pid = fork()) >= 0)
+ break;
+ sleep(i);
+ }
+ if (pid != 0)
+ return (pid);
+ /*
+ * silly: fexecv must set av[ac] = NULL
+ * so we have to cast argv tp (char **)
+ */
+ rols_fexecv(name, in, out, err, argc, (char **)argv);
+ exit(geterrno());
+ /* NOTREACHED */
+}
+
+EXPORT int
+wait_chld(pid)
+ int pid;
+{
+ int died;
+ WAIT_T status;
+
+ do {
+ do {
+ died = wait(&status);
+ } while (died < 0 && geterrno() == EINTR);
+ if (died < 0)
+ return (died);
+ } while (died != pid);
+
+ if (WCOREDUMP(status))
+ unlink("core");
+
+ return (WEXITSTATUS(status));
+}
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 */
diff --git a/librols/strcatl.c b/librols/strcatl.c
new file mode 100644
index 0000000..ef393f1
--- /dev/null
+++ b/librols/strcatl.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.
+ *
+ */
+
+/* @(#)strcatl.c 1.12 03/10/29 Copyright 1985, 1989, 1995-2003 J. Schilling */
+/*
+ * list version of strcat()
+ *
+ * concatenates all past first parameter until a NULL pointer is reached
+ *
+ * WARNING: a NULL constant is not a NULL pointer, so a caller must
+ * cast a NULL constant to a pointer: (char *)NULL
+ *
+ * returns pointer past last character (to '\0' byte)
+ *
+ * Copyright (c) 1985, 1989, 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 <mconfig.h>
+#include <vadefs.h>
+#include <standard.h>
+#include <schily.h>
+
+/* VARARGS3 */
+#ifdef PROTOTYPES
+EXPORT char *
+strcatl(char *to, ...)
+#else
+EXPORT char *
+strcatl(to, va_alist)
+ char *to;
+ va_dcl
+#endif
+{
+ va_list args;
+ register char *p;
+ register char *tor = to;
+
+#ifdef PROTOTYPES
+ va_start(args, to);
+#else
+ va_start(args);
+#endif
+ while ((p = va_arg(args, char *)) != NULL) {
+ while ((*tor = *p++) != '\0') {
+ tor++;
+ }
+ }
+ *tor = '\0';
+ va_end(args);
+ return (tor);
+}
diff --git a/librols/strdup.c b/librols/strdup.c
new file mode 100644
index 0000000..1bc5968
--- /dev/null
+++ b/librols/strdup.c
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)strdup.c 1.1 03/02/27 Copyright 2003 J. Schilling */
+/*
+ * strdup() to be used if missing on libc
+ *
+ * Copyright (c) 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 <mconfig.h>
+#include <standard.h>
+#include <stdxlib.h>
+#include <strdefs.h>
+#include <schily.h>
+#include <libport.h>
+
+#ifndef HAVE_STRDUP
+
+EXPORT char *
+strdup(s)
+ const char *s;
+{
+ unsigned i = strlen(s) + 1;
+ char *res = malloc(i);
+
+ if (res == NULL)
+ return (NULL);
+ if (i > 16) {
+ movebytes(s, res, (int) i);
+ } else {
+ char *s2 = res;
+
+ while ((*s2++ = *s++) != '\0')
+ ;
+ }
+ return (res);
+}
+#endif /* HAVE_STRDUP */
diff --git a/librols/streql.c b/librols/streql.c
new file mode 100644
index 0000000..4b9a117
--- /dev/null
+++ b/librols/streql.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.
+ *
+ */
+
+/* @(#)streql.c 1.7 03/06/15 Copyright 1985, 1995-2003 J. Schilling */
+/*
+ * Check if two strings are equal
+ *
+ * Copyright (c) 1985, 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 <standard.h>
+#include <schily.h>
+
+EXPORT int
+streql(a, b)
+ const char *a;
+ const char *b;
+{
+ register const char *s1 = a;
+ register const char *s2 = b;
+
+ if (s1 == NULL || s2 == NULL)
+ return (FALSE);
+
+ while (*s1 == *s2++)
+ if (*s1++ == '\0')
+ return (TRUE);
+
+ return (FALSE);
+}
diff --git a/librols/swabbytes.c b/librols/swabbytes.c
new file mode 100644
index 0000000..f2c9a57
--- /dev/null
+++ b/librols/swabbytes.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.
+ *
+ */
+
+/* @(#)swabbytes.c 1.6 03/06/15 Copyright 1988, 1995-2003 J. Schilling */
+/*
+ * swab bytes in memory
+ *
+ * Copyright (c) 1988, 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 <standard.h>
+#include <schily.h>
+
+#define DO8(a) a; a; a; a; a; a; a; a;
+
+EXPORT void
+swabbytes(vp, cnt)
+ void *vp;
+ register int cnt;
+{
+ register char *bp = (char *)vp;
+ register char c;
+
+ cnt /= 2; /* even count only */
+ while ((cnt -= 8) >= 0) {
+ DO8(c = *bp++; bp[-1] = *bp; *bp++ = c;);
+ }
+ cnt += 8;
+ while (--cnt >= 0) {
+ c = *bp++; bp[-1] = *bp; *bp++ = c;
+ }
+}
diff --git a/librols/usleep.c b/librols/usleep.c
new file mode 100644
index 0000000..780f7e3
--- /dev/null
+++ b/librols/usleep.c
@@ -0,0 +1,139 @@
+/*
+ * 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.
+ *
+ */
+
+/* @(#)usleep.c 1.17 03/06/15 Copyright 1995-2003 J. Schilling */
+/*
+ * Copyright (c) 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 <mconfig.h>
+#define usleep __nothing_ /* prototype in unistd.h may be different */
+#include <standard.h>
+#include <stdxlib.h>
+#include <timedefs.h>
+#ifdef HAVE_POLL_H
+# include <poll.h>
+#else
+# ifdef HAVE_SYS_POLL_H
+# include <sys/poll.h>
+# endif
+#endif
+#ifdef HAVE_SYS_SYSTEMINFO_H
+#include <sys/systeminfo.h>
+#endif
+#include <libport.h>
+#undef usleep
+
+#ifndef HAVE_USLEEP
+EXPORT int usleep __PR((int usec));
+#endif
+
+#ifdef OPENSERVER
+/*
+ * Don't use the usleep() from libc on SCO's OPENSERVER.
+ * It will kill our processes with SIGALRM.
+ * SCO has a usleep() prototype in unistd.h, for this reason we
+ * #define usleep to __nothing__ before including unistd.h
+ */
+#undef HAVE_USLEEP
+#endif
+
+#ifdef apollo
+/*
+ * Apollo sys5.3 usleep is broken. Define a version based on time_$wait.
+ */
+#include <apollo/base.h>
+#include <apollo/time.h>
+#undef HAVE_USLEEP
+#endif
+
+#if !defined(HAVE_USLEEP)
+
+EXPORT int
+usleep(usec)
+ int usec;
+{
+#if defined(apollo)
+ /*
+ * Need to check apollo before HAVE_SELECT, because Apollo has select,
+ * but it's time wait feature is also broken :-(
+ */
+#define HAVE_USLEEP
+ /*
+ * XXX Do these vars need to be static on Domain/OS ???
+ */
+ static time_$clock_t DomainDelay;
+ static status_$t DomainStatus;
+
+ /*
+ * DomainDelay is a 48 bit value that defines how many 4uS periods to
+ * delay. Since the input value range is 32 bits, the upper 16 bits of
+ * DomainDelay must be zero. So we just divide the input value by 4 to
+ * determine how many "ticks" to wait
+ */
+ DomainDelay.c2.high16 = 0;
+ DomainDelay.c2.low32 = usec / 4;
+ time_$wait(time_$relative, DomainDelay, &DomainStatus);
+#endif /* Apollo */
+
+#if defined(HAVE_SELECT) && !defined(HAVE_USLEEP)
+#define HAVE_USLEEP
+
+ struct timeval tv;
+ tv.tv_sec = usec / 1000000;
+ tv.tv_usec = usec % 1000000;
+ select(0, 0, 0, 0, &tv);
+#endif
+
+#if defined(HAVE_POLL) && !defined(HAVE_USLEEP)
+#define HAVE_USLEEP
+
+ if (poll(0, 0, usec/1000) < 0)
+ comerr("poll delay failed.\n");
+
+#endif
+
+#if defined(HAVE_NANOSLEEP) && !defined(HAVE_USLEEP)
+#define HAVE_USLEEP
+
+ struct timespec ts;
+
+ ts.tv_sec = usec / 1000000;
+ ts.tv_nsec = (usec % 1000000) * 1000;
+
+ nanosleep(&ts, 0);
+#endif
+
+
+#if !defined(HAVE_USLEEP)
+#define HAVE_USLEEP
+
+ sleep((usec+500000)/1000000);
+#endif
+
+ return (0);
+}
+#endif