YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Os.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <yarp/os/Os.h>
13
14#include <cstdio>
15#include <cstdlib>
16#include <cstring>
17
18#ifdef YARP_HAS_ACE
19# include <ace/ACE.h>
20// In one the ACE headers there is a definition of "main" for WIN32
21# ifdef main
22# undef main
23# endif
24#endif
25
26#if defined(__APPLE__)
28#endif
29
30int yarp::os::mkdir(const char* p)
31{
32 return yarp::os::impl::mkdir(p, 0755);
33}
34
35int yarp::os::mkdir_p(const char* p, int ignoreLevels)
36{
37 std::string fileName(p);
38
39 size_t index = fileName.rfind('/');
40 if (index == std::string::npos) {
41#if defined(_WIN32)
42 index = fileName.rfind('\\');
43 if (index == std::string::npos) {
44 return 1;
45 }
46#else
47 return 1;
48#endif
49 }
50 std::string base = fileName.substr(0, index);
51 if (yarp::os::stat(const_cast<char*>(base.c_str())) < 0) {
52 int result = yarp::os::mkdir_p(base.c_str(), ignoreLevels - 1);
53 if (result != 0) {
54 return 1;
55 }
56 }
57 if (ignoreLevels <= 0) {
58 if (yarp::os::stat(fileName.c_str()) < 0) {
59 if (yarp::os::mkdir(fileName.c_str()) >= 0) {
60 return 0;
61 }
62 return 1;
63 }
64 }
65 return 0;
66}
67
68int yarp::os::rmdir(const char* p)
69{
70 return yarp::os::impl::rmdir(p);
71}
72
73int yarp::os::rename(const char* oldname, const char* newname)
74{
75 return std::rename(oldname, newname);
76}
77
78int yarp::os::stat(const char* path)
79{
81 return yarp::os::impl::stat(path, &dummy);
82}
83
85{
86 pid_t pid = yarp::os::impl::getpid();
87 return pid;
88}
89
90void yarp::os::gethostname(char* hostname, size_t size)
91{
92 yarp::os::impl::gethostname(hostname, size);
93 if (std::strlen(hostname) == 0) {
94 std::strncpy(hostname, "no_hostname", size);
95 }
96}
97
99{
100 char hostname[HOST_NAME_MAX];
102 return {hostname};
103}
104
105char* yarp::os::getcwd(char* buf, size_t size)
106{
107 return yarp::os::impl::getcwd(buf, size);
108}
109
111{
112#if defined(__APPLE__)
113 static void* handle = 0;
114 if (!enabled && !handle) {
116 } else {
118 }
119
120#endif
121}
void restoreAppNap(void *activityInfo)
void * disableAppNap()
A mini-server for performing network communication in the background.
struct ::stat YARP_stat
int mkdir(const char *p)
Portable wrapper for the mkdir() function.
Definition Os.cpp:30
int rename(const char *oldname, const char *newname)
Portable wrapper for the rename() function.
Definition Os.cpp:73
void setEnergySavingModeState(bool enabled)
Toggle the OS energy saving feature.
Definition Os.cpp:110
char * getcwd(char *buf, size_t size)
Portable wrapper for the getcwd() function.
Definition Os.cpp:105
int stat(const char *path)
Portable wrapper for the stat() function.
Definition Os.cpp:78
int getpid()
Portable wrapper for the getppid() function.
Definition Os.cpp:84
int rmdir(const char *p)
Portable wrapper for the rmdir() function.
Definition Os.cpp:68
std::string gethostname()
Portable wrapper for the gethostname() function.
Definition Os.cpp:98
int mkdir_p(const char *p, int ignoreLevels=0)
Create a directory and all parent directories needed.
Definition Os.cpp:35