Kouhei Sutou
null+****@clear*****
Fri Jun 26 15:09:36 JST 2015
Kouhei Sutou 2015-06-26 15:09:36 +0900 (Fri, 26 Jun 2015) New Revision: 4a74de98185431b769dc205fe0da4c04eb78d38d https://github.com/groonga/groonga/commit/4a74de98185431b769dc205fe0da4c04eb78d38d Message: Report grn_unlink() error when grn_io_create() is failed Modified files: lib/error.c lib/grn_ctx.h lib/grn_error.h lib/io.c Modified: lib/error.c (+14 -0) =================================================================== --- lib/error.c 2015-06-26 13:18:22 +0900 (e14ef37) +++ lib/error.c 2015-06-26 15:09:36 +0900 (5613942) @@ -62,3 +62,17 @@ grn_current_error_message(void) return strerror(errno); } #endif + +const char * +grn_strerror(int error_code) +{ +#ifdef WIN32 +# define MESSAGE_BUFFER_SIZE 1024 + static char message[MESSAGE_BUFFER_SIZE]; + strerror_s(message, MESSAGE_BUFFER_SIZE, error_code); + return message; +# undef MESSAGE_BUFFER_SIZE +#else /* WIN32 */ + return strerror(error_code); +#endif /* WIN32 */ +} Modified: lib/grn_ctx.h (+2 -3) =================================================================== --- lib/grn_ctx.h 2015-06-26 13:18:22 +0900 (2f052f5) +++ lib/grn_ctx.h 2015-06-26 15:09:36 +0900 (4ba5f3c) @@ -153,7 +153,6 @@ GRN_API void grn_ctx_impl_set_current_error_message(grn_ctx *ctx); #ifdef WIN32 -#define SYSTEM_ERROR_MESSAGE_BUFFER_SIZE 1024 #define SERR(str) do {\ grn_rc rc;\ const char *system_message;\ @@ -333,8 +332,8 @@ GRN_API void grn_ctx_impl_set_current_error_message(grn_ctx *ctx); grn_rc rc;\ int errno_keep = errno;\ grn_bool show_errno = GRN_FALSE;\ - char system_message[SYSTEM_ERROR_MESSAGE_BUFFER_SIZE];\ - strerror_s(system_message, SYSTEM_ERROR_MESSAGE_BUFFER_SIZE, errno);\ + const char *system_message;\ + system_message = grn_strerror(errno);\ switch (errno_keep) {\ case EPERM : rc = GRN_OPERATION_NOT_PERMITTED; break;\ case ENOENT : rc = GRN_NO_SUCH_FILE_OR_DIRECTORY; break;\ Modified: lib/grn_error.h (+1 -0) =================================================================== --- lib/grn_error.h 2015-06-26 13:18:22 +0900 (2581f93) +++ lib/grn_error.h 2015-06-26 15:09:36 +0900 (a0b18ca) @@ -27,6 +27,7 @@ extern "C" { #endif GRN_API const char *grn_current_error_message(void); +GRN_API const char *grn_strerror(int error_code); #ifdef __cplusplus } Modified: lib/io.c (+5 -1) =================================================================== --- lib/io.c 2015-06-26 13:18:22 +0900 (203b69d) +++ lib/io.c 2015-06-26 15:09:36 +0900 (6fe9ac0) @@ -314,7 +314,11 @@ grn_io_create(grn_ctx *ctx, const char *path, uint32_t header_size, uint32_t seg GRN_MUNMAP(&grn_gctx, NULL, &fis->fmo, fis, header, b); } grn_fileinfo_close(ctx, fis); - grn_unlink(path); + if (grn_unlink(path) == -1) { + GRN_LOG(ctx, GRN_LOG_ERROR, + "failed to grn_unlink() path on grn_io_create() error: <%s>", + path, grn_strerror(errno)); + } } GRN_GFREE(fis); } -------------- next part -------------- HTML����������������������������...Download