aboutsummaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authorStefan Hoffmann <stefan991@gmail.com>2014-03-03 20:02:32 +0100
committerThiago de Arruda <tpadilha84@gmail.com>2014-03-06 13:38:45 -0300
commitf2433aedc86db171d5616410605cf0d398d8fdc2 (patch)
tree2df40baf1dce2b9e6e6dc175f66cfff41d7bd6ad /src/os_unix.c
parentfc8686640250561156913387c62924d2bdb5e1ac (diff)
downloadrneovim-f2433aedc86db171d5616410605cf0d398d8fdc2.tar.gz
rneovim-f2433aedc86db171d5616410605cf0d398d8fdc2.tar.bz2
rneovim-f2433aedc86db171d5616410605cf0d398d8fdc2.zip
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
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c33
1 files changed, 7 insertions, 26 deletions
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