summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorKaleb Keithley <kaleb@freedesktop.org>2003-11-14 15:54:55 +0000
committerKaleb Keithley <kaleb@freedesktop.org>2003-11-14 15:54:55 +0000
commitc8ddd5d82a72167de6e0a544b55f9b03ab93053e (patch)
tree878ae3ddd67e48798427db3d709940a664801cd0 /misc.c
R6.6 is the Xorg base-lineXORG-MAINXORG-STABLE
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c157
1 files changed, 157 insertions, 0 deletions
diff --git a/misc.c b/misc.c
new file mode 100644
index 0000000..0a33e1f
--- /dev/null
+++ b/misc.c
@@ -0,0 +1,157 @@
+/* $Xorg: misc.c,v 1.4 2001/02/09 02:06:01 xorgcvs Exp $ */
+/******************************************************************************
+
+Copyright 1993, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+******************************************************************************/
+
+#include "xsm.h"
+
+
+#ifdef NOPUTENV
+/*
+ * define our own putenv() if the system doesn't have one.
+ * putenv(s): place s (a string of the form "NAME=value") in
+ * the environment; replacing any existing NAME. s is placed in
+ * environment, so if you change s, the environment changes (like
+ * putenv on a sun). Binding removed if you putenv something else
+ * called NAME.
+ */
+int
+putenv(s)
+ char *s;
+{
+ char *v;
+ int varlen, idx;
+ extern char **environ;
+ char **newenv;
+ static int virgin = 1; /* true while "environ" is a virgin */
+
+ v = strchr(s, '=');
+ if(v == 0)
+ return 0; /* punt if it's not of the right form */
+ varlen = (v + 1) - s;
+
+ for (idx = 0; environ[idx] != 0; idx++) {
+ if (strncmp(environ[idx], s, varlen) == 0) {
+ if(v[1] != 0) { /* true if there's a value */
+ environ[idx] = s;
+ return 0;
+ } else {
+ do {
+ environ[idx] = environ[idx+1];
+ } while(environ[++idx] != 0);
+ return 0;
+ }
+ }
+ }
+
+ /* add to environment (unless no value; then just return) */
+ if(v[1] == 0)
+ return 0;
+ if(virgin) {
+ register i;
+
+ newenv = (char **) XtMalloc((unsigned) ((idx + 2) * sizeof(char*)));
+ if(newenv == 0)
+ return -1;
+ for(i = idx-1; i >= 0; --i)
+ newenv[i] = environ[i];
+ virgin = 0; /* you're not a virgin anymore, sweety */
+ } else {
+ newenv = (char **) realloc((char *) environ,
+ (unsigned) ((idx + 2) * sizeof(char*)));
+ if (newenv == 0)
+ return -1;
+ }
+
+ environ = newenv;
+ environ[idx] = s;
+ environ[idx+1] = 0;
+
+ return 0;
+}
+
+#endif /* NOPUTENV */
+
+
+
+strbw (a, b)
+
+char *a;
+char *b;
+
+{
+ return !strncmp (a, b, strlen (b));
+}
+
+
+
+#ifdef X_NOT_STDC_ENV
+
+char *Strstr (s1, s2)
+
+char *s1;
+char *s2;
+
+{
+ int n1, n2;
+
+ n1 = strlen (s1);
+ n2 = strlen (s2);
+
+ for (; n1 >= n2; s1++, n1--)
+ {
+ if (!strncmp (s1, s2, n2))
+ return s1;
+ }
+
+ return NULL;
+}
+
+#endif
+
+
+
+#if defined(sun) && defined(SVR4)
+int System (s)
+ char *s;
+{
+ int pid, status;
+ if ((pid = fork ()) == 0) {
+ (void) setpgrp();
+ execl ("/bin/sh", "sh", "-c", s, 0);
+ } else
+ waitpid (pid, &status, 0);
+ return status;
+}
+#endif
+
+
+
+nomem ()
+
+{
+ fprintf (stderr, "Insufficient memory.\n");
+ exit (255);
+}
+