Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

OS.cpp

Go to the documentation of this file.
00001 #include <errno.h>
00002 #include <string.h>
00003 #include <sys/stat.h>
00004 #include <sys/types.h>
00005 #include <sys/utsname.h>
00006 #include <sys/systeminfo.h>
00007 //#include <sys/sysinfo.h>
00008 #include "OSDependent/OS.h"
00009 
00010 const char OS::DirectorySeparator = '/';
00011 
00012 /*
00013  * Get the hostname of this machine.
00014  * The returned value is statically allocated, so the user does 
00015  * not need to deallocate, but should copy it if it needs it after 
00016  * subsequent calls.
00017  *
00018  * Returns name on success, NULL on failure.
00019  */
00020 const char *
00021 OS::getMyHostName()
00022 {
00023   struct utsname info;
00024   // First, ask the local host.
00025   if (::uname(&info) < 0)
00026     return NULL;
00027   // Now, ask the DNS server.
00028   struct hostent *ent = ::gethostbyname(info.nodename);
00029   return ent->h_name;
00030 }
00031 
00032 /*
00033  * Reentrant version of strtok.
00034  */
00035 char *
00036 OS::strtok_r(char *s, const char *tokens, char **lasts)
00037 {
00038   return ::strtok_r(s, tokens, lasts);
00039 }
00040 
00041 int 
00042 OS::mkdir(const char *name)
00043 {
00044 #ifdef ACCESS_CONTROL
00045   return ::mkdir(name, S_IRWXU);
00046 #else
00047   // TODO: fix permissions
00048   return ::mkdir(name, 0755);
00049 #endif
00050 }
00051 
00052 int 
00053 OS::rmdir(const char *name)
00054 {
00055   return ::rmdir(name);
00056 }
00057 
00058 int 
00059 OS::rename(const char *src, const char *dst)
00060 {
00061   return ::rename(src, dst);
00062 }
00063 
00064 int 
00065 OS::remove(const char *name)
00066 {
00067   return ::unlink(name);
00068 }
00069 
00070 bool 
00071 OS::isDirectory(const char *name)
00072 {
00073   struct stat st;
00074   if (::stat(name, &st) < 0)
00075     return false;
00076 #ifdef SHOULD_CRASH
00077   if (st.st_mode & S_IFDIR == S_IFDIR)
00078 #else
00079   // Corrected by Binny.
00080   if ((st.st_mode & S_IFDIR) == S_IFDIR)
00081 #endif
00082     return true;
00083   else
00084     return false;
00085 }
00086 
00087 char *
00088 OS::getProcessorName ()
00089 {
00090   static char buf[256]; 
00091 
00092   ::sysinfo(SI_ARCHITECTURE, buf, 255);
00093   return(buf);
00094 }
00095 
00096 char *
00097 OS::getOSName()
00098 {
00099  static char buf[512];
00100 
00101  ::sysinfo(SI_SYSNAME, buf, 511);
00102  return(buf);
00103 }
00104 
00105 char *
00106 OS::getenv(const char * str)
00107 {
00108   return ::getenv(str);
00109 }
00110 
00111 int
00112 OS::getErrno()
00113 {
00114   return errno;
00115 }

Generated on Mon Oct 7 09:33:29 2002 for Gaia by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001