35# ifndef _XOPEN_SOURCE_EXTENDED
36# define _XOPEN_SOURCE_EXTENDED
46# include <sys/types.h>
62static char* get_cwd (
char*
s, std::size_t l)
64#if !defined (_MSC_VER)
67 return _getcwd (
s, l);
72#if !defined (_WIN32) && !defined (__CYGWIN__)
76 const std::string &xname,
77 const std::string &sname)
84 pret = get_cwd (
buf, 1024);
87 "could not retrieve current working directory\n") ;
90 ret = chdir (dir.c_str ());
92 issue_diag (214,
false, 0,
"could not change directory to %s\n",
96 ret = symlink(xname.c_str(), sname.c_str());
100 if (ret == -1 && errno != EEXIST) {
102 "could not create symbolic link to %s "
103 "locale database (%s)\n",
104 xname.c_str (), std::strerror (errno)) ;
130 const std::string &other )
137 fname [1] && fname [1] ==
':' &&
142 std::string pathname;
143 std::string dir_other (
151 other [1] && other [1] ==
':' &&
155 (pathname += dir_other) += fname;
158 pathname.resize (1024);
161 while (!get_cwd (&pathname [0], pathname.size ())) {
164 "could not retrieve current working directory\n");
168 pathname.resize (pathname.size () * 2);
171 pathname.resize (std::strlen (pathname.data ()));
173 if (pathname.size() &&
177 (pathname += dir_other) += fname;
180#if !defined (_MSC_VER)
181 if (S_ISREG (
filemode (pathname.c_str ())))
183 if (S_IFREG &
filemode (pathname.c_str ()))
189 const char*
const src_root = std::getenv (
"RWSTD_SRC_ROOT");
190 if (src_root && *src_root) {
197#if !defined (_MSC_VER)
198 if (S_ISREG (
filemode (pathname.c_str ())))
200 if (S_IFREG &
filemode (pathname.c_str ()))
206 pathname.resize (1024);
209 while (!get_cwd (&pathname [0], pathname.size ())) {
213 "could not retrieve current working directory\n");
218 pathname.resize (pathname.size () * 2);
222 pathname.resize (std::strlen (pathname.data ()));
225#if !defined (_MSC_VER)
226 if (S_ISREG (
filemode (pathname.c_str ())))
228 if (S_IFREG &
filemode (pathname.c_str ()))
240 if ( 0 == CreateDirectory (
name,
NULL)
241 && GetLastError () != ERROR_ALREADY_EXISTS) {
245 FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER
246 | FORMAT_MESSAGE_FROM_SYSTEM
247 | FORMAT_MESSAGE_IGNORE_INSERTS,
250 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
262 if (-1 == mkdir (
name, 0755)) {
266 if (errno != EEXIST) {
268 name, std::strerror (errno));
bool issue_diag(int type, bool, const Scanner::token_t *token, const char *fmt,...)
int filemode(const char *path)
void create_symlink(const std::string &dir, const std::string &xname, const std::string &sname)
std::string get_pathname(const std::string &fname, const std::string &other)
int makedir(const char *name)