checking in the recent efforts at optimizing clam
[feisty_meow.git] / nucleus / library / basis / environment.cpp
index 5e50abfbe861913a7fe7d6230a672cff7b5bddfd..8549ab7a8ea95cc66843e4ec7d5ee293425b28b8 100644 (file)
 
 #include <stdlib.h>
 #include <sys/types.h>
-#ifdef __UNIX__
+//#ifndef _MSC_VER
   #include <unistd.h>
   #include <sys/times.h>
-#endif
-#ifdef __WIN32__
+//#endif
+/*
+#ifdef _MSC_VER
   #define _WINSOCKAPI_  // make windows.h happy about winsock.
+  // winsock support...
+//  #undef FD_SETSIZE
+//  #define FD_SETSIZE 1000
+    // if you don't set this, you can only select on a default of 64 sockets.
+  #include <winsock2.h>
   #include <windows.h>
   #include <mmsystem.h>
 #endif
+*/
 
 namespace basis {
 
-astring environment::get(const astring &variable_name)
+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__
-  char *value = getenv(variable_name.upper().observe());
-    // dos & os/2 require upper case for the name, so we just do it that way.
+    // windows default does not necessarily exist.
+    to_return = "c:/tmp";
 #else
+    // most reasonable OSes have a /tmp directory.
+    to_return = "/tmp";
+#endif
+    if (!!to_return) set("TMP", to_return);
+  }
+  return to_return;
+}
+
+astring environment::get(const astring &variable_name)
+{
+//#ifdef _MSC_VER
+//  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
+//#endif
   astring to_return;
   if (value)
     to_return = astring(value);
@@ -47,20 +72,20 @@ astring environment::get(const astring &variable_name)
 bool environment::set(const astring &variable_name, const astring &value)
 {
   int ret = 0;
-#ifdef __WIN32__
-  astring assignment = variable_name + "=" + value;
-  ret = _putenv(assignment.s());
-#else
+//#ifdef _MSC_VER
+//  astring assignment = variable_name + "=" + value;
+//  ret = _putenv(assignment.s());
+//#else
   ret = setenv(variable_name.s(), value.s(), true);
-#endif
+//#endif
   return !ret;
 }
 
 basis::un_int environment::system_uptime()
 {
-#ifdef __WIN32__
-  return timeGetTime();
-#else
+//#ifdef _MSC_VER
+//  return timeGetTime();
+//#else
   static clock_t __ctps = sysconf(_SC_CLK_TCK);  // clock ticks per second.
   static const double __multiplier = 1000.0 / double(__ctps);
     // the multiplier gives us our full range for the tick counter.
@@ -80,7 +105,7 @@ basis::un_int environment::system_uptime()
   // emulation) and thus it becomes a bug around 49 days and 17 hours into
   // OS uptime because the value gets stuck at 2^32-1 and never rolls over.
   return basis::un_int(ticks_up);
-#endif
+//#endif
 }
 
 } //namespace.