From f2433aedc86db171d5616410605cf0d398d8fdc2 Mon Sep 17 00:00:00 2001 From: Stefan Hoffmann Date: Mon, 3 Mar 2014 20:02:32 +0100 Subject: cleanup environment variable handling + unit tests * removed a putenv() implementation which isn't needed anymore * mch_getenv() and mch_setenv() are now functions in src/os/env.c * removes direct calls to getenv() and setenv() outside of src/os/env.c * refactored the logic of get_env_name into mch_getenvname_at_index * added unittests for the functions in os/env.c --- src/os_unix.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) (limited to 'src/os_unix.c') diff --git a/src/os_unix.c b/src/os_unix.c index 40eba52da8..5a01f07c36 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -1349,7 +1349,7 @@ int mch_can_exe(char_u *name) name[2] == '/')))) return executable_file(name); - p = (char_u *)getenv("PATH"); + p = (char_u *)mch_getenv("PATH"); if (p == NULL || *p == NUL) return -1; buf = alloc((unsigned)(STRLEN(name) + STRLEN(p) + 2)); @@ -1837,9 +1837,9 @@ int mch_get_shellsize() { * the ioctl() values! */ if (columns == 0 || rows == 0 || vim_strchr(p_cpo, CPO_TSIZE) != NULL) { - if ((p = (char_u *)getenv("LINES"))) + if ((p = (char_u *)mch_getenv("LINES"))) rows = atoi((char *)p); - if ((p = (char_u *)getenv("COLUMNS"))) + if ((p = (char_u *)mch_getenv("COLUMNS"))) columns = atoi((char *)p); } @@ -1950,12 +1950,7 @@ int options; /* SHELL_*, see vim.h */ int fd_toshell[2]; /* for pipes */ int fd_fromshell[2]; int pipe_error = FALSE; -# ifdef HAVE_SETENV char envbuf[50]; -# else - static char envbuf_Rows[20]; - static char envbuf_Columns[20]; -# endif int did_settmode = FALSE; /* settmode(TMODE_RAW) called */ newcmd = vim_strsave(p_sh); @@ -2125,27 +2120,13 @@ int options; /* SHELL_*, see vim.h */ } # endif /* Simulate to have a dumb terminal (for now) */ -# ifdef HAVE_SETENV - setenv("TERM", "dumb", 1); + mch_setenv("TERM", "dumb", 1); sprintf((char *)envbuf, "%ld", Rows); - setenv("ROWS", (char *)envbuf, 1); + mch_setenv("ROWS", (char *)envbuf, 1); sprintf((char *)envbuf, "%ld", Rows); - setenv("LINES", (char *)envbuf, 1); + mch_setenv("LINES", (char *)envbuf, 1); sprintf((char *)envbuf, "%ld", Columns); - setenv("COLUMNS", (char *)envbuf, 1); -# else - /* - * Putenv does not copy the string, it has to remain valid. - * Use a static array to avoid losing allocated memory. - */ - putenv("TERM=dumb"); - sprintf(envbuf_Rows, "ROWS=%ld", Rows); - putenv(envbuf_Rows); - sprintf(envbuf_Rows, "LINES=%ld", Rows); - putenv(envbuf_Rows); - sprintf(envbuf_Columns, "COLUMNS=%ld", Columns); - putenv(envbuf_Columns); -# endif + mch_setenv("COLUMNS", (char *)envbuf, 1); /* * stderr is only redirected when using the GUI, so that a -- cgit