1 /* $Id: util2.c,v 3.6 1994/10/28 11:11:11 davison Trn $
2 */
3 /* This software is Copyright 1991 by Stan Barber.
4 *
5 * Permission is hereby granted to copy, reproduce, redistribute or otherwise
6 * use this software as long as: there is no monetary profit gained
7 * specifically from the use or reproduction of this software, it is not
8 * sold, rented, traded or otherwise marketed, and this copyright notice is
9 * included prominently in any copy made.
10 *
11 * The authors make no claims as to the fitness or correctness of this software
12 * for any use whatsoever, and it is provided as is. Any use of this software
13 * is at the user's own risk.
14 */
15
16 #include "EXTERN.h"
17 #include "common.h"
18 #include "nntp.h"
19 #include "nntpauth.h"
20 #include "util.h"
21 #include "INTERN.h"
22 #include "util2.h"
23
24 /* return ptr to little string in big string, NULL if not found */
25
26 char *
instr(big,little,case_matters)27 instr(big, little, case_matters)
28 char *big, *little;
29 bool_int case_matters;
30 {
31 register char *t, *s, *x;
32
33 for (t = big; *t; t++) {
34 for (x=t,s=little; *s; x++,s++) {
35 if (!*x)
36 return Nullch;
37 if (case_matters == TRUE) {
38 if(*s != *x)
39 break;
40 } else {
41 register char c,d;
42 if (isupper(*s))
43 c = tolower(*s);
44 else
45 c = *s;
46 if (isupper(*x))
47 d = tolower(*x);
48 else
49 d = *x;
50 if ( c != d )
51 break;
52 }
53 }
54 if (!*s)
55 return t;
56 }
57 return Nullch;
58 }
59
60 #ifdef SETENV
61 static bool firstexport = TRUE;
62 extern char **environ;
63
64 void
export(nam,val)65 export(nam,val)
66 char *nam, *val;
67 {
68 register int i=envix(nam); /* where does it go? */
69
70 if (!environ[i]) { /* does not exist yet */
71 if (firstexport) { /* need we copy environment? */
72 int j;
73 #ifndef lint
74 char **tmpenv = (char**) /* point our wand at memory */
75 safemalloc((MEM_SIZE) (i+2) * sizeof(char*));
76 #else
77 char **tmpenv = Null(char **);
78 #endif /* lint */
79
80 firstexport = FALSE;
81 for (j=0; j<i; j++) /* copy environment */
82 tmpenv[j] = environ[j];
83 environ = tmpenv; /* tell exec where it is now */
84 }
85 #ifndef lint
86 else
87 environ = (char**) saferealloc((char*) environ,
88 (MEM_SIZE) (i+2) * sizeof(char*));
89 /* just expand it a bit */
90 #endif /* lint */
91 environ[i+1] = Nullch; /* make sure it's null terminated */
92 }
93 environ[i] = safemalloc((MEM_SIZE) strlen(nam) + strlen(val) + 2);
94 /* this may or may not be in */
95 /* the old environ structure */
96 sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
97 }
98
99 int
envix(nam)100 envix(nam)
101 char *nam;
102 {
103 register int i, len = strlen(nam);
104
105 for (i = 0; environ[i]; i++) {
106 if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
107 break; /* strnEQ must come first to avoid */
108 } /* potential SEGV's */
109 return i;
110 }
111 #endif
112