diff options
author | 2006-07-13 15:41:48 +0000 | |
---|---|---|
committer | 2006-07-13 15:41:48 +0000 | |
commit | c221795fea5519bcbab33836da0e0bd099850e9f (patch) | |
tree | 4877c281b4922a9af93b5c3817020ef7dd5cb52b | |
parent | Add back using libsbutil.a, else libsandbox.so increase currently with at lea... (diff) | |
download | sandbox-c221795fea5519bcbab33836da0e0bd099850e9f.tar.gz sandbox-c221795fea5519bcbab33836da0e0bd099850e9f.tar.bz2 sandbox-c221795fea5519bcbab33836da0e0bd099850e9f.zip |
Split out util functions.
Signed-off-by: Martin Schlemmer <azarah@gentoo.org>
-rw-r--r-- | libsbutil/Makefile.am | 13 | ||||
-rw-r--r-- | libsbutil/get_sandbox_debug_log.c | 62 | ||||
-rw-r--r-- | libsbutil/get_sandbox_lib.c | 48 | ||||
-rw-r--r-- | libsbutil/get_sandbox_log.c | 62 | ||||
-rw-r--r-- | libsbutil/get_sandbox_rc.c | 41 | ||||
-rw-r--r-- | libsbutil/get_tmp_dir.c | 52 | ||||
-rw-r--r-- | libsbutil/is_env_off.c | 42 | ||||
-rw-r--r-- | libsbutil/is_env_on.c | 42 | ||||
-rw-r--r-- | libsbutil/sb_close.c | 53 | ||||
-rw-r--r-- | libsbutil/sb_open.c (renamed from libsbutil/sbio.c) | 87 | ||||
-rw-r--r-- | libsbutil/sb_read.c | 70 | ||||
-rw-r--r-- | libsbutil/sb_write.c | 64 | ||||
-rw-r--r-- | libsbutil/sbutil.c | 137 |
13 files changed, 548 insertions, 225 deletions
diff --git a/libsbutil/Makefile.am b/libsbutil/Makefile.am index 7ca6a67..7d890d0 100644 --- a/libsbutil/Makefile.am +++ b/libsbutil/Makefile.am @@ -12,8 +12,17 @@ noinst_LTLIBRARIES = libsbutil.la libsbutil_la_SOURCES = \ sbutil.h \ - sbutil.c \ - sbio.c \ + get_sandbox_lib.c \ + get_sandbox_rc.c \ + get_sandbox_log.c \ + get_sandbox_debug_log.c \ + get_tmp_dir.c \ + is_env_on.c \ + is_env_off.c \ + sb_open.c \ + sb_read.c \ + sb_write.c \ + sb_close.c \ include/rcscripts/rctypes.h \ include/rcscripts/rcutil.h \ include/rcscripts/util/list.h \ diff --git a/libsbutil/get_sandbox_debug_log.c b/libsbutil/get_sandbox_debug_log.c new file mode 100644 index 0000000..6a9bac2 --- /dev/null +++ b/libsbutil/get_sandbox_debug_log.c @@ -0,0 +1,62 @@ +/* + * get_sandbox_debug_log.c + * + * Util functions. + * + * Copyright 1999-2006 Gentoo Foundation + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Some parts might have Copyright: + * + * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com> + * + * $Header$ + */ + + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> + +#include "sbutil.h" + +void get_sandbox_debug_log(char *path) +{ + char *sandbox_debug_log_env = NULL; + + save_errno(); + + sandbox_debug_log_env = getenv(ENV_SANDBOX_DEBUG_LOG); + + /* THIS CHUNK BREAK THINGS BY DOING THIS: + * SANDBOX_DEBUG_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log + */ + if ((NULL != sandbox_debug_log_env) && + (NULL != strchr(sandbox_debug_log_env, '/'))) + sandbox_debug_log_env = NULL; + + snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s", + SANDBOX_LOG_LOCATION, DEBUG_LOG_FILE_PREFIX, + (sandbox_debug_log_env == NULL ? "" : sandbox_debug_log_env), + (sandbox_debug_log_env == NULL ? "" : "-"), + getpid(), LOG_FILE_EXT); + + restore_errno(); +} + diff --git a/libsbutil/get_sandbox_lib.c b/libsbutil/get_sandbox_lib.c new file mode 100644 index 0000000..e93c5c9 --- /dev/null +++ b/libsbutil/get_sandbox_lib.c @@ -0,0 +1,48 @@ +/* + * get_sandbox_lib.c + * + * Util functions. + * + * Copyright 1999-2006 Gentoo Foundation + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Some parts might have Copyright: + * + * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com> + * + * $Header$ + */ + + +#include <errno.h> +#include <stdio.h> + +#include "sbutil.h" + +void get_sandbox_lib(char *path) +{ + save_errno(); +#ifdef SB_HAVE_MULTILIB + snprintf(path, SB_PATH_MAX, "%s", LIB_NAME); +#else + snprintf(path, SB_PATH_MAX, "%s/%s", LIBSANDBOX_PATH, LIB_NAME); + if (!rc_file_exists(path)) { + snprintf(path, SB_PATH_MAX, "%s", LIB_NAME); + } +#endif + restore_errno(); +} + diff --git a/libsbutil/get_sandbox_log.c b/libsbutil/get_sandbox_log.c new file mode 100644 index 0000000..74f4400 --- /dev/null +++ b/libsbutil/get_sandbox_log.c @@ -0,0 +1,62 @@ +/* + * get_sandbox_log.c + * + * Util functions. + * + * Copyright 1999-2006 Gentoo Foundation + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Some parts might have Copyright: + * + * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com> + * + * $Header$ + */ + + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> + +#include "sbutil.h" + +void get_sandbox_log(char *path) +{ + char *sandbox_log_env = NULL; + + save_errno(); + + sandbox_log_env = getenv(ENV_SANDBOX_LOG); + + /* THIS CHUNK BREAK THINGS BY DOING THIS: + * SANDBOX_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log + */ + if ((NULL != sandbox_log_env) && + (NULL != strchr(sandbox_log_env, '/'))) + sandbox_log_env = NULL; + + snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s", + SANDBOX_LOG_LOCATION, LOG_FILE_PREFIX, + (sandbox_log_env == NULL ? "" : sandbox_log_env), + (sandbox_log_env == NULL ? "" : "-"), + getpid(), LOG_FILE_EXT); + + restore_errno(); +} + diff --git a/libsbutil/get_sandbox_rc.c b/libsbutil/get_sandbox_rc.c new file mode 100644 index 0000000..9771850 --- /dev/null +++ b/libsbutil/get_sandbox_rc.c @@ -0,0 +1,41 @@ +/* + * get_sandbox_rc.c + * + * Util functions. + * + * Copyright 1999-2006 Gentoo Foundation + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Some parts might have Copyright: + * + * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com> + * + * $Header$ + */ + + +#include <errno.h> +#include <stdio.h> + +#include "sbutil.h" + +void get_sandbox_rc(char *path) +{ + save_errno(); + snprintf(path, SB_PATH_MAX, "%s/%s", SANDBOX_BASHRC_PATH, BASHRC_NAME); + restore_errno(); +} + diff --git a/libsbutil/get_tmp_dir.c b/libsbutil/get_tmp_dir.c new file mode 100644 index 0000000..d804d96 --- /dev/null +++ b/libsbutil/get_tmp_dir.c @@ -0,0 +1,52 @@ +/* + * get_tmp_dir.c + * + * Util functions. + * + * Copyright 1999-2006 Gentoo Foundation + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Some parts might have Copyright: + * + * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com> + * + * $Header$ + */ + + +#include <errno.h> +#include <limits.h> +#include <stdlib.h> + +#include "sbutil.h" + +int get_tmp_dir(char *path) +{ + save_errno(); + + if (NULL == realpath(getenv(ENV_TMPDIR) ? getenv(ENV_TMPDIR) + : TMPDIR, + path)) { + if (NULL == realpath(TMPDIR, path)) + return -1; + } + + /* Reset errno in case realpath set it */ + restore_errno(); + + return 0; +} + diff --git a/libsbutil/is_env_off.c b/libsbutil/is_env_off.c new file mode 100644 index 0000000..b29e487 --- /dev/null +++ b/libsbutil/is_env_off.c @@ -0,0 +1,42 @@ +/* + * is_env_off.c + * + * Util functions. + * + * Copyright 1999-2006 Gentoo Foundation + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Header$ + */ + + +#include <errno.h> +#include <stdlib.h> +#include <string.h> + +#include "sbutil.h" + +bool is_env_off (const char *env) +{ + if ((NULL != env) && (NULL != getenv(env)) && + ((0 == strncasecmp(getenv(env), "0", 1)) || + (0 == strncasecmp(getenv(env), "false", 5)) || + (0 == strncasecmp(getenv(env), "no", 2)))) + return TRUE; + + return FALSE; +} + diff --git a/libsbutil/is_env_on.c b/libsbutil/is_env_on.c new file mode 100644 index 0000000..0cfd174 --- /dev/null +++ b/libsbutil/is_env_on.c @@ -0,0 +1,42 @@ +/* + * is_env_on.c + * + * Util functions. + * + * Copyright 1999-2006 Gentoo Foundation + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Header$ + */ + + +#include <errno.h> +#include <stdlib.h> +#include <string.h> + +#include "sbutil.h" + +bool is_env_on (const char *env) +{ + if ((NULL != env) && (NULL != getenv(env)) && + ((0 == strncasecmp(getenv(env), "1", 1)) || + (0 == strncasecmp(getenv(env), "true", 4)) || + (0 == strncasecmp(getenv(env), "yes", 3)))) + return TRUE; + + return FALSE; +} + diff --git a/libsbutil/sb_close.c b/libsbutil/sb_close.c new file mode 100644 index 0000000..76045f1 --- /dev/null +++ b/libsbutil/sb_close.c @@ -0,0 +1,53 @@ +/* + * sb_close.c + * + * IO functions. + * + * Copyright 1999-2006 Gentoo Foundation + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Header$ + */ + + +#include <errno.h> +#include <stdio.h> +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> + +#include "sbutil.h" + + +/* General purpose function to _reliably_ close a file + * + * Returns 0 if successful or negative number on error (and errno set) + */ + +int sb_close(int fd) +{ + int res; + + do { + res = close(fd); + } while ((res < 0) && (EINTR == errno)); + + /* Do not care about errors here */ + errno = 0; + + return res; +} + diff --git a/libsbutil/sbio.c b/libsbutil/sb_open.c index 59f8e91..1e5240f 100644 --- a/libsbutil/sbio.c +++ b/libsbutil/sb_open.c @@ -1,5 +1,5 @@ /* - * sbio.c + * sb_open.c * * IO functions. * @@ -66,88 +66,3 @@ int sb_open(const char *path, int flags, mode_t mode) return fd; } -/* General purpose function to _reliably_ read from a file. - * - * Returns total read bytes or -1 on error. - */ - -size_t sb_read(int fd, void *buf, size_t count) -{ - ssize_t n; - size_t accum = 0; - - do { - n = read(fd, buf + accum, count - accum); - - if (n > 0) { - accum += n; - continue; - } - - if (n < 0) { - if (EINTR == errno) { - /* Reset errno to not trigger DBG_MSG */ - errno = 0; - continue; - } - - DBG_MSG("Failed to read from fd=%i!\n", fd); - return -1; - } - - /* Found EOF */ - break; - } while (accum < count); - - return accum; -} - -/* General purpose function to _reliably_ write to a file - * - * If returned value is less than count, there was a fatal - * error and value tells how many bytes were actually written - */ - -size_t sb_write(int fd, const void *buf, size_t count) -{ - ssize_t n; - size_t accum = 0; - - do { - n = write(fd, buf + accum, count - accum); - if (n < 0) { - if (EINTR == errno) { - /* Reset errno to not trigger DBG_MSG */ - errno = 0; - continue; - } - - DBG_MSG("Failed to write to fd=%i!\n", fd); - break; - } - - accum += n; - } while (accum < count); - - return accum; -} - -/* General purpose function to _reliably_ close a file - * - * Returns 0 if successful or negative number on error (and errno set) - */ - -int sb_close(int fd) -{ - int res; - - do { - res = close(fd); - } while ((res < 0) && (EINTR == errno)); - - /* Do not care about errors here */ - errno = 0; - - return res; -} - diff --git a/libsbutil/sb_read.c b/libsbutil/sb_read.c new file mode 100644 index 0000000..c7bc74e --- /dev/null +++ b/libsbutil/sb_read.c @@ -0,0 +1,70 @@ +/* + * sb_write.c + * + * IO functions. + * + * Copyright 1999-2006 Gentoo Foundation + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Header$ + */ + + +#include <errno.h> +#include <stdio.h> +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> + +#include "sbutil.h" + + +/* General purpose function to _reliably_ read from a file. + * + * Returns total read bytes or -1 on error. + */ + +size_t sb_read(int fd, void *buf, size_t count) +{ + ssize_t n; + size_t accum = 0; + + do { + n = read(fd, buf + accum, count - accum); + + if (n > 0) { + accum += n; + continue; + } + + if (n < 0) { + if (EINTR == errno) { + /* Reset errno to not trigger DBG_MSG */ + errno = 0; + continue; + } + + DBG_MSG("Failed to read from fd=%i!\n", fd); + return -1; + } + + /* Found EOF */ + break; + } while (accum < count); + + return accum; +} + diff --git a/libsbutil/sb_write.c b/libsbutil/sb_write.c new file mode 100644 index 0000000..53597e0 --- /dev/null +++ b/libsbutil/sb_write.c @@ -0,0 +1,64 @@ +/* + * sb_write.c + * + * IO functions. + * + * Copyright 1999-2006 Gentoo Foundation + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Header$ + */ + + +#include <errno.h> +#include <stdio.h> +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> + +#include "sbutil.h" + + +/* General purpose function to _reliably_ write to a file + * + * If returned value is less than count, there was a fatal + * error and value tells how many bytes were actually written + */ + +size_t sb_write(int fd, const void *buf, size_t count) +{ + ssize_t n; + size_t accum = 0; + + do { + n = write(fd, buf + accum, count - accum); + if (n < 0) { + if (EINTR == errno) { + /* Reset errno to not trigger DBG_MSG */ + errno = 0; + continue; + } + + DBG_MSG("Failed to write to fd=%i!\n", fd); + break; + } + + accum += n; + } while (accum < count); + + return accum; +} + diff --git a/libsbutil/sbutil.c b/libsbutil/sbutil.c deleted file mode 100644 index 0b370e9..0000000 --- a/libsbutil/sbutil.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * sbutil.c - * - * Util functions. - * - * Copyright 1999-2006 Gentoo Foundation - * - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Some parts might have Copyright: - * - * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com> - * - * $Header$ - */ - - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <limits.h> -#include <string.h> -#include <sys/stat.h> -#include <unistd.h> -#include <fcntl.h> -#include <libgen.h> - -#include "sbutil.h" - -void get_sandbox_lib(char *path) -{ -#ifdef SB_HAVE_MULTILIB - snprintf(path, SB_PATH_MAX, "%s", LIB_NAME); -#else - snprintf(path, SB_PATH_MAX, "%s/%s", LIBSANDBOX_PATH, LIB_NAME); - if (!rc_file_exists(path)) { - snprintf(path, SB_PATH_MAX, "%s", LIB_NAME); - } -#endif -} - -void get_sandbox_rc(char *path) -{ - snprintf(path, SB_PATH_MAX, "%s/%s", SANDBOX_BASHRC_PATH, BASHRC_NAME); -} - -void get_sandbox_log(char *path) -{ - char *sandbox_log_env = NULL; - - sandbox_log_env = getenv(ENV_SANDBOX_LOG); - - /* THIS CHUNK BREAK THINGS BY DOING THIS: - * SANDBOX_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log - */ - if ((NULL != sandbox_log_env) && - (NULL != strchr(sandbox_log_env, '/'))) - sandbox_log_env = NULL; - - snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s", - SANDBOX_LOG_LOCATION, LOG_FILE_PREFIX, - (sandbox_log_env == NULL ? "" : sandbox_log_env), - (sandbox_log_env == NULL ? "" : "-"), - getpid(), LOG_FILE_EXT); -} - -void get_sandbox_debug_log(char *path) -{ - char *sandbox_debug_log_env = NULL; - - sandbox_debug_log_env = getenv(ENV_SANDBOX_DEBUG_LOG); - - /* THIS CHUNK BREAK THINGS BY DOING THIS: - * SANDBOX_DEBUG_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log - */ - if ((NULL != sandbox_debug_log_env) && - (NULL != strchr(sandbox_debug_log_env, '/'))) - sandbox_debug_log_env = NULL; - - snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s", - SANDBOX_LOG_LOCATION, DEBUG_LOG_FILE_PREFIX, - (sandbox_debug_log_env == NULL ? "" : sandbox_debug_log_env), - (sandbox_debug_log_env == NULL ? "" : "-"), - getpid(), LOG_FILE_EXT); -} - -int get_tmp_dir(char *path) -{ - if (NULL == realpath(getenv(ENV_TMPDIR) ? getenv(ENV_TMPDIR) - : TMPDIR, - path)) { - if (NULL == realpath(TMPDIR, path)) - return -1; - } - - /* Reset errno in case realpath set it */ - errno = 0; - - return 0; -} - -bool is_env_on (const char *env) -{ - if ((NULL != env) && (NULL != getenv(env)) && - ((0 == strncasecmp(getenv(env), "1", 1)) || - (0 == strncasecmp(getenv(env), "true", 4)) || - (0 == strncasecmp(getenv(env), "yes", 3)))) - return TRUE; - - return FALSE; -} - -bool is_env_off (const char *env) -{ - if ((NULL != env) && (NULL != getenv(env)) && - ((0 == strncasecmp(getenv(env), "0", 1)) || - (0 == strncasecmp(getenv(env), "false", 5)) || - (0 == strncasecmp(getenv(env), "no", 2)))) - return TRUE; - - return FALSE; -} - - -// vim:noexpandtab noai:cindent ai |