ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/CCSAdmin/common.c
(Generate patch)

Comparing CCSAdmin/common.c (file contents):
Revision 572 by douglas, 2005-09-25T17:43:17-07:00 vs.
Revision 652 by douglas, 2006-01-13T01:17:20-08:00

# Line 6 | Line 6
6  
7   #include "common.h"
8  
9 + #ifdef __sun__
10 + #define getpass getpassphrase
11 + #endif
12 +
13 + Shells shells[] = {
14 +        { "sh", "/bin/sh", "/bin/sh", "/bin/sh", "/usr/bin/sh" },
15 +        { "csh", "/bin/csh", "/bin/csh", "/bin/csh", "/usr/bin/csh" },
16 +        { "tcsh", "/bin/tcsh", "/bin/tcsh", "/bin/tcsh", "/usr/bin/tcsh" },
17 +        { "bash", "/usr/local/bin/bash", "/bin/bash", "/opt/local/bin/bash", "/usr/local/bin/bash" },
18 +        { "ksh", "/usr/local/bin/ksh", "/bin/ksh", "/bin/ksh", "/usr/bin/ksh" },
19 +        { "zsh", "/usr/local/bin/zsh", "/bin/zsh", "/bin/zsh", "/usr/bin/zsh" },
20 +        { "3sh", "/ccs/bin/3sh", "/ccs/bin/3sh", "/ccs/bin/3sh", "/ccs/bin/3sh" },
21 +        { "custom", NULL, NULL, NULL, NULL }
22 + };
23 +
24   int check(int value, jmp_buf environment)
25   {
26          if (value == -1)
# Line 138 | Line 153 | void get(const char *prompt, regex_t *re
153          while (regcheck(regexec(regex, *string, 0, NULL, 0), regex, environment));
154   }
155  
156 < #ifndef __FreeBSD__
156 > void setshells(Shells *shells, jmp_buf environment)
157 > {
158 >        check(setenv("FREEBSD", shells->freebsd, 1), environment);
159 >        check(setenv("LINUX", shells->linux, 1), environment);
160 >        check(setenv("DARWIN", shells->darwin, 1), environment);
161 >        check(setenv("SOLARIS", shells->solaris, 1), environment);
162 > }
163 >
164 > #if !defined(__FreeBSD__) && !defined(__sun__)
165   size_t strlcpy(char *dst, const char *src, size_t size)
166   {
167          dst[size - 1] = '\0';
# Line 165 | Line 188 | char *fgetln(FILE * restrict stream, siz
188  
189          return line;
190   }
191 + #elif defined(__sun__)
192 + char *fgetln(FILE * restrict stream, size_t * restrict len)
193 + {
194 +        static char *line = NULL;
195 +
196 +        *len = 0;
197 +        line = line ? realloc(line, 1) : malloc(1);
198 +
199 +        while (line[*len] = getc(stream), line[(*len)++] != '\n')
200 +                if (line[*len - 1] != EOF)
201 +                        line = realloc(line, *len + 1);
202 +                else
203 +                        return NULL;
204 +
205 +        return line;
206 + }
207 +
208 + int setenv(const char *name, const char *value, int overwrite)
209 + {
210 +        char *string_ = getenv(name);
211 +
212 +        if (overwrite || !string_)
213 +        {
214 +                char *string = malloc(strlen(name) + strlen(value) + 2);
215 +
216 +                sprintf(string, "%s=%s", name, value);
217 +
218 +                int value_ = putenv(string);
219 +
220 +                if (!string_)
221 +                        free(string_);
222 +
223 +                return value_;
224 +        }
225 +
226 +        return 0;
227 + }
228   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines