summaryrefslogtreecommitdiff
path: root/lib/C/fake
diff options
context:
space:
mode:
Diffstat (limited to 'lib/C/fake')
-rw-r--r--lib/C/fake/Jmakefile29
-rw-r--r--lib/C/fake/Makefile.SH156
-rw-r--r--lib/C/fake/dup2.C78
-rw-r--r--lib/C/fake/getopt.C133
-rw-r--r--lib/C/fake/rename.C45
-rw-r--r--lib/C/fake/scandir.C131
-rw-r--r--lib/C/fake/setsid.C64
7 files changed, 636 insertions, 0 deletions
diff --git a/lib/C/fake/Jmakefile b/lib/C/fake/Jmakefile
new file mode 100644
index 0000000..379744c
--- /dev/null
+++ b/lib/C/fake/Jmakefile
@@ -0,0 +1,29 @@
+/*
+ * Jmakefile for C/fake subdirectory.
+ */
+
+;# $Id: Jmakefile,v 3.0.1.1 1994/01/24 13:43:44 ram Exp $
+;#
+;# Copyright (c) 1991-1993, Raphael Manfredi
+;#
+;# You may redistribute only under the terms of the Artistic Licence,
+;# as specified in the README file that comes with the distribution.
+;# You may reuse parts of this distribution only within the terms of
+;# that same Artistic Licence; a copy of which may be found at the root
+;# of the source tree for dist 3.0.
+;#
+;# $Log: Jmakefile,v $
+;# Revision 3.0.1.1 1994/01/24 13:43:44 ram
+;# patch16: created
+;#
+
+FILES = dup2.C getopt.C rename.C scandir.C setsid.C
+
+INSTALLFLAGS = -m 444
+
+all:: /* So that default make does not default to install */
+
+>PRIVLIB /* Grrr.. Have to let jmake know I need this */
+
+MakeDirectories(install,$(PRIVLIB)/lib/C/fake)
+InstallMultiple($(FILES),$(PRIVLIB)/lib/C/fake)
diff --git a/lib/C/fake/Makefile.SH b/lib/C/fake/Makefile.SH
new file mode 100644
index 0000000..a5eb2db
--- /dev/null
+++ b/lib/C/fake/Makefile.SH
@@ -0,0 +1,156 @@
+: Makefile.SH generated from Jmake.tmpl and Jmakefile [jmake 3.0 PL44]
+: $X-Id: Jmake.tmpl,v 3.0.1.1 1993/08/20 07:36:36 ram Exp ram $
+
+case $CONFIG in
+'')
+ if test -f config.sh; then TOP=.;
+ elif test -f ../config.sh; then TOP=..;
+ elif test -f ../../config.sh; then TOP=../..;
+ elif test -f ../../../config.sh; then TOP=../../..;
+ elif test -f ../../../../config.sh; then TOP=../../../..;
+ else
+ echo "Can't find config.sh."; exit 1
+ fi
+ . $TOP/config.sh
+ ;;
+esac
+case "$0" in
+*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
+esac
+CURRENT=lib/C/fake
+DIR=`echo $CURRENT/ | sed -e 's/\.\///g'`
+echo "Extracting ${DIR}Makefile (with variable substitutions)"
+
+INSTALL=`echo $install | sed -e 's,\./i,\$(TOP)/i,'`
+INSTALLDIR=`echo $installdir | sed -e 's,\./i,\$(TOP)/i,'`
+DATE=`date`
+
+$spitshell >Makefile <<!GROK!THIS!
+########################################################################
+# Makefile generated from Makefile.SH on $DATE
+
+SHELL = /bin/sh
+JMAKE = jmake
+TOP = ../../..
+CURRENT = $CURRENT
+DIR = $DIR
+INSTALL = $INSTALL
+INSTALLDIR = $INSTALLDIR
+
+########################################################################
+# Parameters set by Configure -- edit config.sh if changes are needed
+
+CTAGS = ctags
+MAKE = make
+MV = $mv
+PRIVLIB = $installprivlib
+RM = $rm -f
+
+!GROK!THIS!
+$spitshell >>Makefile <<'!NO!SUBS!'
+########################################################################
+# Jmake rules for building libraries, programs, scripts, and data files
+# $X-Id: Jmake.rules,v 3.0.1.1 1994/10/29 15:46:30 ram Exp ram $
+
+########################################################################
+# Start of Jmakefile
+
+# $X-Id: Jmakefile,v 3.0.1.1 1994/01/24 13:43:44 ram Exp ram $
+#
+# Copyright (c) 1991-1993, Raphael Manfredi
+#
+# You may redistribute only under the terms of the Artistic Licence,
+# as specified in the README file that comes with the distribution.
+# You may reuse parts of this distribution only within the terms of
+# that same Artistic Licence; a copy of which may be found at the root
+# of the source tree for dist 3.0.
+#
+# $X-Log: Jmakefile,v $
+# Revision 3.0.1.1 1994/01/24 13:43:44 ram
+# patch16: created
+#
+
+FILES = dup2.C getopt.C rename.C scandir.C setsid.C
+
+INSTALLFLAGS = -m 444
+
+all::
+
+install::
+ @for dir in $(PRIVLIB)/lib/C/fake; do \
+ case '${MFLAGS}' in *[i]*) set +e;; esac; \
+ (set -x; test -d $$dir || $(INSTALLDIR) $$dir); \
+ done
+
+install:: $(FILES)
+ @case '${MFLAGS}' in *[i]*) set +e;; esac; \
+ for i in $(FILES); do \
+ (set -x; $(INSTALL) -c $(INSTALLFLAGS) $$i $(PRIVLIB)/lib/C/fake); \
+ done
+
+deinstall::
+ @case '${MFLAGS}' in *[i]*) set +e;; esac; \
+ for i in $(FILES); do \
+ (set -x; $(RM) $(PRIVLIB)/lib/C/fake/$$i); \
+ done
+
+########################################################################
+# Common rules for all Makefiles -- do not edit
+
+emptyrule::
+
+clean: local_clean
+realclean: local_realclean
+clobber: local_clobber
+
+local_clean::
+ $(RM) core *~ *.o
+
+local_realclean:: local_clean
+
+local_clobber:: local_realclean
+ $(RM) Makefile config.sh
+
+Makefile.SH: Jmakefile
+ -@if test -f $(TOP)/.package; then \
+ if test -f Makefile.SH; then \
+ echo " $(RM) Makefile.SH~; $(MV) Makefile.SH Makefile.SH~"; \
+ $(RM) Makefile.SH~; $(MV) Makefile.SH Makefile.SH~; \
+ fi; \
+ echo " $(JMAKE) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT)" ; \
+ $(JMAKE) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT) ; \
+ else touch $@; exit 0; fi
+
+Makefile: Makefile.SH
+ /bin/sh Makefile.SH
+
+tags::
+ $(CTAGS) -w *.[ch]
+ $(CTAGS) -xw *.[ch] > tags
+
+local_clobber::
+ $(RM) tags
+
+########################################################################
+# Empty rules for directories with no sub-directories -- do not edit
+
+install::
+ @echo "install in $(CURRENT) done."
+
+deinstall::
+ @echo "deinstall in $(CURRENT) done."
+
+install.man::
+ @echo "install.man in $(CURRENT) done."
+
+deinstall.man::
+ @echo "deinstall.man in $(CURRENT) done."
+
+Makefiles::
+
+Makefiles.SH::
+
+!NO!SUBS!
+chmod 644 Makefile
+$eunicefix Makefile
+
diff --git a/lib/C/fake/dup2.C b/lib/C/fake/dup2.C
new file mode 100644
index 0000000..27c3c48
--- /dev/null
+++ b/lib/C/fake/dup2.C
@@ -0,0 +1,78 @@
+/*
+ * dup2.C -- A dup2 emulation.
+ */
+
+/*
+ * $Id: dup2.C,v 3.0.1.1 1994/01/24 13:58:37 ram Exp $
+ *
+ * Copyright (c) 1991-1993, Raphael Manfredi
+ *
+ * You may redistribute only under the terms of the Artistic Licence,
+ * as specified in the README file that comes with the distribution.
+ * You may reuse parts of this distribution only within the terms of
+ * that same Artistic Licence; a copy of which may be found at the root
+ * of the source tree for dist 3.0.
+ *
+ * Original Author: Larry Wall <lwall@netlabs.com>
+ *
+ * $Log: dup2.C,v $
+ * Revision 3.0.1.1 1994/01/24 13:58:37 ram
+ * patch16: created
+ *
+ */
+
+#include "config.h"
+
+#ifdef I_FCNTL
+#include <fcntl.h>
+#endif
+
+#include "confmagic.h" /* Remove if not metaconfig -M */
+
+#ifndef HAS_DUP2
+/*
+ * dup2
+ *
+ * This routine duplicates file descriptor 'old' into 'new'. After the
+ * operation, both 'new' and 'old' refer to the same file 'old' was referring
+ * to in the first place.
+ *
+ * Returns 0 if OK, -1 on failure with errno being set to indicate the error.
+ *
+ */
+V_FUNC(int dup2, (old, new),
+ int old /* Opened file descriptor */ NXT_ARG
+ int new /* File descriptor we'd like to get */)
+{
+#ifdef HAS_FCNTL
+#ifdef F_DUPFD
+#define USE_FNCTL
+#endif
+#endif
+
+#ifdef USE_FCNTL
+ if (old == new)
+ return 0;
+
+ close(new);
+ return fcntl(old, F_DUPFD, new);
+#else
+ int fd_used[256]; /* Fixed stack used to record dup'ed files */
+ int fd_top = 0; /* Top in the fixed stack */
+ int fd; /* Currently dup'ed file descriptor */
+
+ if (old == new)
+ return 0;
+
+ close(new); /* Ensure one free slot */
+ while ((fd = dup(old)) != new) /* Until dup'ed file matches */
+ fd_used[fd_top++] = fd; /* Remember we have to close it later */
+
+ while (fd_top > 0) /* Close all useless dup'ed slots */
+ close(fd_used[--fd_top]);
+
+ return 0;
+#endif
+}
+#endif
+
diff --git a/lib/C/fake/getopt.C b/lib/C/fake/getopt.C
new file mode 100644
index 0000000..a05cfd7
--- /dev/null
+++ b/lib/C/fake/getopt.C
@@ -0,0 +1,133 @@
+/*
+ * getopt.C -- A getopt implementation.
+ */
+
+/*
+ * $Id: getopt.C,v 3.0.1.1 1994/01/24 13:58:40 ram Exp $
+ *
+ * Copyright (c) 1991-1993, Raphael Manfredi
+ *
+ * You may redistribute only under the terms of the Artistic Licence,
+ * as specified in the README file that comes with the distribution.
+ * You may reuse parts of this distribution only within the terms of
+ * that same Artistic Licence; a copy of which may be found at the root
+ * of the source tree for dist 3.0.
+ *
+ * Original Author: unknown, got this off net.sources
+ *
+ * $Log: getopt.C,v $
+ * Revision 3.0.1.1 1994/01/24 13:58:40 ram
+ * patch16: created
+ *
+ */
+
+#include "config.h"
+#include <stdio.h>
+
+#ifdef I_STRING
+#include <string.h>
+#else
+#include <strings.h>
+#endif
+
+#include "confmagic.h" /* Remove if not metaconfig -M */
+
+#ifndef HAS_GETOPT
+
+/*
+ * Get option letter from argument vector
+ */
+
+int opterr = 1, /* Useless, never set or used */
+ optind = 1, /* Index into parent argv vector */
+ optopt; /* Character checked for validity */
+char *optarg; /* Argument associated with option */
+
+#define BADCH (int) '?'
+#define EMSG ""
+
+#define tell(s) \
+do { \
+ fputs(*nargv, stderr); \
+ fputs(s, stderr); \
+ fputc(optopt, stderr); \
+ fputc('\n', stderr); \
+ return BADCH; \
+} while (0)
+
+/*
+ * getopt
+ *
+ * Parses command line flags and arguments. Given the original arguments
+ * via the (nargc, nargv) tuple, and a list of flags via 'ostr', it returns
+ * the next flag recognized, and sets the externally visible 'optarg'
+ * variable to point to the start of the flags's parameter, if any expected.
+ *
+ * When facing an invalid flag, getopt() returns '?'.
+ *
+ * The 'ostr' string is a list of allowed flag characters, optionally by ':'
+ * when the flag expects a parameter, which can immediately follow the
+ * flag or come as the next word.
+ *
+ * In any case, the 'optopt' variable is set upon return to the flag being
+ * looked at, whether it was a valid flag or not.
+ */
+V_FUNC(int getopt, (nargc, nargv, ostr)
+ int nargc /* Argument count */ NXT_ARG
+ char **nargv /* Argument vector */ NXT_ARG
+ char *ostr /* String specifying options */)
+{
+ static char *place = EMSG; /* Option letter processing */
+ register1 char *oli; /* Option letter list index */
+
+ /*
+ * Update scanning pointer.
+ */
+
+ if (!*place) {
+ if(
+ optind >= nargc ||
+ *(place = nargv[optind]) != '-' ||
+ !*++place
+ )
+ return EOF;
+ if (*place == '-') { /* Found "--", end option processing */
+ ++optind;
+ return EOF;
+ }
+ }
+
+ /*
+ * Is option letter OK?
+ */
+
+ if (
+ (optopt = (int)*place++) == (int)':' ||
+ !(oli = index(ostr,optopt))
+ ) {
+ if (!*place) ++optind;
+ tell(": illegal option -- ");
+ }
+
+ /*
+ * Found a valid option, process it.
+ */
+
+ if (*++oli != ':') { /* Don't need argument */
+ optarg = NULL;
+ if (!*place) ++optind;
+ } else { /* Need an argument */
+ if (*place) optarg = place; /* No white space */
+ else if (nargc <= ++optind) { /* No argument */
+ place = EMSG;
+ tell(": option requires an argument -- ");
+ } else
+ optarg = nargv[optind]; /* White space */
+ place = EMSG;
+ ++optind;
+ }
+
+ return optopt; /* Dump back option letter */
+}
+#endif
+
diff --git a/lib/C/fake/rename.C b/lib/C/fake/rename.C
new file mode 100644
index 0000000..b1457d8
--- /dev/null
+++ b/lib/C/fake/rename.C
@@ -0,0 +1,45 @@
+/*
+ * rename.C -- A rename emulation, for renaming files only.
+ */
+
+/*
+ * $Id: rename.C,v 3.0.1.1 1994/01/24 13:58:42 ram Exp $
+ *
+ * Copyright (c) 1991-1993, Raphael Manfredi
+ *
+ * You may redistribute only under the terms of the Artistic Licence,
+ * as specified in the README file that comes with the distribution.
+ * You may reuse parts of this distribution only within the terms of
+ * that same Artistic Licence; a copy of which may be found at the root
+ * of the source tree for dist 3.0.
+ *
+ * $Log: rename.C,v $
+ * Revision 3.0.1.1 1994/01/24 13:58:42 ram
+ * patch16: created
+ *
+ */
+
+#include "config.h"
+#include "confmagic.h" /* Remove if not metaconfig -M */
+
+#ifndef HAS_RENAME
+/*
+ * rename
+ *
+ * Renames a file within a file system. This cannot be used to rename
+ * directories, unfortunately.
+ */
+V_FUNC(int rename, (from, to),
+ char *from /* Original name */ NXT_ARG
+ char *to /* Target name */)
+{
+ (void) unlink(to);
+ if (-1 == link(from, to))
+ return -1;
+ if (-1 == unlink(from))
+ return -1;
+
+ return 0;
+}
+#endif
+
diff --git a/lib/C/fake/scandir.C b/lib/C/fake/scandir.C
new file mode 100644
index 0000000..b74d4ee
--- /dev/null
+++ b/lib/C/fake/scandir.C
@@ -0,0 +1,131 @@
+/*
+ * scandir.C -- A scandir implementation.
+ */
+
+/*
+ * $Id: scandir.C,v 3.0.1.1 1994/01/24 13:58:45 ram Exp $
+ *
+ * Copyright (c) 1991-1993, Raphael Manfredi
+ *
+ * You may redistribute only under the terms of the Artistic Licence,
+ * as specified in the README file that comes with the distribution.
+ * You may reuse parts of this distribution only within the terms of
+ * that same Artistic Licence; a copy of which may be found at the root
+ * of the source tree for dist 3.0.
+ *
+ * $Log: scandir.C,v $
+ * Revision 3.0.1.1 1994/01/24 13:58:45 ram
+ * patch16: created
+ *
+ */
+
+#include "config.h"
+
+#ifdef I_STRING
+#include <string.h>
+#else
+#include <strings.h>
+#endif
+
+#ifdef I_DIRENT
+#include <dirent.h>
+#else
+#ifdef I_SYS_NDIR
+#include <sys/ndir.h>
+#else
+#ifdef I_SYS_DIR
+#include <sys/dir.h>
+#endif
+#endif
+#endif
+
+#include "confmagic.h" /* Remove if not metaconfig -M */
+
+#ifndef HAS_SCANDIR
+
+extern Malloc_t malloc();
+extern Malloc_t realloc();
+
+extern DIR *opendir();
+extern Direntry_t *readdir();
+
+#define DIR_NULL ((DIR *) 0)
+#define ENTRY_NULL ((Direntry_t *) 0)
+
+static int alphasort _((Direntry_t **, Direntry_t **));
+
+/*
+ * scandir
+ *
+ * This routine reads the directory `dirnam' and builds an array of
+ * pointers to directory entries using malloc(). The second parameter
+ * is the address of a pointer to an array of structure pointers. The
+ * third parameter is a pointer to a routine which is called with a
+ * pointer to a directory entry and should return a non zero value
+ * if the directory entry should be included in the arrary. If this
+ * pointer is NULL, then all the directory entries will be included.
+ * The last argument is a pointer to a routine which is passed to
+ * qsort() to sort the completed array. If this pointer is NULL, the
+ * array is not sorted.
+ * scandir() returns the number of entries in the array and a pointer
+ * to the array through the parameter namlist.
+ * alphasort() is a routine which sorts the array alphabetically.
+ */
+V_FUNC(int scandir, (dirnam, namelist, sel, comp),
+ char *dirnam /* Direcotry name */ NXT_ARG
+ Direntry_t ***namelist /* Pointer to an array of struct ptrs */ NXT_ARG
+ int (*sel)() /* Routine to select entries */ NXT_ARG
+ int (*comp)() /* Routine passed to qsort */)
+{
+ DIR *dirp; /* Returned by opendir() */
+ Direntry_t *dp; /* Read entry */
+ Direntry_t *dp_save; /* Place where entry is stored */
+ Direntry_t **tmplist; /* Where the array list is stored */
+ int nent = 0; /* Number of entries */
+
+ dirp = opendir(dirnam);
+ if (dirp == DIR_NULL)
+ return -1; /* Directory cannot be opened for reading */
+
+ for (dp = readdir(dirp); dp != ENTRY_NULL; dp = readdir(dirp)) {
+ if (sel == ((int (*)()) 0) || (*sel)(dp)) {
+ /* If entry has to be included */
+ nent++; /* One more entry */
+
+ if (nent == 1) { /* Create array for first entry */
+ tmplist = (Direntry_t **)
+ malloc(sizeof(Direntry_t *));
+ if (tmplist == (Direntry_t **) 0)
+ return -1; /* Cannot create array */
+ } else { /* Reallocate for a new entry */
+ tmplist = (Direntry_t **)
+ realloc(tmplist, nent*sizeof(Direntry_t *));
+ if (tmplist == (Direntry_t **) 0)
+ return -1; /* Cannot reallocate array */
+ }
+
+ dp_save = (Direntry_t *) malloc(sizeof(Direntry_t));
+ if (dp_save == ENTRY_NULL)
+ return -1; /* No space to save entry */
+ bcopy((char *) dp, (char *) dp_save, sizeof(Direntry_t));
+ *(tmplist+(nent-1)) = dp_save;
+ }
+ }
+
+ if (comp != ((int (*)()) 0) && nent) /* Need sorting ? */
+ qsort(tmplist, nent, sizeof(Direntry_t *), comp);
+
+ *namelist = tmplist; /* Passes the address of the arrray */
+ closedir(dirp); /* Close directory */
+
+ return nent; /* Number of items */
+}
+
+P_FUNC(int alphasort, (d1, d2),
+ Direntry_t **d1 NXT_ARG Direntry_t **d2)
+{
+ return strcmp((*d1)->d_name, (*d2)->d_name);
+}
+
+#endif
+
diff --git a/lib/C/fake/setsid.C b/lib/C/fake/setsid.C
new file mode 100644
index 0000000..58611b8
--- /dev/null
+++ b/lib/C/fake/setsid.C
@@ -0,0 +1,64 @@
+/*
+ * setsid.C -- A setsid replacement.
+ */
+
+/*
+ * $Id: setsid.C,v 3.0.1.1 1994/01/24 13:58:47 ram Exp $
+ *
+ * Copyright (c) 1991-1993, Raphael Manfredi
+ *
+ * You may redistribute only under the terms of the Artistic Licence,
+ * as specified in the README file that comes with the distribution.
+ * You may reuse parts of this distribution only within the terms of
+ * that same Artistic Licence; a copy of which may be found at the root
+ * of the source tree for dist 3.0.
+ *
+ * $Log: setsid.C,v $
+ * Revision 3.0.1.1 1994/01/24 13:58:47 ram
+ * patch16: created
+ *
+ */
+
+#include "config.h"
+#include "confmagic.h" /* Remove if not metaconfig -M */
+
+#ifndef HAS_SETSID
+/*
+ * setsid
+ *
+ * Set the process group ID and create a new session for the process.
+ *
+ * This is a pale imitation of the setsid() system call, since a session
+ * and a process group are two distinct things for the kernel. However,
+ * when setsid() is not available, the effects should be comparable.
+ */
+V_FUNC_VOID(int setsid)
+{
+ int error = 0;
+
+#ifdef HAS_SETPGID
+ /*
+ * setpgid() supersedes setpgrp() in OSF/1.
+ */
+ error = setpgid(0 ,getpid());
+#else
+#ifdef HAS_SETPGRP
+ /*
+ * Good old way to get a process group leader.
+ */
+#ifdef USE_BSDPGRP
+ error = setpgrp(0 ,getpid()); /* bsd way */
+#else
+ error = setpgrp(); /* usg way */
+#endif
+#endif
+#endif
+
+ /*
+ * When none of the above is defined, do nothing.
+ */
+
+ return error;
+}
+#endif
+