diff options
author | simonmar <unknown> | 1999-11-26 16:29:44 +0000 |
---|---|---|
committer | simonmar <unknown> | 1999-11-26 16:29:44 +0000 |
commit | 7700dda03d273676b274bc148491a4e02a7c5ae0 (patch) | |
tree | 09de9743e3b9f9c7a4108660230969ce893947df /ghc/lib/posix/cbits | |
parent | ef33ed94129ee17b577add392e04619ec1f53800 (diff) | |
download | haskell-7700dda03d273676b274bc148491a4e02a7c5ae0.tar.gz |
[project @ 1999-11-26 16:29:09 by simonmar]
GHC bits for new library organisation.
Diffstat (limited to 'ghc/lib/posix/cbits')
-rw-r--r-- | ghc/lib/posix/cbits/Makefile | 17 | ||||
-rw-r--r-- | ghc/lib/posix/cbits/env.c | 164 | ||||
-rw-r--r-- | ghc/lib/posix/cbits/execvpe.c | 153 | ||||
-rw-r--r-- | ghc/lib/posix/cbits/libposix.h | 77 | ||||
-rw-r--r-- | ghc/lib/posix/cbits/signal.c | 29 |
5 files changed, 0 insertions, 440 deletions
diff --git a/ghc/lib/posix/cbits/Makefile b/ghc/lib/posix/cbits/Makefile deleted file mode 100644 index 86fa034f02..0000000000 --- a/ghc/lib/posix/cbits/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# -# Makefile for cbits subdirectory -# -TOP=../../.. -include $(TOP)/mk/boilerplate.mk -override WAYS= - -# Hack! -SRC_CC_OPTS += -I$(GHC_INCLUDE_DIR) - -CC=$(GHC) -C_SRCS=$(wildcard *.c) -LIBRARY=libHSposix_cbits.a -LIBOBJS=$(C_OBJS) -INSTALL_LIBS += $(LIBRARY) - -include $(TOP)/mk/target.mk diff --git a/ghc/lib/posix/cbits/env.c b/ghc/lib/posix/cbits/env.c deleted file mode 100644 index baf7f95800..0000000000 --- a/ghc/lib/posix/cbits/env.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - * (c) The GRASP/AQUA Project, Glasgow University, 1995-1996 - * - * \subsection[env.lc]{Environment Handling for LibPosix} - * - * Many useful environment functions are not necessarily provided by libc. - * To get around this problem, we introduce our own. The first time that - * you modify your environment, we copy the environment wholesale into - * malloc'ed locations, so that subsequent modifications can do proper - * memory management. The $environ$ variable is updated with a pointer - * to the current environment so that the normal $getenv$ and $exec*$ functions - * should continue to work properly. - */ - -#include "Rts.h" -#include "libposix.h" - -/* Switch this on once we've moved the environment to the malloc arena */ -int dirtyEnv = 0; - -/* - * For some reason, OSF turns off the prototype for this if we're - * _POSIX_SOURCE. Seems to me that this ought to be an ANSI-ism - * rather than a POSIX-ism, but no matter. (JSM(?)) - */ - -char * -strDup(const char *src) -{ - int len = strlen(src) + 1; - char *dst; - - if ((dst = malloc(len)) != NULL) - memcpy(dst, src, len); - return dst; -} - -/* Replace the entire environment */ -int -setenviron(char **envp) -{ - char **old = environ; - int dirtyOld = dirtyEnv; - int i; - - /* A quick hack to move the strings out of the heap */ - environ = envp; - if (copyenv() != 0) { - environ = old; - return -1; - } - /* Release the old space if we allocated it ourselves earlier */ - if (dirtyOld) { - for (i = 0; old[i] != NULL; i++) - free(old[i]); - free(old); - } - return 0; -} - -/* Copy initial environment into malloc arena */ -int -copyenv(void) -{ - char **new; - int i; - - for (i = 0; environ[i] != NULL; i++) - ; - - if ((new = (char **) malloc((i + 1) * sizeof(char *))) == NULL) - return -1; - - new[i] = NULL; - - while (--i >= 0) { - if ((new[i] = strDup(environ[i])) == NULL) { - while (new[++i] != NULL) - free(new[i]); - free(new); - return -1; - } - } - environ = new; - dirtyEnv = 1; - return 0; -} - -/* Set or replace an environment variable - * simonm 14/2/96 - this is different to the standard C library - * implementation and the prototypes clash, so I'm calling it _setenv. - */ -int -_setenv(char *mapping) -{ - int i, keylen; - char *p; - char **new; - - /* We must have a non-empty key and an '=' */ - if (mapping[0] == '=' || (p = strchr(mapping, '=')) == NULL) { - errno = EINVAL; - return -1; - } - /* Include through the '=' for matching */ - keylen = p - mapping + 1; - - if (!dirtyEnv && copyenv() != 0) - return -1; - - if ((p = strDup(mapping)) == NULL) - return -1; - - /* Look for an existing key that matches */ - for (i = 0; environ[i] != NULL && strncmp(environ[i], p, keylen) != 0; i++); - - if (environ[i] != NULL) { - free(environ[i]); - environ[i] = p; - } else { - /* We want to grow the table by *two*, one for the new entry, one for the terminator */ - if ((new = (char **) realloc((void*)environ, (i + 2) * sizeof(char *))) == NULL) { - free(p); - return -1; - } - new[i] = p; - new[i + 1] = NULL; - environ = new; - } - return 0; -} - -/* Delete a variable from the environment */ -int -delenv(char *name) -{ - int i, keylen; - - if (strchr(name, '=') != NULL) { - errno = EINVAL; - return -1; - } - keylen = strlen(name); - - if (!dirtyEnv && copyenv() != 0) - return -1; - - /* Look for a matching key */ - for (i = 0; environ[i] != NULL && - (strncmp(environ[i], name, keylen) != 0 || environ[i][keylen] != '='); i++); - - /* Don't complain if it wasn't there to begin with */ - if (environ[i] == NULL) { - return 0; - } - free(environ[i]); - - do { - environ[i] = environ[i + 1]; - i++; - } while (environ[i] != NULL); - - return 0; -} diff --git a/ghc/lib/posix/cbits/execvpe.c b/ghc/lib/posix/cbits/execvpe.c deleted file mode 100644 index 2c3287ec39..0000000000 --- a/ghc/lib/posix/cbits/execvpe.c +++ /dev/null @@ -1,153 +0,0 @@ -/* -% -% (c) The GRASP/AQUA Project, Glasgow University, 1995-1996 -% -\subsection[posix.lc]{executeFile Runtime Support} - -\begin{code} -*/ -#if !defined(_AIX) -#define NON_POSIX_SOURCE -#endif - -#include "Rts.h" -#include "libposix.h" - -/* - * We want the search semantics of execvp, but we want to provide our - * own environment, like execve. The following copyright applies to - * this code, as it is a derivative of execvp: - *- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -int -execvpe(char *name, char **argv, char **envp) -{ - register int lp, ln; - register char *p; - int eacces, etxtbsy; - char *bp, *cur, *path, *buf; - - /* If it's an absolute or relative path name, it's easy. */ - if (strchr(name, '/')) { - bp = (char *) name; - cur = path = buf = NULL; - goto retry; - } - - /* Get the path we're searching. */ - if (!(path = getenv("PATH"))) { -#ifdef HAVE_CONFSTR - ln = confstr(_CS_PATH, NULL, 0); - if ((cur = path = malloc(ln + 1)) != NULL) { - path[0] = ':'; - (void) confstr (_CS_PATH, path + 1, ln); - } -#else - if ((cur = path = malloc(1 + 1)) != NULL) { - path[0] = ':'; - path[1] = '\0'; - } -#endif - } else - cur = path = strDup(path); - - if (path == NULL || (bp = buf = malloc(strlen(path)+strlen(name)+2)) == NULL) - goto done; - - eacces = etxtbsy = 0; - while (cur != NULL) { - p = cur; - if ((cur = strchr(cur, ':')) != NULL) - *cur++ = '\0'; - - /* - * It's a SHELL path -- double, leading and trailing colons mean the current - * directory. - */ - if (!*p) { - p = "."; - lp = 1; - } else - lp = strlen(p); - ln = strlen(name); - - memcpy(buf, p, lp); - buf[lp] = '/'; - memcpy(buf + lp + 1, name, ln); - buf[lp + ln + 1] = '\0'; - - retry: - (void) execve(bp, argv, envp); - switch (errno) { - case EACCES: - eacces = 1; - break; - case ENOENT: - break; - case ENOEXEC: - { - register size_t cnt; - register char **ap; - - for (cnt = 0, ap = (char **) argv; *ap; ++ap, ++cnt) - ; - if ((ap = malloc((cnt + 2) * sizeof(char *))) != NULL) { - memcpy(ap + 2, argv + 1, cnt * sizeof(char *)); - - ap[0] = "sh"; - ap[1] = bp; - (void) execve("/bin/sh", ap, envp); - free(ap); - } - goto done; - } - case ETXTBSY: - if (etxtbsy < 3) - (void) sleep(++etxtbsy); - goto retry; - default: - goto done; - } - } - if (eacces) - errno = EACCES; - else if (!errno) - errno = ENOENT; - done: - if (path) - free(path); - if (buf) - free(buf); - return (-1); -} diff --git a/ghc/lib/posix/cbits/libposix.h b/ghc/lib/posix/cbits/libposix.h deleted file mode 100644 index 02206d11a7..0000000000 --- a/ghc/lib/posix/cbits/libposix.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef LIBPOSIX_H -#ifdef HAVE_SYS_WAIT_H -#include <sys/wait.h> -#endif /* HAVE_SYS_WAIT_H */ - -#ifdef HAVE_SIGNAL_H -#include <signal.h> -#endif /* HAVE_SIGNAL_H */ - -#ifdef HAVE_SYS_UTSNAME_H -#include <sys/utsname.h> -#endif /* HAVE_SYS_UTSNAME_H */ - -#ifdef HAVE_SYS_TIMES_H -#include <sys/times.h> -#endif /* HAVE_SYS_TIMES_H */ - -#ifdef HAVE_DIRENT_H -#include <dirent.h> -#endif /* HAVE_DIRENT_H */ - -#ifdef HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif /* HAVE_SYS_STAT_H */ - -#ifdef HAVE_FCNTL_H -#include <fcntl.h> -#endif /* HAVE_FCNTL_H */ - -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif /* HAVE_UNISTD_H */ - -#ifdef HAVE_UTIME_H -#include <utime.h> -#endif /* HAVE_UTIME_H */ - -#ifdef HAVE_TERMIOS_H -#include <termios.h> -#endif /* HAVE_TERMIOS_H */ - -#ifdef HAVE_GRP_H -#include <grp.h> -#endif /* HAVE_GRP_H */ - -#ifdef HAVE_PWD_H -#include <pwd.h> -#endif /* HAVE_PWD_H */ - -#if TIME_WITH_SYS_TIME -# include <sys/time.h> -# include <time.h> -#else -# if HAVE_SYS_TIME_H -# include <sys/time.h> -# else -# include <time.h> -# endif -#endif - -#ifndef _POSIX_VDISABLE -#define _POSIX_VDISABLE '\0' /* Just a guess...but it works for Suns */ -#endif - -extern I_ nocldstop; - -char *strDup (const char *); -int setenviron (char **); -int copyenv (void); -int _setenv (char *); -int delenv (char *); -int execvpe (char *, char **, char **); -void stg_sigaddset(StgByteArray newset, StgByteArray oldset, int signum); -void stg_sigdelset(StgByteArray newset, StgByteArray oldset, int signum); - -#define LIBPOSIX_H -#endif diff --git a/ghc/lib/posix/cbits/signal.c b/ghc/lib/posix/cbits/signal.c deleted file mode 100644 index e4d71127f0..0000000000 --- a/ghc/lib/posix/cbits/signal.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * (c) Juan Quintela, Universidade da Corunha 1998 - * - * wrappers for signal funcions - * - * sigset_t is a struct in some UNIXes (LINUX/glibc for instance) - * and it is not posible to do the inline (_casm_). These functions - * aren't inline because it causes gcc to run out of registers on x86. - * - * Ugly casting added by SUP to avoid C compiler warnings about - * incompatible pointer types. - */ - -#include "Rts.h" -#include "libposix.h" - -void -stg_sigaddset(StgByteArray newset, StgByteArray oldset, int signum) -{ - *((sigset_t *)newset) = *((sigset_t *)oldset); - sigaddset((sigset_t *)newset, signum); -} - -void -stg_sigdelset(StgByteArray newset, StgByteArray oldset, int signum) -{ - *((sigset_t *)newset) = *((sigset_t *)oldset); - sigdelset((sigset_t *)newset, signum); -} |