YARP  2.3.68+272-20170522.1+git50f0ae7
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 #include <cstdio>
8 
9 #include <yarp/os/Os.h>
10 
15 #ifdef YARP_HAS_ACE
16 # include <ace/OS_NS_stdio.h>
17 # include <ace/OS_NS_unistd.h>
18 # include <ace/OS_NS_signal.h>
19 # include <ace/OS_NS_stdlib.h>
20 # include <ace/OS_NS_sys_stat.h>
21 # include <ace/ACE.h>
22 #endif
23 
25 {
26  switch (signum)
27  {
29  return ACE_OS::signal(SIGINT, (ACE_SignalHandler) sighandler);
31  return ACE_OS::signal(SIGTERM, (ACE_SignalHandler) sighandler);
32  default:
33  return YARP_NULLPTR; //signal not implemented yet
34  }
35 }
36 
37 void yarp::os::exit(int v)
38 {
39  ACE_OS::exit(v); //may cause crash... exit is not recommended in processes with multi thread, see http://www.cplusplus.com/reference/cstdlib/exit/
40  //::exit(v); //...this seems to work(?)
41 }
42 
44 {
45 #if defined(WIN32)
46  if (verbose==false)
47  {
48  //to suppress windows dialog message
49  _set_abort_behavior(0, _WRITE_ABORT_MSG);
50  _set_abort_behavior(0, _CALL_REPORTFAULT);
51  }
52 #endif
53  ACE_OS::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/
54 }
55 
56 const char *yarp::os::getenv(const char *var)
57 {
58  return ACE_OS::getenv(var);
59 }
60 
61 int yarp::os::mkdir(const char *p)
62 {
63 #ifdef YARP_HAS_ACE
64  return ACE_OS::mkdir(p);
65 #else
66  return ::mkdir(p,0777);
67 #endif
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 #ifdef YARP_HAS_ACE
78  return ACE_OS::rmdir(p);
79 #else
80  return ::rmdir(p);
81 #endif
82 }
83 
84 int yarp::os::rename(const char *oldname, const char *newname)
85 {
86 #ifdef YARP_HAS_ACE
87  return ACE_OS::rename(oldname,newname);
88 #else
89  return std::rename(oldname,newname);
90 #endif
91 }
92 
93 int yarp::os::stat(const char *path)
94 {
95  ACE_stat dummy;
96  return ACE_OS::stat(path, &dummy);
97 }
98 
100 {
101  pid_t pid = ACE_OS::getpid();
102  return pid;
103 }
104 
105 void yarp::os::setprogname(const char *progname)
106 {
107 #ifdef YARP_HAS_ACE
108  ACE_OS::setprogname(ACE::basename(progname));
109 #else
110  // not available
111 #endif
112 }
113 
114 
115 void yarp::os::getprogname(char*progname, size_t size)
116 {
117 #ifdef YARP_HAS_ACE
118  const char* tmp = ACE_OS::getprogname ();
119  if (strlen(tmp)==0)
120  {
121  strncpy(progname,"no_progname",size);
122  }
123  else
124  {
125  strncpy(progname,tmp,size);
126  }
127 #else
128  // not available
129  *progname = '\0';
130 #endif
131 }
132 
133 
134 void yarp::os::gethostname(char* hostname, size_t size)
135 {
136 #ifdef YARP_HAS_ACE
137  ACE_OS::hostname(hostname, size);
138 #else
139  ::gethostname(hostname, size);
140 #endif
141  if (strlen(hostname)==0)
142  {
143  strncpy(hostname,"no_hostname",size);
144  }
145 }
#define ACE_stat
void setprogname(const char *progname)
Wrapper for ACE_OS::setprogname().
Definition: Os.cpp:105
const char * getenv(const char *var)
Wrapper for ACE_OS::getenv().
Definition: Os.cpp:56
int stat(const char *path)
Wrapper for ACE_OS::stat() function.
Definition: Os.cpp:93
static bool createPath(const ConstString &fileName, int ignoreLevel=1)
Definition: NameConfig.cpp:140
YarpSignalHandler signal(int signum, YarpSignalHandler sighandler)
Wrapper for the ACE_OS::signal signal.
Definition: Os.cpp:24
void exit(int v)
Wrapper for ACE_OS::exit().
Definition: Os.cpp:37
bool verbose
Definition: yarpros.cpp:20
int rename(const char *oldname, const char *newname)
Wrapper for ACE_OS::rename().
Definition: Os.cpp:84
int getpid()
Wrapper for ACE_OS::getppid().
Definition: Os.cpp:99
void(* YarpSignalHandler)(int)
Definition: Os.h:23
void getprogname(char *progname, size_t size)
Wrapper for ACE_OS::getprogname().
Definition: Os.cpp:115
void gethostname(char *hostname, size_t size)
Wrapper for ACE_OS::hostname().
Definition: Os.cpp:134
int rmdir(const char *p)
Wrapper for ACE_OS::rmdir().
Definition: Os.cpp:75
int mkdir(const char *p)
Wrapper for ACE_OS::mkdir().
Definition: Os.cpp:61
void abort(bool verbose=false)
Wrapper for ACE_OS::abort().
Definition: Os.cpp:43
#define YARP_NULLPTR
Expands to either the standard nullptr or to 0 elsewhere.
Definition: compiler.h:2513
dest v
Definition: ImageCopy.cpp:62
#define ACE_SignalHandler
int mkdir_p(const char *p, int ignoreLevels=0)
Create a directory and all parent directories needed.
Definition: Os.cpp:70