[Groonga-commit] groonga/grnxx at f5c87ec [master] Rename grnxx::Error to grnxx::Errno.

Back to archive index

susumu.yata null+****@clear*****
Fri Jun 28 19:40:49 JST 2013


susumu.yata	2013-06-28 19:40:49 +0900 (Fri, 28 Jun 2013)

  New Revision: f5c87ec479e53a483ff205daacce507174c30673
  https://github.com/groonga/grnxx/commit/f5c87ec479e53a483ff205daacce507174c30673

  Message:
    Rename grnxx::Error to grnxx::Errno.

  Modified files:
    .gitignore
    lib/grnxx/Makefile.am
    lib/grnxx/features.hpp
    lib/grnxx/os.cpp
    lib/grnxx/storage/chunk-posix.cpp
    lib/grnxx/storage/chunk-windows.cpp
    lib/grnxx/storage/file-posix.cpp
    lib/grnxx/storage/file-windows.cpp
    lib/grnxx/storage/path.cpp
    lib/grnxx/thread.cpp
    test/Makefile.am
    test/test_logger.cpp
  Renamed files:
    lib/grnxx/errno.cpp
      (from lib/grnxx/error.cpp)
    lib/grnxx/errno.hpp
      (from lib/grnxx/error.hpp)
    test/test_errno.cpp
      (from test/test_error.cpp)

  Modified: .gitignore (+1 -1)
===================================================================
--- .gitignore    2013-06-28 17:46:15 +0900 (71336bc)
+++ .gitignore    2013-06-28 19:40:49 +0900 (a6fec36)
@@ -32,7 +32,7 @@ test/test_backtrace
 test/test_bytes
 test/test_charset
 test/test_duration
-test/test_error
+test/test_errno
 test/test_exception
 test/test_features
 test/test_geo_point

  Modified: lib/grnxx/Makefile.am (+2 -2)
===================================================================
--- lib/grnxx/Makefile.am    2013-06-28 17:46:15 +0900 (ca8cf7c)
+++ lib/grnxx/Makefile.am    2013-06-28 19:40:49 +0900 (cfd2ae6)
@@ -19,7 +19,7 @@ libgrnxx_la_SOURCES =			\
 	broken_down_time.cpp		\
 	charset.cpp			\
 	duration.cpp			\
-	error.cpp			\
+	errno.cpp			\
 	geo_point.cpp			\
 	grnxx.cpp			\
 	logger.cpp			\
@@ -45,7 +45,7 @@ libgrnxx_include_HEADERS =		\
 	bytes.hpp			\
 	charset.hpp			\
 	duration.hpp			\
-	error.hpp			\
+	errno.hpp			\
 	exception.hpp			\
 	features.hpp			\
 	flags_impl.hpp			\

  Renamed: lib/grnxx/errno.cpp (+35 -18) 53%
===================================================================
--- lib/grnxx/error.cpp    2013-06-28 17:46:15 +0900 (2e3a0b7)
+++ lib/grnxx/errno.cpp    2013-06-28 19:40:49 +0900 (b0e1b34)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2012  Brazil, Inc.
+  Copyright (C) 2012-2013  Brazil, Inc.
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -15,12 +15,11 @@
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
-#include "grnxx/error.hpp"
+#include "grnxx/errno.hpp"
+
+#include <string.h>
 
 #ifdef GRNXX_WINDOWS
-# ifndef NOMINMAX
-#  define NOMINMAX
-# endif  // NOMINMAX
 # include <windows.h>
 #endif  // GRNXX_WINDOWS
 
