#
#
# add_file "unix/os_strerror.cc"
# content [59559ef3dd40d42c763b3222484c31396725be7a]
#
# add_file "win32/os_strerror.cc"
# content [7c80ac3dec9995059360f9509516e1315cecd63a]
#
# patch "ChangeLog"
# from [8ffba0bc8729cbc23e8d9ed687fe6d970b403c0b]
# to [1848f72962b9bd28c47fef2c494742cf2e0fb1e6]
#
# patch "Makefile.am"
# from [07bd9acc2044ae79e1f2286aa62a4ffa8ff15e22]
# to [9c641f8577ac86b8eb86f1b1cb3b585e7319454c]
#
# patch "configure.ac"
# from [9a0e730650f554caa768ae612c5583b69bc10330]
# to [d341e69d700975ab4f573f5a1847c68fb16f841e]
#
# patch "file_io.cc"
# from [7fc3a9cac7cb770a2a4fa826d3a23797cda1242e]
# to [c4cb671e671c2389b06dcab4624b541a33853deb]
#
# patch "platform.hh"
# from [02cce907829ab54b8a3a6e4338913f33ddb826d7]
# to [04d460e4e4f8c07d1f40499754a33dfbdbb873ca]
#
# patch "unix/fs.cc"
# from [8c6fe727ef9e240274689f7ef2d08836f73f703b]
# to [5833b5cb00e799e0560372454fe9fd80f424c4c2]
#
# patch "unix/process.cc"
# from [7b082099d353d8d3d6418754c36964123cb6f4fd]
# to [93c62c374ed212a5612d02dfe5d22eeecdd6456c]
#
# patch "win32/fs.cc"
# from [ff7c48b0e00a6f458db9dcdb83dfb8ed7f77a900]
# to [a71696ed436a5ec8878a0f891a4488f1b31ab361]
#
# patch "win32/process.cc"
# from [79552c8593362854390fe3560b13ab682a31c434]
# to [7d15ead25cf13b557357eaa1abf29fb8af92e33e]
#
============================================================
--- unix/os_strerror.cc 59559ef3dd40d42c763b3222484c31396725be7a
+++ unix/os_strerror.cc 59559ef3dd40d42c763b3222484c31396725be7a
@@ -0,0 +1,19 @@
+// Copyright (C) 2006 Matthew Gregan
+// all rights reserved.
+// licensed to the public under the terms of the GNU GPL (>= 2)
+// see the file COPYING for details
+
+#include
+
+#include "sanity.hh"
+#include "platform.hh"
+
+std::string
+os_strerror(os_err_t errnum)
+{
+ char* msg = strerror(errnum);
+ if (msg == 0)
+ return (F("unknown error code %d") % errnum).str();
+ return std::string(msg);
+}
+
============================================================
--- win32/os_strerror.cc 7c80ac3dec9995059360f9509516e1315cecd63a
+++ win32/os_strerror.cc 7c80ac3dec9995059360f9509516e1315cecd63a
@@ -0,0 +1,25 @@
+// Copyright (C) 2006 Matthew Gregan
+// all rights reserved.
+// licensed to the public under the terms of the GNU GPL (>= 2)
+// see the file COPYING for details
+
+#define WIN32_LEAN_AND_MEAN
+#include
+
+#include "sanity.hh"
+#include "platform.hh"
+
+std::string
+os_strerror(os_err_t errnum)
+{
+ LPTSTR tstr;
+ if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
+ 0, errnum, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ reinterpret_cast(&tstr), 0,
+ static_cast(0)) == 0)
+ return (F("unknown error code %d") % errnum).str();
+ std::string str = tstr;
+ LocalFree(tstr);
+ return str;
+}
+
============================================================
--- ChangeLog 8ffba0bc8729cbc23e8d9ed687fe6d970b403c0b
+++ ChangeLog 1848f72962b9bd28c47fef2c494742cf2e0fb1e6
@@ -1,5 +1,12 @@
2006-05-27 Matthew Gregan
+ * {unix,win32}/os_strerror.cc, platform.hh: Add OS-specific
+ wrapper around strerror().
+ * Makefile.am: Add new files.
+ * configure.ac: Define os_err_t based on detected OS.
+ * {unix,win32}/{fs,process}.cc, file_io.cc: Use new strerror
+ wrapper.
+
* netxx/{resolve_gethostbyname,sockopt}.cxx: A couple more error
reporting cleanups.
============================================================
--- Makefile.am 07bd9acc2044ae79e1f2286aa62a4ffa8ff15e22
+++ Makefile.am 9c641f8577ac86b8eb86f1b1cb3b585e7319454c
@@ -224,11 +224,11 @@
UNIX_PLATFORM_SOURCES = \
unix/read_password.cc unix/get_system_flavour.cc unix/process.cc unix/terminal.cc \
- unix/inodeprint.cc unix/fs.cc unix/make_io_binary.cc
+ unix/inodeprint.cc unix/fs.cc unix/make_io_binary.cc unix/os_strerror.cc
WIN32_PLATFORM_SOURCES = \
win32/read_password.cc win32/get_system_flavour.cc win32/process.cc win32/terminal.cc \
- win32/inodeprint.cc win32/fs.cc win32/make_io_binary.cc
+ win32/inodeprint.cc win32/fs.cc win32/make_io_binary.cc win32/os_strerror.cc
# primaries
============================================================
--- configure.ac 9a0e730650f554caa768ae612c5583b69bc10330
+++ configure.ac d341e69d700975ab4f573f5a1847c68fb16f841e
@@ -286,8 +286,10 @@
])
if test "$ac_win32" = "yes"; then
AM_CONDITIONAL(WIN32_PLATFORM, true)
+ AC_DEFINE(os_err_t, unsigned int, [OS-specific error type])
else
AM_CONDITIONAL(WIN32_PLATFORM, false)
+ AC_DEFINE(os_err_t, int, [OS-specific error type])
fi
# Check for IPv6. Let the user enable or disable it manually using a
============================================================
--- file_io.cc 7fc3a9cac7cb770a2a4fa826d3a23797cda1242e
+++ file_io.cc c4cb671e671c2389b06dcab4624b541a33853deb
@@ -165,7 +165,7 @@
F("could not create directory '%s'\nit is a file") % p);
E(false,
F("could not create directory '%s'\n%s")
- % err.path1().native_directory_string() % strerror(err.native_error()));
+ % err.path1().native_directory_string() % os_strerror(err.native_error()));
}
require_path_is_directory(p,
F("could not create directory '%s'") % p,
@@ -197,7 +197,7 @@
{
E(false, F("could not remove '%s'\n%s")
% err.path1().native_directory_string()
- % strerror(err.native_error()));
+ % os_strerror(err.native_error()));
}
}
============================================================
--- platform.hh 02cce907829ab54b8a3a6e4338913f33ddb826d7
+++ platform.hh 04d460e4e4f8c07d1f40499754a33dfbdbb873ca
@@ -63,4 +63,7 @@
void rename_clobberingly(any_path const & from, any_path const & to);
+// strerror wrapper for OS-specific errors (e.g. use FormatMessage on Win32)
+std::string os_strerror(os_err_t errnum);
+
#endif // __PLATFORM_HH__
============================================================
--- unix/fs.cc 8c6fe727ef9e240274689f7ef2d08836f73f703b
+++ unix/fs.cc 5833b5cb00e799e0560372454fe9fd80f424c4c2
@@ -24,7 +24,7 @@
{
char buffer[4096];
E(getcwd(buffer, 4096),
- F("cannot get working directory: %s") % std::strerror(errno));
+ F("cannot get working directory: %s") % os_strerror(errno));
return std::string(buffer);
}
@@ -32,7 +32,7 @@
change_current_working_dir(any_path const & to)
{
E(!chdir(to.as_external().c_str()),
- F("cannot change to directory %s: %s") % to % std::strerror(errno));
+ F("cannot change to directory %s: %s") % to % os_strerror(errno));
}
system_path
@@ -102,7 +102,7 @@
if (errno == ENOENT)
return path::nonexistent;
else
- E(false, F("error accessing file %s: %s") % path % std::strerror(errno));
+ E(false, F("error accessing file %s: %s") % path % os_strerror(errno));
}
if (S_ISREG(buf.st_mode))
return path::file;
@@ -119,5 +119,5 @@
rename_clobberingly(any_path const & from, any_path const & to)
{
E(!rename(from.as_external().c_str(), to.as_external().c_str()),
- F("renaming '%s' to '%s' failed: %s") % from % to % std::strerror(errno));
+ F("renaming '%s' to '%s' failed: %s") % from % to % os_strerror(errno));
}
============================================================
--- unix/process.cc 7b082099d353d8d3d6418754c36964123cb6f4fd
+++ unix/process.cc 93c62c374ed212a5612d02dfe5d22eeecdd6456c
@@ -50,7 +50,7 @@
struct stat s;
int rc = stat(path, &s);
- N(rc != -1, F("error getting status of file %s: %s") % path % strerror(errno));
+ N(rc != -1, F("error getting status of file %s: %s") % path % os_strerror(errno));
return (s.st_mode & S_IXUSR) && !(s.st_mode & S_IFDIR);
}
@@ -69,13 +69,13 @@
mode_t mode;
struct stat s;
int fd = open(path, O_RDONLY);
- N(fd != -1, F("error opening file %s: %s") % path % strerror(errno));
+ N(fd != -1, F("error opening file %s: %s") % path % os_strerror(errno));
if (fstat(fd, &s))
return -1;
mode = s.st_mode;
mode |= ((S_IXUSR|S_IXGRP|S_IXOTH) & ~read_umask());
int ret = fchmod(fd, mode);
- N(close(fd) == 0, F("error closing file %s: %s") % path % strerror(errno));
+ N(close(fd) == 0, F("error closing file %s: %s") % path % os_strerror(errno));
return ret;
}
============================================================
--- win32/fs.cc ff7c48b0e00a6f458db9dcdb83dfb8ed7f77a900
+++ win32/fs.cc a71696ed436a5ec8878a0f891a4488f1b31ab361
@@ -18,22 +18,6 @@
#include "platform.hh"
std::string
-win32_strerror(DWORD errnum)
-{
- LPTSTR tstr;
-
- if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
- 0, errnum, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- reinterpret_cast(&tstr), 0,
- static_cast(0)) == 0)
- return (F("unknown error code %d") % errnum).str();
-
- std::string str = tstr;
- LocalFree(tstr);
- return str;
-}
-
-std::string
get_current_working_dir()
{
char buffer[4096];
@@ -204,13 +188,13 @@
if (rename_clobberingly_impl(szFrom, szTo))
return;
lastError = GetLastError();
- L(FL("attempted rename of '%s' to '%s' failed: %d")
- % szFrom % szTo % lastError);
+ L(FL("attempted rename of '%s' to '%s' failed: %s (%d)")
+ % szFrom % szTo % os_strerror(lastError) % lastError);
Sleep(sleepTime);
if (sleepTime < 250)
sleepTime *= 2;
}
E(false, F("renaming '%s' to '%s' failed: %s (%d)") % from % to
- % win32_strerror(lastError) % lastError);
+ % os_strerror(lastError) % lastError);
}
============================================================
--- win32/process.cc 79552c8593362854390fe3560b13ab682a31c434
+++ win32/process.cc 7d15ead25cf13b557357eaa1abf29fb8af92e33e
@@ -120,7 +120,8 @@
L(FL("searching for exe: %s\n") % argv[0]);
if (SearchPath(NULL, argv[0], ".exe", realexelen, realexe, &filepart)==0)
{
- L(FL("SearchPath failed, err=%d\n") % GetLastError());
+ os_err_t errnum = GetLastError();
+ L(FL("SearchPath failed, err=%s (%d)\n") % os_strerror(errnum) % errnum);
free(realexe);
return -1;
}
@@ -133,7 +134,8 @@
/* We don't need to set any of the STARTUPINFO members */
if (CreateProcess(realexe, (char*)cmd.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)==0)
{
- L(FL("CreateProcess failed, err=%d\n") % GetLastError());
+ os_err_t errnum = GetLastError();
+ L(FL("CreateProcess failed, err=%s (%d)\n") % os_strerror(errnum) % errnum);
free(realexe);
return -1;
}