-
-/* Convert a unix-style set-of-paths (a colon-separated list of directory
- paths with forward slashes) into the dos style (semicolon-separated
- list with backward slashes), simultaneously undoing any translations
- performed by the mount table. */
-
-static char *buf = NULL;
-static int blen = 2000;
-
-static char *
-unix_paths_to_dos_paths(char *newenv)
-{
- int ei;
- char *src;
-
- if (buf == 0)
- buf = (char *) malloc(blen);
-
- if (newenv == 0 || *newenv == 0 ||
- (src = strchr(newenv, '=')) == 0) /* find the equals sign */
- return 0;
-
- src++; /* now skip past it */
-
- if (src[0] == '/' || /* is this a unix style path? */
- (src[0] == '.' && src[1] == '/') ||
- (src[0] == '.' && src[1] == '.' && src[2] == '/'))
- { /* we accept that we will fail on a relative path like 'foo/mumble' */
- /* Found an env name, turn from unix style into dos style */
- int len = src - newenv;
- char *dir = buf + len;
-
- memcpy(buf, newenv, len);
- /* Split out the colons */
- while (1)
- {
- char *tok = strchr (src, ':');
- int doff = dir - buf;
-
- if (doff + MAX_PATH > blen)
- {
- blen *= 2;
- buf = (char *) realloc((void *) buf, blen);
- dir = buf + doff;
- }
- if (tok)
- {
- *tok = 0;
- cygwin32_unix_path_to_dos_path_keep_rel (src, dir);
- *tok = ':';
- dir += strlen(dir);
- src = tok + 1;
- *dir++ = ';';
- }
- else
- {
- cygwin32_unix_path_to_dos_path_keep_rel (src, dir);
- dir += strlen(dir);
- *dir++ = 0;
- break;
- }
- }
- return buf;
- }
- return 0;
-}
-
-/* Convert a dos-style set-of-paths (a semicolon-separated list with
- backward slashes) into the dos style (colon-separated list of
- directory paths with forward slashes), simultaneously undoing any
- translations performed by the mount table. */
-
-static char *
-dos_paths_to_unix_paths(char *newenv)
-{
- int ei;
- char *src;
-
- if (buf == 0)
- buf = (char *) malloc(blen);
-
- if (newenv == 0 || *newenv == 0 ||
- (src = strchr(newenv, '=')) == 0) /* find the equals sign */
- return 0;
-
- src++; /* now skip past it */
-
- if (src[0] == '\\' || /* is this a dos style path? */
- (isalpha(src[0]) && src[1] == ':' && src[2] == '\\') ||
- (src[0] == '.' && src[1] == '\\') ||
- (src[0] == '.' && src[1] == '.' && src[2] == '\\'))
- { /* we accept that we will fail on a relative path like 'foo\mumble' */
- /* Found an env name, turn from dos style into unix style */
- int len = src - newenv;
- char *dir = buf + len;
-
- memcpy(buf, newenv, len);
- /* Split out the colons */
- while (1)
- {
- char *tok = strchr (src, ';');
- int doff = dir - buf;
-
- if (doff + MAX_PATH > blen)
- {
- blen *= 2;
- buf = (char *) realloc((void *) buf, blen);
- dir = buf + doff;
- }
- if (tok)
- {
- *tok = 0;
- cygwin32_dos_path_to_unix_path_keep_rel (src, dir);
- *tok = ';';
- dir += strlen(dir);
- src = tok + 1;
- *dir++ = ':';
- }
- else
- {
- cygwin32_dos_path_to_unix_path_keep_rel (src, dir);
- dir += strlen(dir);
- *dir++ = 0;
- break;
- }
- }
- return buf;
- }
- return 0;
-}
-
-