@@ -31,6 +30,8 @@
 namespace grnxx {
 namespace {
 
+constexpr size_t MESSAGE_BUF_SIZE = 256;
+
 #ifdef GRNXX_WINDOWS
 class Freer {
  public:
@@ -42,36 +43,52 @@ class Freer {
 
 }  // namespace
 
-StringBuilder &Error::write_to(StringBuilder &builder) const {
+StringBuilder &Errno::write_to(StringBuilder &builder) const {
   switch (type_) {
-    case POSIX_ERROR: {
-      return builder << '(' << std::strerror(posix_error_) << ')';
+    case STANDARD_ERRNO: {
+      // Note that a string returned by ::strerror() may be modified by a
+      // subsequent call to ::perror() or ::strerror().
+      const char *message = "n/a";
+#ifdef GRNXX_MSC
+      char message_buf[MESSAGE_BUF_SIZE];
+      if (::strerror_s(message_buf, MESSAGE_BUF_SIZE, standard_errno_) == 0) {
+        message = message_buf;
+      }
+#elif defined(GRNXX_HAS_XSI_STRERROR)
+      char message_buf[MESSAGE_BUF_SIZE];
+      if (::strerror_r(standard_errno_, message_buf, MESSAGE_BUF_SIZE) == 0) {
+        message = message_buf;
+      }
+#elif defined(GRNXX_HAS_GNU_STRERROR)
+      // ::strerror_r() may not use "message_buf" when an immutable error
+      // message is available.
+      char message_buf[MESSAGE_BUF_SIZE];
+      message = ::strerror_r(standard_errno_, message_buf, MESSAGE_BUF_SIZE);
+#else  // defined(GRNXX_HAS_GNU_STRERROR)
+      message = ::strerror(standard_errno_);
+#endif  // defined(GRNXX_HAS_GNU_STRERROR)
+      return builder << standard_errno_ << " (" << message << ')';
     }
 #ifdef GRNXX_WINDOWS
-    case WINDOWS_ERROR: {
+    case WINDOWS_ERRNO: {
       char *message;
       if (::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
                            FORMAT_MESSAGE_FROM_SYSTEM |
                            FORMAT_MESSAGE_IGNORE_INSERTS,
-                           nullptr, windows_error_,
+                           nullptr, windows_errno_,
                            MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
                            reinterpret_cast<LPSTR>(&message),
                            0, nullptr) != 0) {
         std::unique_ptr<char[], Freer> message_freer(message);
-        builder << '(' << message << ')';
+        builder << windows_errno_ << " (" << message << ')';
       } else {
-        builder << "(n/a)";
+        builder << windows_errno << " (n/a)";
       }
       return builder;
     }
 #endif  // GRNXX_WINDOWS
-    case GRNXX_ERROR: {
-      // TODO
-      // grnxx_error_
-      return builder << "(undefined)";
-    }
     default: {
-      return builder << "(undefined)";
+      return builder << "n/a";
     }
   }
 }

  Renamed: lib/grnxx/errno.hpp (+28 -38) 57%
===================================================================
--- lib/grnxx/error.hpp    2013-06-28 17:46:15 +0900 (4ffda9b)
+++ lib/grnxx/errno.hpp    2013-06-28 19:40:49 +0900 (6ff15cf)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2012  Brazil, Inc.
+  Copyright (C) 2012-2013  Brazil, Inc.
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -15,8 +15,8 @@
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
-#ifndef GRNXX_ERROR_HPP
-#define GRNXX_ERROR_HPP
+#ifndef GRNXX_ERRNO_HPP
+#define GRNXX_ERRNO_HPP
 
 #include "grnxx/features.hpp"
 
@@ -24,68 +24,58 @@ namespace grnxx {
 
 class StringBuilder;
 
-enum ErrorType {
-  POSIX_ERROR,
+enum ErrnoType {
+  STANDARD_ERRNO,
 #ifdef GRNXX_WINDOWS
-  WINDOWS_ERROR,
+  WINDOWS_ERRNO
 #endif  // GRNXX_WINDOWS
-  GRNXX_ERROR
 };
 
-enum ErrorCode {
-  // TODO
-};
-
-class Error {
+class GRNXX_EXPORT Errno {
  public:
   // For errno.
-  explicit Error(int error_code)
-      : type_(POSIX_ERROR),
-        posix_error_(error_code) {}
+  explicit Errno(int error_code)
+      : type_(STANDARD_ERRNO),
+        standard_errno_(error_code) {}
 #ifdef GRNXX_WINDOWS
-  // For DWORD returned by ::GetLastError().
-  explicit Error(unsigned long error_code)
-      : type_(WINDOWS_ERROR),
-        windows_error_(error_code) {}
+  // For DWORD returned by ::GetLastErrno().
+  explicit Errno(unsigned long error_code)
+      : type_(WINDOWS_ERRNO),
+        windows_errno_(error_code) {}
 #endif  // GRNXX_WINDOWS
-  explicit Error(ErrorCode error_code)
-      : type_(GRNXX_ERROR),
-        grnxx_error_(error_code) {}
 
-  ErrorType type() const {
+  // Return the errno type.
+  ErrnoType type() const {
     return type_;
   }
-  int posix_error() const {
-    return posix_error_;
+  // Return the standard errno.
+  int standard_errno() const {
+    return standard_errno_;
   }
 #ifdef GRNXX_WINDOWS
-  unsigned long windows_error() const {
-    return windows_error_;
+  // Return the windows errno.
+  unsigned long windows_errno() const {
+    return windows_errno_;
   }
 #endif  // GRNXX_WINDOWS
-  ErrorCode grnxx_error() const {
-    return grnxx_error_;
-  }
 
+  // Write a human-readable error message to "builder".
   StringBuilder &write_to(StringBuilder &builder) const;
 
  private:
-  ErrorType type_;
+  ErrnoType type_;
   union {
-    int posix_error_;
+    int standard_errno_;
 #ifdef GRNXX_WINDOWS
-    unsigned long windows_error_;
+    unsigned long windows_errno_;
 #endif  // GRNXX_WINDOWS
-    ErrorCode grnxx_error_;
   };
-
-  // Copyable.
 };
 
-inline StringBuilder &operator<<(StringBuilder &builder, const Error &error) {
+inline StringBuilder &operator<<(StringBuilder &builder, const Errno &error) {
   return error.write_to(builder);
 }
 
 }  // namespace grnxx
 
-#endif  // GRNXX_ERROR_HPP
+#endif  // GRNXX_ERRNO_HPP

  Modified: lib/grnxx/features.hpp (+13 -0)
===================================================================
--- lib/grnxx/features.hpp    2013-06-28 17:46:15 +0900 (6ef1091)
+++ lib/grnxx/features.hpp    2013-06-28 19:40:49 +0900 (60cc702)
@@ -144,6 +144,12 @@
 
 // Source features.
 
+#ifdef _GNU_SOURCE
+# define GRNXX_GNU_SOURCE _GNU_SOURCE
+#else  // _GNU_SOURCE
+# define GRNXX_GNU_SOURCE 0
+#endif  // _GNU_SOURCE
+
 #ifdef _POSIX_C_SOURCE
 # define GRNXX_POSIX_C_SOURCE _POSIX_C_SOURCE
 #else  // _POSIX_C_SOURCE
@@ -182,6 +188,13 @@
 
 // Available functions.
 
+#if ((GRNXX_POSIX_C_SOURCE >= 20112L) || (GRNXX_XOPEN_SOURCE >= 600)) &&\
+    !GRNXX_GNU_SOURCE
+# define GRNXX_HAS_XSI_STRERROR
+#else  // ((GRNXX_POSIX_C_SOURCE >= 20112L) || ...
+# define GRNXX_HAS_GNU_STRERROR
+#endif  // ((GRNXX_POSIX_C_SOURCE >= 20112L) || ...
+
 #if GRNXX_POSIX_C_SOURCE >= 199309L
 # define GRNXX_HAS_NANOSLEEP
 #endif  // GRNXX_POSIX_C_SOURCE >= 199309L

  Modified: lib/grnxx/os.cpp (+2 -2)
===================================================================
--- lib/grnxx/os.cpp    2013-06-28 17:46:15 +0900 (b871a69)
+++ lib/grnxx/os.cpp    2013-06-28 19:40:49 +0900 (6dab63b)
@@ -21,7 +21,7 @@
 #include <cstring>
 #include <cerrno>
 
-#include "grnxx/error.hpp"
+#include "grnxx/errno.hpp"
 #include "grnxx/lock.hpp"
 #include "grnxx/logger.hpp"
 
@@ -48,7 +48,7 @@ char *OS::get_environment_variable(const char *name) {
   size_t value_size;
   if (::_dupenv_s(&value, &value_size, name) != 0) {
     GRNXX_ERROR() << "failed to get environment variable: name = " << name
-                  << ": '::_dupenv_s' " << Error(errno);
+                  << ": '::_dupenv_s' " << Errno(errno);
     return nullptr;
   }
   char * const result = new (std::nothrow) char[value_size + 1];

  Modified: lib/grnxx/storage/chunk-posix.cpp (+5 -5)
===================================================================
--- lib/grnxx/storage/chunk-posix.cpp    2013-06-28 17:46:15 +0900 (89027d4)
+++ lib/grnxx/storage/chunk-posix.cpp    2013-06-28 19:40:49 +0900 (0047dcd)
@@ -26,7 +26,7 @@
 #include <memory>
 #include <new>
 
-#include "grnxx/error.hpp"
+#include "grnxx/errno.hpp"
 #include "grnxx/logger.hpp"
 #include "grnxx/storage/file.hpp"
 
@@ -47,7 +47,7 @@ ChunkImpl::ChunkImpl()
 ChunkImpl::~ChunkImpl() {
   if (address_ != MAP_FAILED) {
     if (::munmap(address_, static_cast<size_t>(size_)) != 0) {
-      GRNXX_ERROR() << "failed to unmap chunk: '::munmap' " << Error(errno);
+      GRNXX_ERROR() << "failed to unmap chunk: '::munmap' " << Errno(errno);
     }
   }
 }
@@ -91,7 +91,7 @@ bool ChunkImpl::sync(uint64_t offset, uint64_t size) {
   if (size > 0) {
     if (::msync(static_cast<char *>(address_) + offset, size, MS_SYNC) != 0) {
       GRNXX_ERROR() << "failed to sync chunk: offset = " << offset
-                    << ", size = " << size << ": '::msync' " << Error(errno);
+                    << ", size = " << size << ": '::msync' " << Errno(errno);
       return false;
     }
   }
@@ -148,7 +148,7 @@ bool ChunkImpl::create_file_backed_chunk(File *file, uint64_t offset,
                   << "file_path = " << file->path()
                   << ", file_size = " << file_size
                   << ", offset = " << offset << ", size = " << size
-                  << ", flags = " << flags << ": '::mmap' " << Error(errno);
+                  << ", flags = " << flags << ": '::mmap' " << Errno(errno);
     return false;
   }
   return true;
@@ -176,7 +176,7 @@ bool ChunkImpl::create_anonymous_chunk(uint64_t size, ChunkFlags flags) {
     address_ = ::mmap(nullptr, size, protection_flags, mmap_flags, -1, 0);
     if (address_ == MAP_FAILED) {
       GRNXX_ERROR() << "failed to map anonymous chunk: size = " << size
-                    << ", flags = " << flags << ": '::mmap' " << Error(errno);
+                    << ", flags = " << flags << ": '::mmap' " << Errno(errno);
       return false;
     }
   }

  Modified: lib/grnxx/storage/chunk-windows.cpp (+8 -8)
===================================================================
--- lib/grnxx/storage/chunk-windows.cpp    2013-06-28 17:46:15 +0900 (97c0bd5)
+++ lib/grnxx/storage/chunk-windows.cpp    2013-06-28 19:40:49 +0900 (0d0fc5f)
@@ -21,7 +21,7 @@
 
 #include <new>
 
-#include "grnxx/error.hpp"
+#include "grnxx/errno.hpp"
 #include "grnxx/logger.hpp"
 #include "grnxx/storage/file.hpp"
 
@@ -38,13 +38,13 @@ ChunkImpl::~ChunkImpl() {
   if (address_) {
     if (!::UnmapViewOfFile(address_)) {
       GRNXX_ERROR() << "failed to unmap chunk"
-                    << ": '::UnmapViewOfFile' " << Error(::GetLastError());
+                    << ": '::UnmapViewOfFile' " << Errno(::GetLastError());
     }
   }
   if (handle_) {
     if (!::CloseHandle(handle_)) {
       GRNXX_ERROR() << "failed to close file mapping"
-                    << ": '::CloseHandle' " << Error(::GetLastError());
+                    << ": '::CloseHandle' " << Errno(::GetLastError());
     }
   }
 }
@@ -85,7 +85,7 @@ bool ChunkImpl::sync(uint64_t offset, uint64_t size) {
   if (!::FlushViewOfFile(static_cast<char *>(address_) + offset, size)) {
     GRNXX_ERROR() << "failed to sync chunk: offset = " << offset
                   << ", size = " << size
-                  << ": '::FlushViewOfFile' " << Error(::GetLastError());
+                  << ": '::FlushViewOfFile' " << Errno(::GetLastError());
     return false;
   }
   return true;
@@ -130,7 +130,7 @@ bool ChunkImpl::create_file_backed_chunk(File *file, uint64_t offset,
                   << "file_path = " << file->path()
                   << ", file_size = " << file_size << ", offset = " << offset
                   << ", size = " << size << ", flags = " << flags
-                  << ": '::CreateFileMapping' " << Error(::GetLastError());
+                  << ": '::CreateFileMapping' " << Errno(::GetLastError());
     return false;
   }
   const DWORD offset_high = static_cast<DWORD>(offset >> 32);
@@ -142,7 +142,7 @@ bool ChunkImpl::create_file_backed_chunk(File *file, uint64_t offset,
                   << "file_path = " << file->path()
                   << ", file_size = " << file_size << ", offset = " << offset
                   << ", size = " << size << ", flags = " << flags
-                  << ": '::MapViewOfFile' " << Error(::GetLastError());
+                  << ": '::MapViewOfFile' " << Errno(::GetLastError());
     return false;
   }
   return true;
@@ -162,14 +162,14 @@ bool ChunkImpl::create_anonymous_chunk(uint64_t size, ChunkFlags flags) {
   if (!handle_) {
     GRNXX_ERROR() << "failed to create anonymous file mapping: "
                   << "size = " << size << ", flags = " << flags
-                  << ": '::CreateFileMapping' " << Error(::GetLastError());
+                  << ": '::CreateFileMapping' " << Errno(::GetLastError());
     return false;
   }
   address_ = ::MapViewOfFile(handle_, FILE_MAP_WRITE, 0, 0, 0);
   if (!address_) {
     GRNXX_ERROR() << "failed to map anonymous chunk: "
                   << "size = " << size << ", flags = " << flags
-                  << ": '::MapViewOfFile' " << Error(::GetLastError());
+                  << ": '::MapViewOfFile' " << Errno(::GetLastError());
     return false;
   }
   return true;

  Modified: lib/grnxx/storage/file-posix.cpp (+12 -12)
===================================================================
--- lib/grnxx/storage/file-posix.cpp    2013-06-28 17:46:15 +0900 (743bc85)
+++ lib/grnxx/storage/file-posix.cpp    2013-06-28 19:40:49 +0900 (f7207f8)
@@ -29,7 +29,7 @@
 #include <limits>
 #include <new>
 
-#include "grnxx/error.hpp"
+#include "grnxx/errno.hpp"
 #include "grnxx/logger.hpp"
 #include "grnxx/storage/path.hpp"
 
@@ -55,7 +55,7 @@ FileImpl::~FileImpl() {
     }
     if (::close(fd_) != 0) {
       GRNXX_ERROR() << "failed to close file: path = " << path_.get()
-                    << ": '::close' " << Error(errno);
+                    << ": '::close' " << Errno(errno);
     }
   }
 }
@@ -129,7 +129,7 @@ bool FileImpl::unlink(const char *path) {
   }
   if (::unlink(path) != 0) {
     GRNXX_WARNING() << "failed to unlink file: path = " << path
-                    << ": '::unlink' " << Error(errno);
+                    << ": '::unlink' " << Errno(errno);
     return false;
   }
   return true;
@@ -163,7 +163,7 @@ bool FileImpl::lock(FileLockFlags lock_flags) {
     }
     GRNXX_ERROR() << "failed to lock file: path = " << path_.get()
                   << ", lock_flags = " << lock_flags
-                  << ": '::flock' " << Error(errno);
+                  << ": '::flock' " << Errno(errno);
     return false;
   }
   locked_ = true;
@@ -177,7 +177,7 @@ bool FileImpl::unlock() {
   }
   if (::flock(fd_, LOCK_UN) != 0) {
     GRNXX_ERROR() << "failed to unlock file: path = " << path_.get()
-                  << ": '::flock' " << Error(errno);
+                  << ": '::flock' " << Errno(errno);
     return false;
   }
   locked_ = false;
@@ -187,7 +187,7 @@ bool FileImpl::unlock() {
 bool FileImpl::sync() {
   if (::fsync(fd_) != 0) {
     GRNXX_ERROR() << "failed to sync file: path = " << path_.get()
-                  << ": '::fsync' " << Error(errno);
+                  << ": '::fsync' " << Errno(errno);
     return false;
   }
   return true;
@@ -205,7 +205,7 @@ bool FileImpl::resize(uint64_t size) {
   if (::ftruncate(fd_, size) != 0) {
     GRNXX_ERROR() << "failed to resize file: path = " << path_.get()
                   << ", size = " << size
-                  << ": '::ftruncate' " << Error(errno);
+                  << ": '::ftruncate' " << Errno(errno);
     return false;
   }
   return true;
@@ -215,7 +215,7 @@ bool FileImpl::get_size(uint64_t *size) {
   struct stat stat;
   if (::fstat(fd_, &stat) != 0) {
     GRNXX_ERROR() << "failed to stat file: path = " << path_.get()
-                  << ": '::fstat' " << Error(errno);
+                  << ": '::fstat' " << Errno(errno);
     return false;
   }
   if (size) {
@@ -249,7 +249,7 @@ bool FileImpl::create_persistent_file(const char *path, FileFlags flags) {
   if (fd_ == -1) {
     GRNXX_ERROR() << "failed to create file: path = " << path
                   << ", flags = " << flags
-                  << ": '::open' " << Error(errno);
+                  << ": '::open' " << Errno(errno);
     return false;
   }
   return true;
@@ -272,7 +272,7 @@ bool FileImpl::create_temporary_file(const char *path, FileFlags flags) {
       return true;
     }
     GRNXX_WARNING() << "failed to create file: path = " << path_.get()
-                    << ": '::open' " << Error(errno);
+                    << ": '::open' " << Errno(errno);
   }
   GRNXX_ERROR() << "failed to create temporary file: "
                 << "path = " << path
@@ -294,7 +294,7 @@ bool FileImpl::open_file(const char *path, FileFlags flags) {
   if (fd_ == -1) {
     GRNXX_ERROR() << "failed to open file: path = " << path
                   << ", flags = " << flags
-                  << ": '::open' " << Error(errno);
+                  << ": '::open' " << Errno(errno);
     return false;
   }
   return true;
@@ -309,7 +309,7 @@ bool FileImpl::open_or_create_file(const char *path, FileFlags flags) {
   if (fd_ == -1) {
     GRNXX_ERROR() << "failed to open file: path = " << path
                   << ", flags = " << flags
-                  << ": '::open' " << Error(errno);
+                  << ": '::open' " << Errno(errno);
     return false;
   }
   return true;

  Modified: lib/grnxx/storage/file-windows.cpp (+13 -13)
===================================================================
--- lib/grnxx/storage/file-windows.cpp    2013-06-28 17:46:15 +0900 (919b59a)
+++ lib/grnxx/storage/file-windows.cpp    2013-06-28 19:40:49 +0900 (15f01d0)
@@ -26,7 +26,7 @@
 #include <limits>
 #include <new>
 
-#include "grnxx/error.hpp"
+#include "grnxx/errno.hpp"
 #include "grnxx/logger.hpp"
 #include "grnxx/storage/path.hpp"
 
@@ -52,7 +52,7 @@ FileImpl::~FileImpl() {
     }
     if (!::CloseHandle(handle_)) {
       GRNXX_ERROR() << "failed to close file: file = " << *this
-                    << ": '::CloseHandle' " << Error(::GetLastError());
+                    << ": '::CloseHandle' " << Errno(::GetLastError());
     }
   }
 }
@@ -127,7 +127,7 @@ bool FileImpl::unlink(const char *path) {
   }
   if (!::DeleteFile(path)) {
     GRNXX_WARNING() << "failed to unlink file: path = " << path
-                    << ": '::DeleteFile' " << Error(::GetLastError());
+                    << ": '::DeleteFile' " << Errno(::GetLastError());
     return false;
   }
   return true;
@@ -166,7 +166,7 @@ bool FileImpl::try_lock(FileLockMode mode) {
     }
     GRNXX_ERROR() << "failed to lock file: path = " << path_.get()
                   << ", mode = " << mode
-                  << ": '::LockFileEx' " << Error(last_error);
+                  << ": '::LockFileEx' " << Errno(last_error);
     return false;
   }
   locked_ = true;
@@ -184,7 +184,7 @@ bool FileImpl::unlock() {
   overlapped.OffsetHigh = 0x80000000U;
   if (!::UnlockFileEx(handle_, 0, 0, 0x80000000U, &overlapped)) {
     GRNXX_ERROR() << "failed to unlock file: path = " << path_.get()
-                  << ": '::UnlockFileEx' " << Error(::GetLastError());
+                  << ": '::UnlockFileEx' " << Errno(::GetLastError());
     return false;
   }
   locked_ = false;
@@ -194,7 +194,7 @@ bool FileImpl::unlock() {
 void FileImpl::sync() {
   if (!::FlushFileBuffers(handle_)) {
     GRNXX_ERROR() << "failed to sync file: path = " << path_.get()
-                  << ": '::FlushFileBuffers' " << Error(::GetLastError());
+                  << ": '::FlushFileBuffers' " << Errno(::GetLastError());
     return false;
   }
   return true;
@@ -214,13 +214,13 @@ bool FileImpl::resize(uint64_t size) {
   if (!::SetFilePointerEx(handle_, request, nullptr, FILE_BEGIN)) {
     GRNXX_ERROR() << "failed to seek file: path = " << path_.get()
                   << ", offset = " << offset << ", whence = " << whence
-                  << ": '::SetFilePointerEx' " << Error(::GetLastError());
+                  << ": '::SetFilePointerEx' " << Errno(::GetLastError());
     return false;
   }
   if (!::SetEndOfFile(handle_)) {
     GRNXX_ERROR() << "failed to resize file: path = " << path_.get()
                   << ", size = " << size
-                  << ": '::SetEndOfFile' " << Error(::GetLastError());
+                  << ": '::SetEndOfFile' " << Errno(::GetLastError());
     return false;
   }
   return true;
@@ -230,7 +230,7 @@ bool FileImpl::get_size(uint64_t *size) {
   LARGE_INTEGER file_size;
   if (!::GetFileSizeEx(handle_, &file_size)) {
     GRNXX_ERROR() << "failed to get file size: path = " << path_.get()
-                  << ": '::GetFileSizeEx' " << Error(::GetLastError());
+                  << ": '::GetFileSizeEx' " << Errno(::GetLastError());
     return false;
   }
   if (size) {
@@ -270,7 +270,7 @@ bool FileImpl::create_persistent_file(const char *path, FileFlags flags) {
   if (handle_ == INVALID_HANDLE_VALUE) {
     GRNXX_ERROR() << "failed to open file: path = " << path
                   << ", flags = " << flags
-                  << ": '::CreateFileA' " << Error(::GetLastError());
+                  << ": '::CreateFileA' " << Errno(::GetLastError());
     return false;
   }
   return true;
@@ -292,7 +292,7 @@ bool FileImpl::create_temporary_file(const char *path, FileFlags flags) {
       return true;
     }
     GRNXX_WARNING() << "failed to create file: path = " << path_.get()
-                    << ": '::CreateFileA' " << Error(::GetLastError());
+                    << ": '::CreateFileA' " << Errno(::GetLastError());
   }
   GRNXX_ERROR() << "failed to create temporary file: path = " << path
                 << ", flags = " << flags;
@@ -318,7 +318,7 @@ bool FileImpl::open_file(const char *path, FileFlags flags) {
   if (handle_ == INVALID_HANDLE_VALUE) {
     GRNXX_ERROR() << "failed to open file: path = " << path
                   << ", flags = " << flags
-                  << ": '::CreateFileA' " << Error(::GetLastError());
+                  << ": '::CreateFileA' " << Errno(::GetLastError());
     return false;
   }
   return true;
@@ -339,7 +339,7 @@ bool FileImpl::open_or_create_file(const char *path, FileFlags flags) {
   if (handle_ == INVALID_HANDLE_VALUE) {
     GRNXX_ERROR() << "failed to open file: path = " << path
                   << ", flags = " << flags
-                  << ": '::CreateFileA' " << Error(::GetLastError());
+                  << ": '::CreateFileA' " << Errno(::GetLastError());
     return false;
   }
   return true;

  Modified: lib/grnxx/storage/path.cpp (+3 -3)
===================================================================
--- lib/grnxx/storage/path.cpp    2013-06-28 17:46:15 +0900 (745d6f7)
+++ lib/grnxx/storage/path.cpp    2013-06-28 19:40:49 +0900 (f1c9458)
@@ -28,7 +28,7 @@
 #include <new>
 #include <random>
 
-#include "grnxx/error.hpp"
+#include "grnxx/errno.hpp"
 #include "grnxx/logger.hpp"
 #include "grnxx/string_builder.hpp"
 
@@ -49,7 +49,7 @@ char *Path::full_path(const char *path) {
 #ifdef GRNXX_WINDOWS
   if (!::_fullpath(full_path, path, sizeof(full_path))) {
     GRNXX_ERROR() << "failed to generate full path: path = " << path
-                  << ": '::_fullpath' " << Error(errno);
+                  << ": '::_fullpath' " << Errno(errno);
     return nullptr;
   }
   full_path_length = std::strlen(full_path);
@@ -57,7 +57,7 @@ char *Path::full_path(const char *path) {
   if (path[0] != '/') {
     if (!::getcwd(full_path, sizeof(full_path))) {
       GRNXX_ERROR() << "failed to get current working directory: '::getcwd' "
-                    << Error(errno);
+                    << Errno(errno);
       return nullptr;
     }
     full_path_length = std::strlen(full_path);

  Modified: lib/grnxx/thread.cpp (+8 -8)
===================================================================
--- lib/grnxx/thread.cpp    2013-06-28 17:46:15 +0900 (e656509)
+++ lib/grnxx/thread.cpp    2013-06-28 19:40:49 +0900 (e8cca39)
@@ -40,7 +40,7 @@
 //#include <chrono>
 //#include <thread>
 
-#include "grnxx/error.hpp"
+#include "grnxx/errno.hpp"
 #include "grnxx/logger.hpp"
 #include "grnxx/system_clock.hpp"
 
@@ -94,7 +94,7 @@ bool ThreadImpl::start(const Routine &routine) {
                                             routine_clone.get(), 0, nullptr);
   if (handle == 0) {
     GRNXX_ERROR() << "failed to create thread: '_beginthreadex' "
-                  << Error(errno);
+                  << Errno(errno);
     return false;
   }
   thread_ = reinterpret_cast<HANDLE>(handle);
@@ -103,7 +103,7 @@ bool ThreadImpl::start(const Routine &routine) {
                                      routine_clone.get());
   if (error != 0) {
     GRNXX_ERROR() << "failed to create thread: '::pthread_create' "
-                  << Error(error);
+                  << Errno(error);
     return false;
   }
 #endif  // GRNXX_WINDOWS
@@ -121,19 +121,19 @@ bool ThreadImpl::join() {
 #ifdef GRNXX_WINDOWS
   if (::WaitForSingleObject(thread_, INFINITE) == WAIT_FAILED) {
     GRNXX_ERROR() << "failed to join thread: '::WaitForSingleObject' "
-                  << Error(::GetLastError());
+                  << Errno(::GetLastError());
     result = false;
   }
   if (::CloseHandle(thread_) != 0) {
     GRNXX_ERROR() << "failed to close thread: '::CloseHandle' "
-                  << Error(::GetLastError());
+                  << Errno(::GetLastError());
     result = false;
   }
 #else  // GRNXX_WINDOWS
   const int error = ::pthread_join(thread_, nullptr);
   if (error != 0) {
     GRNXX_ERROR() << "failed to join thread: '::pthread_join' "
-                  << Error(error);
+                  << Errno(error);
     result = false;
   }
 #endif  // GRNXX_WINDOWS
@@ -150,14 +150,14 @@ bool ThreadImpl::detach() {
 #ifdef GRNXX_WINDOWS
   if (::CloseHandle(thread_) != 0) {
     GRNXX_ERROR() << "failed to detach thread: '::CloseHandle' "
-                  << Error(::GetLastError());
+                  << Errno(::GetLastError());
     result = false;
   }
 #else  // GRNXX_WINDOWS
   const int error = ::pthread_detach(thread_);
   if (error != 0) {
     GRNXX_ERROR() << "failed to detach thread: '::pthread_detach' "
-                  << Error(error);
+                  << Errno(error);
     result = false;
   }
 #endif  // GRNXX_WINDOWS

  Modified: test/Makefile.am (+3 -3)
===================================================================
--- test/Makefile.am    2013-06-28 17:46:15 +0900 (82d779a)
+++ test/Makefile.am    2013-06-28 19:40:49 +0900 (235667c)
@@ -6,7 +6,7 @@ TESTS =					\
 	test_bytes			\
 	test_charset			\
 	test_duration			\
-	test_error			\
+	test_errno			\
 	test_exception			\
 	test_features			\
 	test_geo_point			\
@@ -41,8 +41,8 @@ test_charset_LDADD = ../lib/grnxx/libgrnxx.la
 test_duration_SOURCES = test_duration.cpp
 test_duration_LDADD = ../lib/grnxx/libgrnxx.la
 
-test_error_SOURCES = test_error.cpp
-test_error_LDADD = ../lib/grnxx/libgrnxx.la
+test_errno_SOURCES = test_errno.cpp
+test_errno_LDADD = ../lib/grnxx/libgrnxx.la
 
 test_exception_SOURCES = test_exception.cpp
 test_exception_LDADD = ../lib/grnxx/libgrnxx.la

  Renamed: test/test_errno.cpp (+9 -4) 72%
===================================================================
--- test/test_error.cpp    2013-06-28 17:46:15 +0900 (1d14176)
+++ test/test_errno.cpp    2013-06-28 19:40:49 +0900 (f427bb4)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2012  Brazil, Inc.
+  Copyright (C) 2012-2013  Brazil, Inc.
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,7 @@
 #include <cassert>
 #include <cerrno>
 
-#include "grnxx/error.hpp"
+#include "grnxx/errno.hpp"
 #include "grnxx/logger.hpp"
 
 int main() {
@@ -26,7 +26,12 @@ int main() {
                            grnxx::LOGGER_ENABLE_COUT);
   grnxx::Logger::set_max_level(grnxx::NOTICE_LOGGER);
 
-  GRNXX_ERROR() << "EINVAL: " << grnxx::Error(EINVAL);
-  GRNXX_ERROR() << "12345: " << grnxx::Error(12345);
+  // Errnos required by the ISO C standard.
+  GRNXX_NOTICE() << "EDOM = " << grnxx::Errno(EDOM);
+  GRNXX_NOTICE() << "EILSEQ = " << grnxx::Errno(EILSEQ);
+  GRNXX_NOTICE() << "ERANGE = " << grnxx::Errno(ERANGE);
+
+  // An undefined errno.
+  GRNXX_NOTICE() << "-123456789 = " << grnxx::Errno(-123456789);
   return 0;
 }

  Modified: test/test_logger.cpp (+2 -2)
===================================================================
--- test/test_logger.cpp    2013-06-28 17:46:15 +0900 (f7dc66f)
+++ test/test_logger.cpp    2013-06-28 19:40:49 +0900 (a0445f2)
@@ -19,7 +19,7 @@
 #include <cerrno>
 #include <cstdio>
 
-#include "grnxx/error.hpp"
+#include "grnxx/errno.hpp"
 #include "grnxx/logger.hpp"
 
 //void f3() {
@@ -57,7 +57,7 @@ int main() {
   assert(std::fopen(path, "rb") == NULL);
 
   GRNXX_ERROR() << "failed to open file: <" << path << ">: 'fopen' "
-                << grnxx::Error(errno);
+                << grnxx::Errno(errno);
 
   GRNXX_LOGGER(0) << "Level: 0";
   GRNXX_LOGGER(1) << "Level: 1";
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index