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 {
00035 typedef ::utsname utsname;
00036 inline int uname(utsname* name)
00037 {
00038 return ::uname(name);
00039 }
00040
00041 typedef ::pid_t pid_t;
00042 inline pid_t getpid()
00043 {
00044 return ::getpid();
00045 }
00046 inline pid_t getppid()
00047 {
00048 return ::getppid();
00049 }
00050
00051 inline char* getenv(const char *name)
00052 {
00053 return ::getenv(name);
00054 }
00055
00056
00057
00058
00059 class GetOpt
00060 {
00061 public:
00062 GetOpt(int argc, char* const argv[], const char* opt, int flag)
00063 : optarg(::optarg), optind(1), opterr(1), optopt(0), m_argc(argc), m_argv(argv), m_opt(opt), m_flag(flag)
00064 {
00065 ::optind = 1;
00066 }
00067
00068 ~GetOpt()
00069 {
00070 ::optind = 1;
00071 }
00072
00073 int operator()()
00074 {
00075 ::opterr = opterr;
00076 ::optind = optind;
00077
00078 int result = getopt(m_argc, m_argv, m_opt);
00079
00080 optarg = ::optarg;
00081 optind = ::optind;
00082 optopt = ::optopt;
00083
00084 return result;
00085 }
00086 char* optarg;
00087 int optind;
00088 int opterr;
00089 int optopt;
00090
00091 private:
00092 int m_argc;
00093 char* const * m_argv;
00094 const char* m_opt;
00095 int m_flag;
00096 };
00097
00098 };
00099
00100 #endif // COIL_OS_H