From: Chris Koeritz Date: Mon, 10 Sep 2012 03:05:29 +0000 (-0400) Subject: cleaning up usage of TMP variable to always get it from environment class. X-Git-Tag: 2.140.90~1247 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=f2cd4d9e0a4c8a6594ce9c438ed7c71cdae6e558;p=feisty_meow.git cleaning up usage of TMP variable to always get it from environment class. --- diff --git a/doc/perl_tools.html b/doc/perl_tools.html index eda77f29..4c0d2ef5 100644 --- a/doc/perl_tools.html +++ b/doc/perl_tools.html @@ -221,7 +221,7 @@ dos's command, nt's cmd, unix's sh and bash, and perl.  This script will al any files ending in ".sh" or ".pl" and it will create aliases for them in forms appropriate to the different shells.  The .zz_auto_gen subdirectory -is created under the home directory (or under TMP in DOS and Win32) as +is created under the home directory as a storage place for the generated files.

diff --git a/nucleus/applications/bundler/unpacker_stub.cpp b/nucleus/applications/bundler/unpacker_stub.cpp index a515d8cc..8782e2d8 100644 --- a/nucleus/applications/bundler/unpacker_stub.cpp +++ b/nucleus/applications/bundler/unpacker_stub.cpp @@ -196,11 +196,6 @@ int unpacker_stub::execute() astring target; cmds.get_value("target", target); if (!target) { -/* no, this is wrong headed. make them supply a target if there is - * no default target provided in the bundle. - // a bogus default is provided if they don't specify the destination. - target = environment::get("TMP") + "/unbundled"; -*/ provided_target = false; } else { //LOG(astring("target is now ") + target); @@ -212,7 +207,7 @@ int unpacker_stub::execute() astring logdir = environment::get(LOGDIR_WORD); #ifdef __WIN32__ if (!logdir) { - logdir = environment::get("TMP") + "/logs"; + logdir = environment::TMP() + "/logs"; environment::set(LOGDIR_WORD, logdir); } #else diff --git a/nucleus/applications/nechung/cgi_nechung.cpp b/nucleus/applications/nechung/cgi_nechung.cpp index a7478245..7fc24c4f 100644 --- a/nucleus/applications/nechung/cgi_nechung.cpp +++ b/nucleus/applications/nechung/cgi_nechung.cpp @@ -71,7 +71,7 @@ int main(int argc, char *argv[]) tmp.zap( (end + 1) - extension.length(), end); tmp += "idx"; astring base_part = filename(tmp).basename(); - index_file_name = environment::get("TMP") + "/" + base_part; + index_file_name = environment::TMP() + "/" + base_part; #ifdef DEBUG_NECHUNG LOG(astring("index file is ") + index_file_name); #endif diff --git a/nucleus/applications/nechung/nechung.cpp b/nucleus/applications/nechung/nechung.cpp index 5c93f7c6..70b33063 100644 --- a/nucleus/applications/nechung/nechung.cpp +++ b/nucleus/applications/nechung/nechung.cpp @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) tmp.zap( (end + 1) - extension.length(), end); tmp += "idx"; astring base_part = filename(tmp).basename(); - index_file_name = environment::get("TMP") + "/" + base_part; + index_file_name = environment::TMP() + "/" + base_part; #ifdef DEBUG_NECHUNG LOG(astring("index file is ") + index_file_name); #endif diff --git a/nucleus/library/application/windoze_helper.cpp b/nucleus/library/application/windoze_helper.cpp index c9c29109..85c30488 100644 --- a/nucleus/library/application/windoze_helper.cpp +++ b/nucleus/library/application/windoze_helper.cpp @@ -406,45 +406,6 @@ istring query_for_process_info() } #endif -// used as a return value when the name cannot be determined. -#ifndef EMBEDDED_BUILD - #define SET_BOGUS_NAME(error) { \ - COMPLAIN(error); \ - if (output) { \ - fclose(output); \ - unlink(tmpfile.s()); \ - } \ - istring home_dir = env_string("HOME"); \ - to_return = home_dir + "/failed_to_determine.exe"; \ - } -#else - #define SET_BOGUS_NAME(error) { \ - COMPLAIN(error); \ - to_return = "unknown"; \ - } -#endif - -istring application_name() -{ - FUNCDEF("application_name"); - istring to_return; -#ifdef __UNIX__ - to_return = get_cmdline_from_proc(); -#elif defined(__WIN32__) - flexichar low_buff[MAX_ABS_PATH + 1]; - GetModuleFileName(NIL, low_buff, MAX_ABS_PATH - 1); - istring buff = from_unicode_temp(low_buff); - buff.to_lower(); // we lower-case the name since windows seems to UC it. - to_return = buff; -#elif defined(EMBEDDED_BUILD) - SET_BOGUS_NAME("embedded_exe"); -#else - #pragma error("hmmm: no means of finding app name is implemented.") - SET_BOGUS_NAME("not_implemented_for_this_OS"); -#endif - return to_return; -} - istring module_name(const void *module_handle) { #ifdef __UNIX__ @@ -554,32 +515,6 @@ istring current_directory() return to_return; } -istring env_string(const istring &variable_name) -{ -#ifdef __WIN32__ - char *value = getenv(variable_name.upper().observe()); - // dos & os/2 require upper case for the name, so we just do it that way. -#else - char *value = getenv(variable_name.observe()); - // reasonable OSes support mixed-case environment variables. -#endif - istring to_return; - if (value) - to_return = istring(value); - return to_return; -} - -bool set_environ(const istring &variable_name, const istring &value) -{ - int ret = 0; -#ifdef __WIN32__ - ret = putenv((variable_name + "=" + value).s()); -#else - ret = setenv(variable_name.s(), value.s(), true); -#endif - return !ret; -} - timeval fill_timeval_ms(int duration) { timeval time_out; // timeval has tv_sec=seconds, tv_usec=microseconds. diff --git a/nucleus/library/basis/environment.cpp b/nucleus/library/basis/environment.cpp index 5e50abfb..907c8504 100644 --- a/nucleus/library/basis/environment.cpp +++ b/nucleus/library/basis/environment.cpp @@ -29,6 +29,23 @@ namespace basis { +astring environment::TMP() +{ + const static astring TMP_VARIABLE_NAME("TMP"); + astring to_return = get(TMP_VARIABLE_NAME); + if (!to_return) { + // they did not see fit to set this in the environment. let's make something up. +#ifdef __WIN32__ + // windows default does not necessarily exist. + to_return = "c:/tmp"; +#else + // most reasonable OSes have a /tmp directory. + to_return = "/tmp"; +#endif + } + return to_return; +} + astring environment::get(const astring &variable_name) { #ifdef __WIN32__ diff --git a/nucleus/library/basis/environment.h b/nucleus/library/basis/environment.h index e9823e73..d5189393 100644 --- a/nucleus/library/basis/environment.h +++ b/nucleus/library/basis/environment.h @@ -26,6 +26,12 @@ namespace basis { class environment : public virtual root_object { public: + static astring TMP(); + //!< provides a single place to get the temporary directory. + /*!< this will locate the value of the TMP variable and return it. if the TMP + variable is not currently defined, this will try to do something reasonable for + a default value. */ + static astring get(const astring &variable_name); //!< looks up the "variable_name" in the current environment variables. /*!< this returns the value for "variable_name" as it was found in the @@ -33,18 +39,11 @@ public: in time for the user and process. the returned string will be empty if no variable under that name could be found. */ -// static astring get(const char *variable_name) { return get(astring(variable_name)); } - //!< synonym using simpler char pointer. - static bool set(const astring &variable_name, const astring &value); //!< adds or creates "variable_name" in the environment. /*!< changes the current set of environment variables by adding or modifying the "variable_name". its new value will be "value". */ -// static bool set(const char *variable_name, const char *value) -// { return set(astring(variable_name), astring(value)); } - //!< synonym using simpler char pointers. - static basis::un_int system_uptime(); //!< gives the operating system's uptime in a small form that rolls over. }; diff --git a/nucleus/library/configuration/application_configuration.cpp b/nucleus/library/configuration/application_configuration.cpp index 16a1bea3..601164e4 100644 --- a/nucleus/library/configuration/application_configuration.cpp +++ b/nucleus/library/configuration/application_configuration.cpp @@ -105,7 +105,7 @@ printf("got an app name before chewing: %s\n", __check_once_app_path.s()); printf("no dir part found, app name after chewing: %s\n", __check_once_app_path.s()); // there was no directory component, so we'll try to guess one. - astring temp_filename(environment::get("TMP") + astring temp_filename(environment::TMP() + a_sprintf("/zz_cmdfind.%d", chaos().inclusive(0, 999999999))); system((astring("which ") + __check_once_app_path + " >" + temp_filename).s()); FILE *which_file = fopen(temp_filename.s(), "r"); @@ -191,7 +191,7 @@ astring application_configuration::query_for_process_info() fclose(output); \ unlink(tmpfile.s()); \ } \ - astring home_dir = env_string("HOME"); \ + astring home_dir = environment::get("HOME"); \ to_return = home_dir + "/failed_to_determine.exe"; \ } diff --git a/nucleus/library/tests_filesystem/test_byte_filer.cpp b/nucleus/library/tests_filesystem/test_byte_filer.cpp index 0fac18a9..b37faaba 100644 --- a/nucleus/library/tests_filesystem/test_byte_filer.cpp +++ b/nucleus/library/tests_filesystem/test_byte_filer.cpp @@ -63,7 +63,7 @@ const astring &TEST_FILE() const char *TEST_FILE_SUFFIX = ".txt"; static astring __hidden_filename; if (!__hidden_filename) { - __hidden_filename = environment::get("TMP"); + __hidden_filename = environment::TMP(); if (!__hidden_filename) __hidden_filename = "/tmp"; // try to create it just in case it wasn't there already. directory::make_directory(__hidden_filename); @@ -174,9 +174,8 @@ int test_byte_filer::run_file_scan() files.zap(0, 0); // toss the first element since that's our app filename. if (!files.length()) { - // pretend they gave us the list of files in the TMP directory. some of + // pretend they gave us the list of files in the current directory. some of // these might fail if they're locked up. -// astring tmpdir = environment::get("TMP"); astring tmpdir = application_configuration::current_directory(); directory dir(tmpdir); for (int i = 0; i < dir.files().length(); i++) { diff --git a/nucleus/library/tests_filesystem/test_huge_file.cpp b/nucleus/library/tests_filesystem/test_huge_file.cpp index f9209eb7..d360345d 100644 --- a/nucleus/library/tests_filesystem/test_huge_file.cpp +++ b/nucleus/library/tests_filesystem/test_huge_file.cpp @@ -57,9 +57,8 @@ void test_huge_file::run_file_scan() files.zap(0, 0); // toss the first element since that's our app filename. if (!files.length()) { - // pretend they gave us the list of files in the TMP directory. some of + // pretend they gave us the list of files in the current directory. some of // these might fail if they're locked up. -// astring tmpdir = environment::get("TMP"); astring tmpdir = application_configuration::current_directory(); directory dir(tmpdir); for (int i = 0; i < dir.files().length(); i++) { diff --git a/nucleus/library/versions/version_checker.cpp b/nucleus/library/versions/version_checker.cpp index 24d06b69..4f14e257 100644 --- a/nucleus/library/versions/version_checker.cpp +++ b/nucleus/library/versions/version_checker.cpp @@ -80,7 +80,7 @@ astring version_checker::text_form() const bool version_checker::good_version() const { - astring version_disabler = environment::get("TMP"); + astring version_disabler = environment::TMP(); version_disabler += "/no_version_check.txt"; FILE *always_okay = fopen(version_disabler.s(), "r"); if (always_okay) { diff --git a/octopi/library/cromp/cromp_transaction.cpp b/octopi/library/cromp/cromp_transaction.cpp index c8b582ba..8345c154 100644 --- a/octopi/library/cromp/cromp_transaction.cpp +++ b/octopi/library/cromp/cromp_transaction.cpp @@ -14,8 +14,11 @@ #include "cromp_transaction.h" +#include #include +#include #include +#include #include #include #include @@ -33,7 +36,7 @@ using namespace textual; namespace cromp { -//#define DEBUG_CROMP_TRANSACTION +#define DEBUG_CROMP_TRANSACTION // uncomment for noisy version. const int MAXIMUM_TRANSACTION = 100 * MEGABYTE; @@ -45,7 +48,7 @@ const int MAXIMUM_TRANSACTION = 100 * MEGABYTE; // since the transaction stuff is so low-level, we risk a feedback loop if // we log stuff when the program wide logger is itself a communication // object. - #define LOG(s) CLASS_EMERGENCY_LOG(file_logger(portable::env_string("TMP") + "/cromp_transaction.log"), s) + #define LOG(s) CLASS_EMERGENCY_LOG(file_logger(environment::TMP() + "/cromp_transaction.log"), s) #else #define LOG(s) #endif