posix/coil/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
int m_argc
オプション文字が足りない時、多い時にセットされる
int operator()()
Parses the command line arguments.
GetOpt class.
const char * m_opt
int optind
オプション引数
pid_t getppid()
Get process ID of the parent process.
Definition: ace/coil/OS.h:43
GetOpt(int argc, char *const argv[], const char *opt, int flag)
Constructor.
char * optarg
::pid_t pid_t
Get process ID of the caller process.
Definition: ace/coil/OS.h:38
int uname(utsname *name)
Get System information.
Definition: ace/coil/OS.h:33
static int getopt(int nargc, char *const *nargv, const char *ostr)
Function of parses the command line arguments.
pid_t getpid()
Definition: ace/coil/OS.h:39
char * getenv(const char *name)
Get environment variable.
Definition: ace/coil/OS.h:48
~GetOpt()
Destructor.
char *const * m_argv
int opterr
処理対象引数
int optopt
エラー表示 0:抑止、1:表示
ACE_utsname utsname
Get System information.
Definition: ace/coil/OS.h:32
Common Object Interface Layer.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:43