YARP  2.3.70.1
Yet Another Robot Platform
Os.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 RobotCub Consortium
3  * Author: Lorenzo Natale
4  * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
5  */
6 
7 
8 #include <yarp/os/Os.h>
9 
15 
16 #include <cstdio>
17 #include <cstdlib>
18 #include <cstring>
19 
20 #ifdef YARP_HAS_ACE
21 # include <ace/ACE.h>
22 #endif
23 
24 
25 #ifndef YARP_NO_DEPRECATED // Since YARP 2.3.70
27 {
28  switch (signum) {
30  return yarp::os::impl::signal(SIGINT, sighandler);
32  return yarp::os::impl::signal(SIGTERM, sighandler);
33  default:
34  return YARP_NULLPTR; //signal not implemented yet
35  }
36 }
37 #endif // YARP_NO_DEPRECATED
38 
39 #ifndef YARP_NO_DEPRECATED // Since YARP 2.3.70
40 void yarp::os::exit(int exit_code)
41 {
42  std::exit(exit_code); //may cause crash... exit is not recommended in processes with multi thread, see http://www.cplusplus.com/reference/cstdlib/exit/
43 }
44 #endif // YARP_NO_DEPRECATED
45 
46 #ifndef YARP_NO_DEPRECATED // Since YARP 2.3.70
48 {
49 #if defined(_WIN32)
50  if (verbose==false) {
51  //to suppress windows dialog message
52  _set_abort_behavior(0, _WRITE_ABORT_MSG);
53  _set_abort_behavior(0, _CALL_REPORTFAULT);
54  }
55 #endif
56  std::abort(); // exit is not recommended in processes with multi thread, see http://www.cplusplus.com/reference/cstdlib/exit/ and http://www.cplusplus.com/reference/cstdlib/abort/
57 }
58 #endif // YARP_NO_DEPRECATED
59 
60 const char *yarp::os::getenv(const char *var)
61 {
62  return yarp::os::impl::getenv(var);
63 }
64 
65 int yarp::os::mkdir(const char *p)
66 {
67  return yarp::os::impl::mkdir(p, 0755);
68 }
69 
70 int yarp::os::mkdir_p(const char *p, int ignoreLevels) {
71  bool ok = yarp::os::impl::NameConfig::createPath(p, ignoreLevels);
72  return ok?0:1;
73 }
74 
75 int yarp::os::rmdir(const char *p)
76 {
77  return yarp::os::impl::rmdir(p);
78 }
79 
80 int yarp::os::rename(const char *oldname, const char *newname)
81 {
82  return std::rename(oldname, newname);
83 }
84 
85 int yarp::os::stat(const char *path)
86 {
88  return yarp::os::impl::stat(path, &dummy);
89 }
90 
92 {
93  pid_t pid = yarp::os::impl::getpid();
94  return pid;
95 }
96 
97 void yarp::os::setprogname(const char *progname)
98 {
99 #ifdef YARP_HAS_ACE
100  ACE_OS::setprogname(ACE::basename(progname));
101 #else
102  // not available
103  YARP_UNUSED(progname);
104 #endif
105 }
106 
107 
108 void yarp::os::getprogname(char* progname, size_t size)
109 {
110 #ifdef YARP_HAS_ACE
111  const char* tmp = ACE_OS::getprogname();
112  if (std::strlen(tmp)==0) {
113  std::strncpy(progname, "no_progname", size);
114  } else {
115  std::strncpy(progname, tmp, size);
116  }
117 #else
118  // not available
119  *progname = '\0';
120  YARP_UNUSED(size);
121 #endif
122 }
123 
124 
125 void yarp::os::gethostname(char* hostname, size_t size)
126 {
127  yarp::os::impl::gethostname(hostname, size);
128  if (std::strlen(hostname)==0) {
129  std::strncpy(hostname, "no_hostname", size);
130  }
131 }
132 
133 char* yarp::os::getcwd(char *buf, size_t size)
134 {
135  return yarp::os::impl::getcwd(buf, size);
136 }
137 
138 int yarp::os::fork(void)
139 {
140  pid_t pid = yarp::os::impl::fork();
141  return pid;
142 }
char * getcwd(char *buf, size_t size)
Portable wrapper for the getcwd() function.
Definition: Os.cpp:133
void setprogname(const char *progname)
Portable wrapper for the setprogname() function.
Definition: Os.cpp:97
struct ::stat YARP_stat
const char * getenv(const char *var)
Portable wrapper for the getenv() function.
Definition: Os.cpp:60
int stat(const char *path)
Portable wrapper for the stat() function.
Definition: Os.cpp:85
void exit(int exit_code)
Portable wrapper for the exit() function.
Definition: Os.cpp:40
static bool createPath(const ConstString &fileName, int ignoreLevel=1)
Definition: NameConfig.cpp:131
YarpSignalHandler signal(int signum, YarpSignalHandler sighandler)
Portable wrapper for the signal() function.
Definition: Os.cpp:26
bool verbose
Definition: yarpros.cpp:20
int rename(const char *oldname, const char *newname)
Portable wrapper for the rename() function.
Definition: Os.cpp:80
int getpid()
Portable wrapper for the getppid() function.
Definition: Os.cpp:91
void(* YarpSignalHandler)(int)
Definition: Os.h:24
int fork(void)
Portable wrapper for the fork() function.
Definition: Os.cpp:138
void getprogname(char *progname, size_t size)
Portable wrapper for the getprogname() function.
Definition: Os.cpp:108
void gethostname(char *hostname, size_t size)
Portable wrapper for the gethostname() function.
Definition: Os.cpp:125
int rmdir(const char *p)
Portable wrapper for the rmdir() function.
Definition: Os.cpp:75
int mkdir(const char *p)
Portable wrapper for the mkdir() function.
Definition: Os.cpp:65
void abort(bool verbose=false)
Portable wrapper for the abort() function.
Definition: Os.cpp:47
int mkdir_p(const char *p, int ignoreLevels=0)
Create a directory and all parent directories needed.
Definition: Os.cpp:70