From d6b1ac7faa1f6c7a9e655add93dc8a31bfbc44df Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Thu, 7 Sep 2006 20:42:53 +0000 Subject: [PATCH] * environ.cc (build_env): Don't put an empty environment variable into the environment. Optimize use of "len". * errno.cc (ERROR_MORE_DATA): Translate to EMSGSIZE rather than EAGAIN. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/environ.cc | 13 +++++++------ winsup/cygwin/errno.cc | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 0982043ab..bdf457235 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2006-09-07 Christopher Faylor + + * environ.cc (build_env): Don't put an empty environment variable into + the environment. Optimize use of "len". + * errno.cc (ERROR_MORE_DATA): Translate to EMSGSIZE rather than EAGAIN. + 2006-08-31 Corinna Vinschen * grp.cc (initgroups32): Run get_server_groups under original token. diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc index c11a657d2..58b1e5070 100644 --- a/winsup/cygwin/environ.cc +++ b/winsup/cygwin/environ.cc @@ -1064,30 +1064,31 @@ build_env (const char * const *envp, char *&envblock, int &envc, const char *p; win_env *conv; len = strcspn (*srcp, "=") + 1; + const char *rest = *srcp + len; /* Check for a bad entry. This is necessary to get rid of empty strings, induced by putenv and changing the string afterwards. Note that this doesn't stop invalid strings without '=' in it etc., but we're opting for speed here for now. Adding complete checking would be pretty expensive. */ - if (len == 1) + if (len == 1 || !*rest) continue; /* See if this entry requires posix->win32 conversion. */ - conv = getwinenv (*srcp, *srcp + len, &temp); + conv = getwinenv (*srcp, rest, &temp); if (conv) p = conv->native; /* Use win32 path */ else p = *srcp; /* Don't worry about it */ - len = strlen (p); + len = strlen (p) + 1; if (len >= 32 * 1024) { free (envblock); envblock = NULL; goto out; } - new_tl += len + 1; /* Keep running total of block length so far */ + new_tl += len; /* Keep running total of block length so far */ /* See if we need to increase the size of the block. */ if (new_tl > tl) @@ -1103,7 +1104,7 @@ build_env (const char * const *envp, char *&envblock, int &envc, } } - memcpy (s, p, len + 1); + memcpy (s, p, len); /* See if environment variable is "special" in a Windows sense. Under NT, the current directories for visited drives are stored @@ -1112,7 +1113,7 @@ build_env (const char * const *envp, char *&envblock, int &envc, if (s[0] == '!' && (isdrive (s + 1) || (s[1] == ':' && s[2] == ':')) && s[3] == '=') *s = '='; - s += len + 1; + s += len; } *s = '\0'; /* Two null bytes at the end */ assert ((s - envblock) <= tl); /* Detect if we somehow ran over end diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc index e8beaa273..50819a952 100644 --- a/winsup/cygwin/errno.cc +++ b/winsup/cygwin/errno.cc @@ -87,7 +87,7 @@ static NO_COPY struct X (MAX_THRDS_REACHED, EAGAIN), X (META_EXPANSION_TOO_LONG, EINVAL), X (MOD_NOT_FOUND, ENOENT), - X (MORE_DATA, EAGAIN), + X (MORE_DATA, EMSGSIZE), X (NEGATIVE_SEEK, EINVAL), X (NETNAME_DELETED, ENOSHARE), X (NOACCESS, EFAULT),