8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 06:03:02 +01:00

Change from getenv to readenv. This is still getenv in Linux/UNIX but GetEnvironmentVariable in Windows.

This commit is contained in:
robocop 2006-01-14 04:48:59 +00:00
parent 0a4cc3b0ce
commit b67b0219ab
15 changed files with 173 additions and 125 deletions

View File

@ -66,6 +66,8 @@
#include "../utilities/common/cmd_util_proto.h"
#endif
#include "../common/utils_proto.h"
#ifdef UNIX
#include <unistd.h>
#endif
@ -90,6 +92,7 @@
#include <sys/file.h>
#endif
// The following structure in only needed if we are building a local exe
// I've commented it out to make it clear since this global variable is
// defined in burp.cpp as well, and is not relevant for SERVICE_THREAD
@ -374,21 +377,21 @@ static int api_gbak(int argc,
BurpGlobals::putSpecific(tdgbl);
tdgbl->output_proc = output_main;
const TEXT* usr;
Firebird::string usr;
if (!user)
usr = getenv("ISC_USER");
fb_utils::readenv("ISC_USER", usr);
else
usr = user;
const TEXT* pswd;
Firebird::string pswd;
if (!password)
pswd = getenv("ISC_PASSWORD");
fb_utils::readenv("ISC_PASSWORD", pswd);
else
pswd = password;
char *const spb = (char *) gds__alloc((SLONG) (2 + 2 + ((usr) ? strlen(usr) : 0) +
2 + ((pswd) ? strlen(pswd) : 0)) +
2 + length);
char *const spb = (char *) gds__alloc((SLONG) (2 + 2 + usr.length() +
2 + pswd.length() +
2 + length));
/* 'isc_spb_version'
'isc_spb_current_version'
'isc_spb_user_name'
@ -415,20 +418,20 @@ static int api_gbak(int argc,
*spb_ptr++ = isc_spb_version;
*spb_ptr++ = isc_spb_current_version;
if (usr) {
if (usr.length()) {
*spb_ptr++ = isc_spb_user_name;
*spb_ptr++ = strlen(usr);
MEMMOVE(usr, spb_ptr, strlen(usr));
spb_ptr += strlen(usr);
*spb_ptr++ = usr.length();
MEMMOVE(usr.c_str(), spb_ptr, usr.length());
spb_ptr += usr.length();
if (user)
*user = '\0';
}
if (pswd) {
if (pswd.length()) {
*spb_ptr++ = isc_spb_password;
*spb_ptr++ = strlen(pswd);
MEMMOVE(pswd, spb_ptr, strlen(pswd));
spb_ptr += strlen(pswd);
*spb_ptr++ = pswd.length();
MEMMOVE(pswd.c_str(), spb_ptr, pswd.length());
spb_ptr += pswd.length();
if (password)
*password = '\0';
}

View File

@ -131,6 +131,46 @@ int name_length(const TEXT* const name)
}
//***************
// r e a d e n v
//***************
// Goes to read directly the environment variables from the operating system on Windows
// and provides a stub for UNIX.
bool readenv(const char* env_name, Firebird::string& env_value)
{
#ifdef WIN_NT
const DWORD rc = GetEnvironmentVariable(env_name, NULL, 0);
if (rc)
{
env_value.reserve(rc - 1);
DWORD rc2 = GetEnvironmentVariable(env_name, env_value.begin(), rc);
if (rc2 < rc && rc2 != 0)
{
env_value.recalculate_length();
return true;
}
}
#else
const char* p = getenv(env_name);
if (p)
return env_value.assign(p).length() != 0;
#endif
// Not found, clear the output var.
env_value.begin()[0] = 0;
env_value.recalculate_length();
return false;
}
bool readenv(const char* env_name, Firebird::PathName& env_value)
{
Firebird::string result;
bool rc = readenv(env_name, result);
env_value.assign(result.c_str(), result.length());
return rc;
}
// ***************
// s n p r i n t f
// ***************

View File

@ -39,6 +39,8 @@ namespace fb_utils
}
char* exact_name_limit(char* const str, size_t bufsize);
int name_length(const TEXT* const name);
bool readenv(const char* env_name, Firebird::string& env_value);
bool readenv(const char* env_name, Firebird::PathName& env_value);
int snprintf(char* buffer, size_t count, const char* format...);
} // namespace fb_utils

View File

@ -246,7 +246,7 @@ static void blr_print_verb(gds_ctl*, SSHORT);
static int blr_print_word(gds_ctl*);
static void init(void);
static void sanitize(TEXT*);
static void sanitize(Firebird::string& locale);
static void safe_concat_path(TEXT* destbuf, const TEXT* srcbuf);
@ -1500,10 +1500,10 @@ SSHORT API_ROUTINE gds__msg_lookup(void* handle,
if (!messageL && !(messageL = global_default_msg)) {
/* Try environment variable setting first */
TEXT* p = getenv("ISC_MSGS");
if (p == NULL ||
Firebird::string p;
if (!fb_utils::readenv("ISC_MSGS", p) ||
(status =
gds__msg_open(reinterpret_cast<void**>(&messageL), p)))
gds__msg_open(reinterpret_cast<void**>(&messageL), p.c_str())))
{
TEXT translated_msg_file[sizeof(MSG_FILE_LANG) + LOCALE_MAX + 1];
@ -1516,11 +1516,11 @@ SSHORT API_ROUTINE gds__msg_lookup(void* handle,
if (!msg_file) /* NOMEM: */
return -2;
p = getenv("LC_MESSAGES");
if (p != NULL) {
sanitize(p); // CVC: Sanitizing environment variable???
if (fb_utils::readenv("LC_MESSAGES", p))
{
sanitize(p);
fb_utils::snprintf(translated_msg_file,
sizeof(translated_msg_file), MSG_FILE_LANG, p);
sizeof(translated_msg_file), MSG_FILE_LANG, p.c_str());
gds__prefix_msg(msg_file, translated_msg_file);
status =
gds__msg_open(reinterpret_cast<void**>(&messageL),
@ -2562,8 +2562,9 @@ BOOLEAN API_ROUTINE gds__validate_lib_path(const TEXT* module,
* else, if the module is not in the path return FALSE.
*
**************************************/
TEXT* ib_ext_lib_path = getenv(ib_env_var);
if (!ib_ext_lib_path) {
Firebird::string ib_ext_lib_path;
if (!fb_utils::readenv(ib_env_var, ib_ext_lib_path))
{
strncpy(resolved_module, module, length);
resolved_module[length - 1] = 0;
return TRUE; /* The variable is not defined. Return TRUE */
@ -2588,13 +2589,11 @@ BOOLEAN API_ROUTINE gds__validate_lib_path(const TEXT* module,
TEXT abs_path[MAXPATHLEN];
TEXT path[MAXPATHLEN];
// Let's not modify envvar with strtok!
TEXT temp_path[MAXPATHLEN];
strncpy(temp_path, ib_ext_lib_path, sizeof(temp_path));
temp_path[sizeof(temp_path) - 1] = 0;
const TEXT* token = strtok(temp_path, ";");
// Warning: ib_ext_lib_path.length() is not coherent since strtok is applied to it.
const TEXT* token = strtok(ib_ext_lib_path.begin(), ";");
while (token != NULL) {
strcpy(path, token);
strncpy(path, token, sizeof(path));
path[sizeof(path) - 1] = 0;
/* make sure that there is no traing slash on the path */
TEXT* p = path + strlen(path);
if ((p != path) && ((p[-1] == '/') || (p[-1] == '\\')))
@ -3576,7 +3575,7 @@ static void init(void)
/* V4_GLOBAL_MUTEX_UNLOCK; */
}
static void sanitize(TEXT* locale)
static void sanitize(Firebird::string& locale)
{
/**************************************
*
@ -3591,10 +3590,10 @@ static void sanitize(TEXT* locale)
*
**************************************/
while (*locale) {
if (*locale == '.')
*locale = '_';
locale++;
for (Firebird::string::pointer p = locale.begin(); *p; ++p)
{
if (*p == '.')
*p = '_';
}
}
@ -3684,8 +3683,8 @@ public:
ib_prefix = ib_prefix_val;
// Find appropiate temp directory
const char* tempDir = getenv(FB_TMP_ENV);
if (!tempDir)
Firebird::PathName tempDir;
if (!fb_utils::readenv(FB_TMP_ENV, tempDir))
{
#ifdef WIN_NT
const DWORD len = GetTempPath(sizeof(fbTempDir), fbTempDir);
@ -3695,14 +3694,14 @@ public:
tempDir = fbTempDir;
}
#else
tempDir = getenv("TMP");
fb_utils::readenv("TMP", tempDir);
#endif
}
if (!tempDir || strlen(tempDir) >= MAXPATHLEN)
if (!tempDir.length() || tempDir.length() >= MAXPATHLEN)
{
tempDir = WORKFILE;
}
strcpy(fbTempDir, tempDir);
strcpy(fbTempDir, tempDir.c_str());
#ifdef EMBEDDED
// Generate filename based on the current PID
@ -3714,8 +3713,8 @@ public:
// Find appropriate Firebird lock file prefix
// Override conditional defines with the enviroment
// variable FIREBIRD_LOCK if it is set.
Firebird::PathName lockPrefix(getenv(FB_LOCK_ENV) ? getenv(FB_LOCK_ENV) : "");
if (lockPrefix.isEmpty())
Firebird::PathName lockPrefix;
if (!fb_utils::readenv(FB_LOCK_ENV, lockPrefix))
{
#ifdef EMBEDDED
lockPrefix = tempDir;
@ -3727,8 +3726,8 @@ public:
ib_prefix_lock = ib_prefix_lock_val;
// Find appropriate Firebird message file prefix.
Firebird::PathName msgPrefix(getenv(FB_MSG_ENV) ? getenv(FB_MSG_ENV) : "");
if (msgPrefix.isEmpty())
Firebird::PathName msgPrefix;
if (!fb_utils::readenv(FB_MSG_ENV, msgPrefix))
{
msgPrefix = prefix;
}

View File

@ -30,6 +30,7 @@
#include "../common/classes/fb_string.h"
#include "../jrd/os/path_utils.h"
#include "../common/utils_proto.h"
static const char* CONFIG_FILE = "firebird.conf";
@ -104,11 +105,12 @@ private:
root_dir += PathUtils::dir_sep;
}
}
bool getRootFromEnvironment(const char* envName) {
const char* envValue = getenv(envName);
if (! envValue) {
bool getRootFromEnvironment(const char* envName)
{
string envValue;
if (!fb_utils::readenv(envName, envValue))
return false;
}
root_dir = envValue;
addSlash();
return true;

View File

@ -47,8 +47,8 @@ typedef Firebird::string string;
ConfigRoot::ConfigRoot()
{
// Check the environment variable
const char* envPath = getenv("FIREBIRD");
if (envPath != NULL && strcmp("", envPath))
Firebird::PathName envPath;
if (fb_utils::readenv("FIREBIRD", envPath))
{
root_dir = envPath;
return;

View File

@ -39,6 +39,7 @@
#include "../jrd/met_proto.h"
#include "../jrd/opt_proto.h"
#include "../jrd/vio_proto.h"
#include "../common/utils_proto.h"
#include rms
@ -174,9 +175,10 @@ ExternalFile* EXT_file(jrd_rel* relation, TEXT* file_name, bid* description)
logical name is defined and it is not READONLY, then let there be
an error. */
const UCHAR* lognam = getenv("GDS_RMSACCESS");
if (lognam) {
if (strcmp(lognam, "READONLY") == 0)
Firebird::string lognam;
if (fb_utils::readenv("GDS_RMSACCESS", lognam))
{
if (lognam == "READONLY")
fab.fab$b_fac = FAB$M_GET;
}
else

View File

@ -623,7 +623,8 @@ bool SCH_validate(void)
if (!init_flag || !active_thread) {
gds__log("SCH_validate -- not entered");
if (getenv("ISC_PUNT"))
// CVC: No need to replace by fb_utils::readenv() I think.
if (getenv("ISC_PUNT"))
abort();
return false;
}

View File

@ -629,13 +629,13 @@ int API_ROUTINE gds__edit(const TEXT* file_name, USHORT type)
* Edit a file.
*
**************************************/
const TEXT* editor;
Firebird::string editor;
#ifndef WIN_NT
if (!(editor = getenv("VISUAL")) && !(editor = getenv("EDITOR")))
if (!fb_utils::readenv("VISUAL", editor) && !fb_utils::readenv("EDITOR", editor))
editor = "vi";
#else
if (!(editor = getenv("EDITOR")))
if (!fb_utils::readenv("EDITOR", editor))
editor = "Notepad";
#endif
@ -644,7 +644,7 @@ int API_ROUTINE gds__edit(const TEXT* file_name, USHORT type)
// The path of the editor + the path of the file + quotes + one space.
// We aren't using quotes around the editor for now.
TEXT buffer[MAXPATHLEN * 2 + 5];
fb_utils::snprintf(buffer, sizeof(buffer), "%s \"%s\"", editor, file_name);
fb_utils::snprintf(buffer, sizeof(buffer), "%s \"%s\"", editor.c_str(), file_name);
system(buffer);
@ -1053,10 +1053,8 @@ void API_ROUTINE isc_set_login(const UCHAR** dpb, SSHORT* dpb_size)
/* look for the environment variables */
const TEXT* username = getenv("ISC_USER");
const TEXT* password = getenv("ISC_PASSWORD");
if (!username && !password)
Firebird::string username, password;
if (!fb_utils::readenv("ISC_USER", username) && !fb_utils::readenv("ISC_PASSWORD", password))
return;
/* figure out whether the username or
@ -1090,18 +1088,19 @@ void API_ROUTINE isc_set_login(const UCHAR** dpb, SSHORT* dpb_size)
}
}
if (username && !user_seen) {
if (password && !password_seen)
if (username.length() && !user_seen)
{
if (password.length() && !password_seen)
isc_expand_dpb_internal(dpb, dpb_size,
isc_dpb_user_name, username, isc_dpb_password,
password, 0);
isc_dpb_user_name, username.c_str(), isc_dpb_password,
password.c_str(), 0);
else
isc_expand_dpb_internal(dpb, dpb_size,
isc_dpb_user_name, username, 0);
isc_dpb_user_name, username.c_str(), 0);
}
else if (password && !password_seen)
else if (password.length() && !password_seen)
isc_expand_dpb_internal(dpb, dpb_size,
isc_dpb_password, password, 0);
isc_dpb_password, password.c_str(), 0);
#endif
}
@ -1124,8 +1123,8 @@ BOOLEAN API_ROUTINE isc_set_path(TEXT* file_name,
/* look for the environment variables to tack
onto the beginning of the database path */
const TEXT* pathname = getenv("ISC_PATH");
if (!pathname)
Firebird::PathName pathname;
if (!fb_utils::readenv("ISC_PATH", pathname))
return FALSE;
if (!file_length)
@ -1144,7 +1143,7 @@ BOOLEAN API_ROUTINE isc_set_path(TEXT* file_name,
/* concatenate the strings */
strcpy(expanded_name, pathname);
strcpy(expanded_name, pathname.c_str());
/* CVC: Make the concatenation work if no slash is present. */
p = expanded_name + (strlen (expanded_name) - 1);
@ -2438,16 +2437,16 @@ inline void setTag(Firebird::ClumpletWriter& dpb, UCHAR tag, const TEXT* value)
void setLogin(Firebird::ClumpletWriter& dpb)
{
const TEXT* username = getenv("ISC_USER");
if (username && !dpb.find(isc_dpb_sys_user_name))
Firebird::string username;
if (fb_utils::readenv("ISC_USER", username) && !dpb.find(isc_dpb_sys_user_name))
{
setTag(dpb, isc_dpb_user_name, username);
setTag(dpb, isc_dpb_user_name, username.c_str());
}
const TEXT* password = getenv("ISC_PASSWORD");
if (password && !dpb.find(isc_dpb_password_enc))
Firebird::string password;
if (fb_utils::readenv("ISC_PASSWORD", password) && !dpb.find(isc_dpb_password_enc))
{
setTag(dpb, isc_dpb_password, password);
setTag(dpb, isc_dpb_password, password.c_str());
}
}

View File

@ -53,6 +53,7 @@
#include "../jrd/gds_proto.h"
#include "../jrd/perf_proto.h"
#include "../include/fb_exception.h"
#include "../common/utils_proto.h"
#ifdef VMS
const char* STARTUP_FILE = "QLI_STARTUP";
@ -104,20 +105,15 @@ int CLIB_ROUTINE main( int argc, char **argv)
// Look at options, if any
const TEXT* startup_file = STARTUP_FILE;
Firebird::PathName startup_file = STARTUP_FILE;
#ifdef UNIX
// If a Unix system, get home directory from environment
SCHAR home_directory[MAXPATHLEN];
startup_file = getenv("HOME");
if (startup_file == NULL) {
if (!fb_utils::readenv("HOME", startup_file))
startup_file = ".qli_startup";
}
else {
strcpy(home_directory, startup_file);
strcat(home_directory, "/.qli_startup");
startup_file = home_directory;
}
else
startup_file.append("/.qli_startup");
#endif
const TEXT* application_file = NULL;
@ -181,7 +177,7 @@ int CLIB_ROUTINE main( int argc, char **argv)
case 'I':
if (argv >= arg_end || **argv == '-')
startup_file = NULL;
startup_file = "";
else
startup_file = *argv++;
break;
@ -256,19 +252,18 @@ int CLIB_ROUTINE main( int argc, char **argv)
if (application_file)
LEX_push_file(application_file, true);
if (startup_file)
LEX_push_file(startup_file, false);
if (startup_file.length())
LEX_push_file(startup_file.c_str(), false);
#ifdef VMS
bool vms_tryagain_flag = false;
if (startup_file)
vms_tryagain_flag = LEX_push_file(startup_file, false);
if (startup_file.length())
vms_tryagain_flag = LEX_push_file(startup_file.c_str(), false);
/* If default value of startup file wasn't altered by the use of -i,
and LEX returned FALSE (above), try the old logical name, QLI_INIT */
and LEX returned false (above), try the old logical name, QLI_INIT */
if (!vms_tryagain_flag && startup_file
&& !(strcmp(startup_file, STARTUP_FILE)))
if (!vms_tryagain_flag && startup_file == STARTUP_FILE)
{
LEX_push_file("QLI_INIT", false);
}

View File

@ -40,6 +40,7 @@
#include "../jrd/gds_proto.h"
#include "../jrd/utl_proto.h"
#include "../jrd/gdsassert.h"
#include "../common/utils_proto.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@ -896,14 +897,17 @@ qli_tok* LEX_token(void)
token->tok_length = p - token->tok_string;
*p = '\0';
if (token->tok_string[0] == '$' &&
trans_limit < TRANS_LIMIT && (p = getenv(token->tok_string + 1)))
if (token->tok_string[0] == '$' && trans_limit < TRANS_LIMIT)
{
LEX_push_string(p);
++trans_limit;
token = LEX_token();
--trans_limit;
return token;
Firebird::string s;
if (fb_utils::readenv(token->tok_string + 1, s))
{
LEX_push_string(s.c_str());
++trans_limit;
token = LEX_token();
--trans_limit;
return token;
}
}
qli_symbol* symbol = HSH_lookup(token->tok_string, token->tok_length);

View File

@ -634,6 +634,7 @@ rem_port* INET_connect(const TEXT* name,
fflush(stdout);
}
INET_start_time = inet_debug_timer();
// CVC: I don't see the point in replacing this with fb_utils::readenv().
const char* p = getenv("INET_force_error");
if (p != NULL) {
INET_force_error = atoi(p);
@ -1244,10 +1245,11 @@ static int accept_connection(rem_port* port,
* is activiated for the production product.
* 1995-February-27 David Schnepper
*/
const char* home = getenv("ISC_INET_SERVER_HOME");
if (home) {
if (chdir(home)) {
gds__log("inet_server: unable to cd to %s errno %d\n", home,
Firebird::PathName home;
if (fb_utils::readenv("ISC_INET_SERVER_HOME", home))
{
if (chdir(home.c_str())) {
gds__log("inet_server: unable to cd to %s errno %d\n", home.c_str(),
INET_ERRNO);
/* We continue after the error */
}

View File

@ -209,6 +209,7 @@ const USHORT MIN_ROWS_PER_BATCH = 10; /* data rows - picked by SWAG */
#ifdef DEBUG
{
// CVC: I don't see the point in replacing this with fb_utils::readenv().
const char* p = getenv("DEBUG_BATCH_SIZE");
if (p)
result = atoi(p);

View File

@ -45,6 +45,7 @@
#include "../common/classes/ClumpletWriter.h"
#include "../utilities/gsec/call_service.h"
#include "../common/utils_proto.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@ -150,13 +151,9 @@ inline void envPick(TEXT* dest, size_t size, const TEXT* var)
{
if (dest && (!dest[0]))
{
const TEXT* val = getenv(var);
if (val)
{
--size;
strncpy(dest, val, size);
dest[size] = 0;
}
Firebird::string val;
if (fb_utils::readenv(var, val))
val.copyTo(dest, size);
}
}

View File

@ -23,7 +23,7 @@
*
* 2002.10.29 Sean Leyne - Removed obsolete "Netware" port
*
* $Id: ibmgr.cpp,v 1.17 2005-12-30 15:59:19 alexpeshkoff Exp $
* $Id: ibmgr.cpp,v 1.18 2006-01-14 04:48:59 robocop Exp $
*/
#include "firebird.h"
@ -104,12 +104,13 @@ int CLIB_ROUTINE main( int argc, char **argv)
/* Let's see if we have something in
environment variables
*/
const TEXT* user = getenv("ISC_USER");
const TEXT* password = getenv("ISC_PASSWORD");
Firebird::string user, password;
fb_utils::readenv("ISC_USER", user);
fb_utils::readenv("ISC_PASSWORD", password);
const TEXT* host = NULL; // pointer for getenv
Firebird::string host;
/* MMM - do not allow to change host now
host = getenv("ISC_HOST");
fb_utils::readenv("ISC_HOST", host);
*/
TEXT msg[MSG_LEN];
@ -141,16 +142,16 @@ int CLIB_ROUTINE main( int argc, char **argv)
copy_str_upper(ibmgr_data.user, pw->pw_name);
if (user)
copy_str_upper(ibmgr_data.user, user);
if (user.length())
copy_str_upper(ibmgr_data.user, user.c_str());
if (password)
strcpy(ibmgr_data.password, password);
if (password.length())
strcpy(ibmgr_data.password, password.c_str());
else
ibmgr_data.password[0] = '\0';
if (host)
strcpy(ibmgr_data.host, host);
if (host.length())
strcpy(ibmgr_data.host, host.c_str());
else
strcpy(ibmgr_data.host, "localhost");