Move environment functions from spawn-pipe.c to compat/mingw.c

We want to get rid of spawn-pipe.*, but these functions will be needed.

On the way, the function signature was changed to avoid warnings about
incompatible pointer types when the argument is the global variable
"environ".
This commit is contained in:
Johannes Sixt
2007-11-18 20:22:04 +01:00
parent 3deda75919
commit f8fd915d0c
4 changed files with 43 additions and 42 deletions

View File

@@ -536,6 +536,45 @@ void mingw_execvp(const char *cmd, const char **argv)
mingw_free_path_split(path);
}
char **copy_environ()
{
return copy_env(environ);
}
char **copy_env(char **env)
{
char **s;
int n = 1;
for (s = env; *s; s++)
n++;
s = xmalloc(n*sizeof(char *));
memcpy(s, env, n*sizeof(char *));
return s;
}
void env_unsetenv(char **env, const char *name)
{
int src, dst;
size_t nmln;
nmln = strlen(name);
for (src = dst = 0; env[src]; ++src) {
size_t enln;
enln = strlen(env[src]);
if (enln > nmln) {
/* might match, and can test for '=' safely */
if (0 == strncmp (env[src], name, nmln)
&& '=' == env[src][nmln])
/* matches, so skip */
continue;
}
env[dst] = env[src];
++dst;
}
env[dst] = NULL;
}
int mingw_socket(int domain, int type, int protocol)
{
SOCKET s = WSASocket(domain, type, protocol, NULL, 0, 0);

View File

@@ -473,6 +473,10 @@ static inline int waitpid(pid_t pid, unsigned *status, unsigned options)
#define SIGCHLD 0
#define SIGPIPE 0
char **copy_environ();
char **copy_env(char **env);
void env_unsetenv(char **env, const char *name);
unsigned int sleep (unsigned int __seconds);
const char *inet_ntop(int af, const void *src,
char *dst, size_t cnt);

View File

@@ -129,42 +129,3 @@ int spawnvppe_pipe(const char *cmd, const char **argv, const char **env,
return pid;
}
const char **copy_environ()
{
return copy_env(environ);
}
const char **copy_env(const char **env)
{
const char **s;
int n = 1;
for (s = env; *s; s++)
n++;
s = xmalloc(n*sizeof(const char *));
memcpy(s, env, n*sizeof(const char *));
return s;
}
void env_unsetenv(const char **env, const char *name)
{
int src, dst;
size_t nmln;
nmln = strlen(name);
for (src = dst = 0; env[src]; ++src) {
size_t enln;
enln = strlen(env[src]);
if (enln > nmln) {
/* might match, and can test for '=' safely */
if (0 == strncmp (env[src], name, nmln)
&& '=' == env[src][nmln])
/* matches, so skip */
continue;
}
env[dst] = env[src];
++dst;
}
env[dst] = NULL;
}

View File

@@ -1,5 +1,2 @@
int spawnvppe_pipe(const char *cmd, const char **argv, const char **env, char **path, int pin[], int pout[]);
int spawnvpe_pipe(const char *cmd, const char **argv, const char **env, int pin[], int pout[]);
const char **copy_environ();
const char **copy_env(const char **env);
void env_unsetenv(const char **env, const char *name);