00001 
00019 #ifndef COIL_OS_H
00020 #define COIL_OS_H
00021 
00022 #include <string>
00023 #include <sys/utsname.h>
00024 #include <sys/types.h> 
00025 #include <unistd.h> 
00026 #include <stdlib.h>
00027 
00028 extern "C"
00029 {
00030   extern char *optarg;
00031 };
00032 
00033 namespace coil
00034 {
00058   typedef ::utsname utsname;
00059   inline int uname(utsname* name)
00060   {
00061     return ::uname(name);
00062   }
00063 
00083   typedef ::pid_t pid_t;
00084   inline pid_t getpid()
00085   {
00086     return ::getpid();
00087   }
00088 
00108   inline pid_t getppid()
00109   {
00110     return ::getppid();
00111   }
00112 
00136   inline char* getenv(const char *name)
00137   {
00138     return ::getenv(name);
00139   }
00140 
00141 
00142   
00143 
00157   class GetOpt
00158   {
00159   public:
00179     GetOpt(int argc, char* const argv[], const char* opt, int flag)
00180       : optarg(::optarg), optind(1), opterr(1), optopt(0), m_argc(argc), m_argv(argv), m_opt(opt), m_flag(flag)
00181     {
00182       ::optind = 1;
00183 #ifdef __QNX___
00184       optind_last = 1;
00185 #endif
00186     }
00187 
00203     ~GetOpt()
00204     {
00205       ::optind = 1;
00206 #ifdef __QNX__
00207       optind_last = 1;
00208 #endif
00209     }
00210 
00230     int operator()()
00231     {
00232       ::opterr = opterr;
00233 #ifndef __QNX__
00234       ::optind = optind;
00235 #else
00236       ::optind = optind_last;
00237       ::optarg = 0;
00238 #endif
00239       int result = getopt(m_argc, m_argv, m_opt);
00240 #ifdef __QNX__
00241         if(::optind == optind_last)
00242           {
00243             ::optind++;
00244             result = getopt(m_argc, m_argv, m_opt);
00245             optind_last = ::optind;
00246           }
00247 #endif
00248       optarg = ::optarg;
00249       optind = ::optind;
00250       optopt = ::optopt;
00251 #if __QNX__
00252       if(optind_last < m_argc) { ++optind_last; }
00253 #endif
00254       return result;
00255     }
00256 
00257     char* optarg;     
00258     int optind;       
00259     int opterr;       
00260     int optopt;       
00261 #ifdef __QNX__
00262     int optind_last;
00263 #endif
00264 
00265   private:
00266     int m_argc;
00267     char* const * m_argv;
00268     const char* m_opt;
00269     int m_flag;
00270   };
00271     
00272 };
00273 
00274 #endif // COIL_OS_H