OpenRTM-aist  1.2.1
OS.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef COIL_OS_H
20 #define COIL_OS_H
21 
22 #include <string>
23 #include <sys/utsname.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #include <stdlib.h>
27 
28 extern "C"
29 {
30  extern char *optarg;
31 };
32 
33 namespace coil
34 {
59  inline int uname(utsname* name)
60  {
61  return ::uname(name);
62  }
63 
84  inline pid_t getpid()
85  {
87  }
88 
108  inline pid_t getppid()
109  {
111  }
112 
136  inline char* getenv(const char *name)
137  {
138  return ::getenv(name);
139  }
140 
141 
142  /* Global Variables for getopt() */
143 
157  class GetOpt
158  {
159  public:
179  GetOpt(int argc, char* const argv[], const char* opt, int flag)
180  : optarg(::optarg), optind(1), opterr(1), optopt(0), m_argc(argc), m_argv(argv), m_opt(opt), m_flag(flag)
181  {
182  ::optind = 1;
183 #ifdef __QNX___
184  optind_last = 1;
185 #endif
186  }
187 
204  {
205  ::optind = 1;
206 #ifdef __QNX__
207  optind_last = 1;
208 #endif
209  }
210 
231  {
232  ::opterr = opterr;
233 #ifndef __QNX__
234  ::optind = optind;
235 #else
236  ::optind = optind_last;
237  ::optarg = 0;
238 #endif
239  int result = getopt(m_argc, m_argv, m_opt);
240 #ifdef __QNX__
241  if(::optind == optind_last)
242  {
243  ::optind++;
244  result = getopt(m_argc, m_argv, m_opt);
245  optind_last = ::optind;
246  }
247 #endif
248  optarg = ::optarg;
249  optind = ::optind;
250  optopt = ::optopt;
251 #if __QNX__
252  if(optind_last < m_argc) { ++optind_last; }
253 #endif
254  return result;
255  }
256 
257  char* optarg;
258  int optind;
259  int opterr;
260  int optopt;
261 #ifdef __QNX__
262  int optind_last;
263 #endif
264 
265  private:
266  int m_argc;
267  char* const * m_argv;
268  const char* m_opt;
269  int m_flag;
270  };
271 
272 };
273 
274 #endif // COIL_OS_H
char * getenv(const char *name)
Get environment variable.
Definition: OS.h:136
int operator()()
Parses the command line arguments.
Definition: OS.h:230
GetOpt class.
Definition: OS.h:157
int optind
オプション引数
Definition: OS.h:258
pid_t getppid()
Get process ID of the parent process.
Definition: OS.h:108
GetOpt(int argc, char *const argv[], const char *opt, int flag)
Constructor.
Definition: OS.h:179
char * optarg
Definition: OS.h:257
char * optarg
int uname(utsname *name)
Definition: OS.h:59
::pid_t pid_t
Get process ID of the caller process.
Definition: OS.h:83
pid_t getpid()
Definition: OS.h:84
~GetOpt()
Destructor.
Definition: OS.h:203
int opterr
処理対象引数
Definition: OS.h:259
int optopt
エラー表示 0:抑止、1:表示
Definition: OS.h:260
::utsname utsname
Get System information.
Definition: OS.h:58
Common Object Interface Layer.
Definition: Affinity.h:28