Kouhei Sutou
null+****@clear*****
Thu Apr 16 22:47:03 JST 2015
Kouhei Sutou 2015-04-16 22:47:03 +0900 (Thu, 16 Apr 2015) New Revision: 005f98a4396d1f9fd94281aea07cd9d1a10bc93c https://github.com/groonga/groonga/commit/005f98a4396d1f9fd94281aea07cd9d1a10bc93c Message: Define portable mkstemp() as function Modified files: build/ac_macros/check_functions.m4 config.h.cmake lib/grn.h lib/grn_util.h lib/ii.c lib/util.c Modified: build/ac_macros/check_functions.m4 (+1 -1) =================================================================== --- build/ac_macros/check_functions.m4 2015-04-16 22:19:51 +0900 (388f746) +++ build/ac_macros/check_functions.m4 2015-04-16 22:47:03 +0900 (624adc7) @@ -7,7 +7,7 @@ AC_CHECK_FUNCS(_strnicmp) AC_CHECK_FUNCS(_strtoui64) AC_CHECK_FUNCS(gmtime_r) AC_CHECK_FUNCS(localtime_r) -AC_CHECK_FUNCS(mkostemp) +AC_CHECK_FUNCS(mkstemp) AC_CHECK_FUNCS(open) AC_CHECK_FUNCS(strcasecmp) AC_CHECK_FUNCS(strncasecmp) Modified: config.h.cmake (+1 -1) =================================================================== --- config.h.cmake 2015-04-16 22:19:51 +0900 (940ebc4) +++ config.h.cmake 2015-04-16 22:47:03 +0900 (d99a07a) @@ -147,7 +147,7 @@ #cmakedefine HAVE_FPCLASSIFY #cmakedefine HAVE_GMTIME_R #cmakedefine HAVE_LOCALTIME_R -#cmakedefine HAVE_MKOSTEMP +#cmakedefine HAVE_MKSTEMP #cmakedefine HAVE_OPEN #cmakedefine HAVE_STRCASECMP #cmakedefine HAVE_STRNCASECMP Modified: lib/grn.h (+1 -14) =================================================================== --- lib/grn.h 2015-04-16 22:19:51 +0900 (f7c5446) +++ lib/grn.h 2015-04-16 22:47:03 +0900 (0a7cf7c) @@ -1,5 +1,5 @@ /* -*- c-basic-offset: 2 -*- */ -/* Copyright(C) 2009-2014 Brazil +/* Copyright(C) 2009-2015 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -530,13 +530,6 @@ typedef int grn_cond; (*(p) = (v)) # endif /* ATOMIC 64BIT SET */ -# ifdef HAVE_MKOSTEMP -# define GRN_MKOSTEMP(template,flags,mode) mkostemp(template,flags) -# else /* HAVE_MKOSTEMP */ -# define GRN_MKOSTEMP(template,flags,mode) \ - (mktemp(template), GRN_OPEN((template),((flags)|O_RDWR|O_CREAT|O_EXCL),mode)) -# endif /* HAVE_MKOSTEMP */ - #elif (defined(WIN32) || defined (_WIN64)) /* __GNUC__ */ # define GRN_ATOMIC_ADD_EX(p,i,r) \ @@ -566,9 +559,6 @@ typedef int grn_cond; # define GRN_BIT_SCAN_REV(v,r) for (r = 31; r && !((1 << r) & v); r--) # define GRN_BIT_SCAN_REV0(v,r) GRN_BIT_SCAN_REV(v,r) -# define GRN_MKOSTEMP(template,flags,mode) \ - (mktemp(template), GRN_OPEN((template),((flags)|O_RDWR|O_CREAT),mode)) - #else /* __GNUC__ */ # if (defined(__sun) && defined(__SVR4)) /* ATOMIC ADD */ @@ -584,9 +574,6 @@ typedef int grn_cond; # define GRN_BIT_SCAN_REV(v,r) for (r = 31; r && !((1 << r) & v); r--) # define GRN_BIT_SCAN_REV0(v,r) GRN_BIT_SCAN_REV(v,r) -# define GRN_MKOSTEMP(template,flags,mode) \ - (mktemp(template), GRN_OPEN((template),flags,mode)) - #endif /* __GNUC__ */ typedef uint8_t byte; Modified: lib/grn_util.h (+3 -1) =================================================================== --- lib/grn_util.h 2015-04-16 22:19:51 +0900 (84aa357) +++ lib/grn_util.h 2015-04-16 22:47:03 +0900 (073d888) @@ -1,5 +1,5 @@ /* -*- c-basic-offset: 2 -*- */ -/* Copyright(C) 2010-2011 Brazil +/* Copyright(C) 2010-2015 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -29,6 +29,8 @@ GRN_API grn_rc grn_normalize_offset_and_limit(grn_ctx *ctx, int size, int *offse GRN_API const char *grn_win32_base_dir(void); GRN_API char *grn_path_separator_to_system(char *dest, char *groonga_path); +int grn_mktemp(char *path_template); + #ifdef __cplusplus } #endif Modified: lib/ii.c (+1 -7) =================================================================== --- lib/ii.c 2015-04-16 22:19:51 +0900 (ad60a1f) +++ lib/ii.c 2015-04-16 22:47:03 +0900 (e34a554) @@ -7718,16 +7718,10 @@ grn_ii_buffer_open(grn_ctx *ctx, grn_ii *ii, if (ii_buffer->counters) { ii_buffer->block_buf = GRN_MALLOCN(grn_id, II_BUFFER_BLOCK_SIZE); if (ii_buffer->block_buf) { - int open_flags = 0; -#ifdef WIN32 - open_flags |= O_BINARY; -#endif snprintf(ii_buffer->tmpfpath, PATH_MAX, "%sXXXXXX", grn_io_path(ii->seg)); ii_buffer->block_buf_size = II_BUFFER_BLOCK_SIZE; - ii_buffer->tmpfd = GRN_MKOSTEMP(ii_buffer->tmpfpath, - open_flags, - S_IRUSR|S_IWUSR); + ii_buffer->tmpfd = grn_mktemp(ii_buffer->tmpfpath); if (ii_buffer->tmpfd != -1) { grn_obj_flags flags; grn_table_get_info(ctx, ii->lexicon, &flags, NULL, NULL, NULL, NULL); Modified: lib/util.c (+39 -0) =================================================================== --- lib/util.c 2015-04-16 22:19:51 +0900 (6ef00f5) +++ lib/util.c 2015-04-16 22:47:03 +0900 (a99f3cd) @@ -24,6 +24,11 @@ #include <string.h> #include <stdio.h> +#include <stdlib.h> + +#ifdef WIN32 +# include <io.h> +#endif /* WIN32 */ grn_rc grn_normalize_offset_and_limit(grn_ctx *ctx, int size, int *p_offset, int *p_limit) @@ -1339,3 +1344,37 @@ grn_win32_base_dir(void) return win32_base_dir; } #endif + +#ifdef WIN32 +int +grn_mkstemp(char *path_template) +{ + errno_t error; + int fd; + size_t path_template_size; + + path_template_size = strlen(path_template) + 1; + error = _mktemp_s(path_template, path_template_size); + if (error != 0) { + return -1; + } + + error = fopen_s(&fd, path_template, "wb"); + if (error != 0) { + return -1; + } + + return fd; +} +#else /* WIN32 */ +int +grn_mkstemp(char *path_template) +{ +# ifdef HAVE_MKSTEMP + return mkstemp(path_template); +# else /* HAVE_MKSTEMP */ + mktemp(path_template); + return open(path_template, O_RDWR | O_CREAT | OEXCL, S_IRUSR | S_IWUSR); +# endif /* HAVE_MKSTEMP */ +} +#endif /* WIN32 */ -------------- next part -------------- HTML����������������������������... Download