DCL 4.0
Loading...
Searching...
No Matches
_stdlib.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#include <errno.h>
4#include <string.h>
5#include <stdlib.h> // alloca
6#include <dcl/_stdlib.h>
7
8#include <dcl/Object.h> // __T(str)
9#include <dcl/String.h>
10
11#include "__strumbs.h"
12
13#if __DCL_DEBUG
14#undef __THIS_FILE__
15const char_t __THIS_FILE__[] = __T("dcl/_stdlib.cpp");
16#endif
17
18__DCL_BEGIN_NAMESPACE
19
20#if __DCL_WINDOWS
21DCLCAPI int setenv(const char* _name, const char* _value, int _overwrite)
22{
23 char* sz = (char*) _alloca(strlen(_name) + strlen(_value) + 2);
24 strcpy(sz, _name);
25 strcat(sz, "=");
26 strcat(sz, _value);
27 return _putenv(sz);
28}
29
30DCLCAPI int unsetenv(const char* _name)
31{
32 char* sz = (char*)_alloca(strlen(_name) + 2);
33 strcpy(sz, _name);
34 strcat(sz, "=");
35 return _putenv(sz);
36}
37#endif
38
39#if !__DCL_WINDOWS
40int __getenv(const String& _name, String& _value)
41{
42 STRTOMBS_ER(_name, name);
43 char* s = ::getenv(name);
44 if (s) {
45 MBSTOSTR_ER(s, (size_t) -1, _value);
46 return 0;
47 }
48 errno = ENOENT;
49 return -1;
50}
51
52int __setenv(const String& _name, const String& _value, bool _overwrite)
53{
54 STRTOMBS_ER(_name, name);
55 STRTOMBS_ER(_value, value);
56 return ::setenv(name, value, _overwrite ? 1 : 0);
57}
58
59int __unsetenv(const String& _name)
60{
61 STRTOMBS_ER(_name, name);
62 return ::unsetenv(name);
63}
64
65int __realpath(const String& _path, String& _resolved)
66{
67 char resolved[PATH_MAX + 1];
68 STRTOMBS_ER(_path, path);
69 char* s = ::realpath(path, resolved);
70 if (s) {
71 MBSTOSTR_ER(s, (size_t)-1, _resolved);
72 return 0;
73 }
74 return -1;
75}
76
77#endif // !__DCL_WINDOWS
78
79__DCL_END_NAMESPACE
#define STRTOMBS_ER(str, mbs)
Definition __strumbs.h:33
#define MBSTOSTR_ER(mbs, nmbs, str)
Definition __strumbs.h:19
int __realpath(const String &_path, String &_resolved)
Definition _stdlib.cpp:65
int __setenv(const String &_name, const String &_value, bool _overwrite)
Definition _stdlib.cpp:52
int __unsetenv(const String &_name)
Definition _stdlib.cpp:59
__DCL_BEGIN_NAMESPACE int __getenv(const String &_name, String &_value)
Definition _stdlib.cpp:40
#define __THIS_FILE__
Definition _trace.h:14
#define DCLCAPI
Definition Config.h:100
wchar_t char_t
Definition Config.h:275
#define __T(str)
Definition Object.h:44