Navigation Menu

Skip to content

Commit

Permalink
windows: always use _close() on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 16, 2015
1 parent a80f0a7 commit 08f8cbd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
1 change: 0 additions & 1 deletion build/ac_macros/check_functions.m4
Expand Up @@ -5,7 +5,6 @@ AC_CHECK_FUNCS(_localtime64_s)
AC_CHECK_FUNCS(_stricmp)
AC_CHECK_FUNCS(_strnicmp)
AC_CHECK_FUNCS(_strtoui64)
AC_CHECK_FUNCS(close)
AC_CHECK_FUNCS(gmtime_r)
AC_CHECK_FUNCS(localtime_r)
AC_CHECK_FUNCS(mkostemp)
Expand Down
1 change: 0 additions & 1 deletion config.h.cmake
Expand Up @@ -144,7 +144,6 @@
#cmakedefine HAVE_BACKTRACE
#cmakedefine HAVE_CLOCK
#cmakedefine HAVE_CLOCK_GETTIME
#cmakedefine HAVE_CLOSE
#cmakedefine HAVE_FPCLASSIFY
#cmakedefine HAVE_GMTIME_R
#cmakedefine HAVE_LOCALTIME_R
Expand Down
6 changes: 6 additions & 0 deletions include/groonga/portability.h
Expand Up @@ -121,4 +121,10 @@
# define grn_read(fd, buf, count) read((fd), (buf), (count))
#endif /* WIN32 */

#ifdef WIN32
# define grn_close(fd) _close((fd))
#else /* WIN32 */
# define grn_close(fd) close((fd))
#endif /* WIN32 */

#endif /* GROONGA_PORTABILITY_H */
6 changes: 0 additions & 6 deletions lib/grn.h
Expand Up @@ -73,12 +73,6 @@
# define GRN_OPEN(pathname, ...) _open(pathname, __VA_ARGS__)
#endif /* HAVE_OPEN */

#ifdef HAVE_CLOSE
# define GRN_CLOSE(fd) close(fd)
#else
# define GRN_CLOSE(fd) _close(fd)
#endif /* HAVE_CLOSE */

#ifdef WIN32

# if defined(__GNUC__) && !defined(WINVER)
Expand Down
6 changes: 3 additions & 3 deletions lib/ii.c
Expand Up @@ -7759,7 +7759,7 @@ grn_ii_buffer_commit(grn_ctx *ctx, grn_ii_buffer *ii_buffer)
grn_ii_buffer_flush(ctx, ii_buffer);
}
if (ii_buffer->tmpfd != -1) {
GRN_CLOSE(ii_buffer->tmpfd);
grn_close(ii_buffer->tmpfd);
}
if (ii_buffer->block_buf) {
GRN_FREE(ii_buffer->block_buf);
Expand Down Expand Up @@ -7834,7 +7834,7 @@ grn_ii_buffer_commit(grn_ctx *ctx, grn_ii_buffer *ii_buffer)
GRN_LOG(ctx, GRN_LOG_NOTICE,
"tmpfile_size:%" GRN_FMT_INT64D " > total_chunk_size:%" GRN_FMT_SIZE,
ii_buffer->filepos, ii_buffer->total_chunk_size);
GRN_CLOSE(ii_buffer->tmpfd);
grn_close(ii_buffer->tmpfd);
grn_unlink(ii_buffer->tmpfpath);
ii_buffer->tmpfd = -1;
return ctx->rc;
Expand All @@ -7853,7 +7853,7 @@ grn_ii_buffer_close(grn_ctx *ctx, grn_ii_buffer *ii_buffer)
grn_obj_close(ctx, ii_buffer->tmp_lexicon);
}
if (ii_buffer->tmpfd != -1) {
GRN_CLOSE(ii_buffer->tmpfd);
grn_close(ii_buffer->tmpfd);
grn_unlink(ii_buffer->tmpfpath);
}
if (ii_buffer->block_buf) {
Expand Down
20 changes: 10 additions & 10 deletions lib/io.c
Expand Up @@ -68,7 +68,7 @@ static uint32_t grn_io_version_default = GRN_IO_VERSION_DEFAULT;
inline static grn_rc grn_open(grn_ctx *ctx, fileinfo *fi, const char *path, int flags);
inline static void grn_fileinfo_init(fileinfo *fis, int nfis);
inline static int grn_opened(fileinfo *fi);
inline static grn_rc grn_close(grn_ctx *ctx, fileinfo *fi);
inline static grn_rc grn_fileinfo_close(grn_ctx *ctx, fileinfo *fi);
#ifdef WIN32
inline static void * grn_mmap(grn_ctx *ctx, grn_io *io,
HANDLE *fmo, fileinfo *fi,
Expand Down Expand Up @@ -323,7 +323,7 @@ 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_close(ctx, fis);
grn_fileinfo_close(ctx, fis);
grn_unlink(path);
}
GRN_GFREE(fis);
Expand Down Expand Up @@ -493,7 +493,7 @@ grn_io_detect_type(grn_ctx *ctx, const char *path)
} else {
ERR(GRN_INVALID_FORMAT, "grn_io_detect_type failed");
}
GRN_CLOSE(fd);
grn_close(fd);
} else {
SERR(path);
}
Expand Down Expand Up @@ -526,7 +526,7 @@ grn_io_open(grn_ctx *ctx, const char *path, grn_io_mode mode)
}
}
}
GRN_CLOSE(fd);
grn_close(fd);
if (!segment_size) { return NULL; }
}
b = grn_io_compute_base(header_size);
Expand All @@ -546,7 +546,7 @@ grn_io_open(grn_ctx *ctx, const char *path, grn_io_mode mode)
fis = GRN_GMALLOCN(fileinfo, max_nfiles);
if (!fis) {
GRN_MUNMAP(&grn_gctx, NULL, &(fi.fmo), &fi, header, b);
grn_close(ctx, &fi);
grn_fileinfo_close(ctx, &fi);
return NULL;
}
grn_fileinfo_init(fis, max_nfiles);
Expand Down Expand Up @@ -581,7 +581,7 @@ grn_io_open(grn_ctx *ctx, const char *path, grn_io_mode mode)
GRN_GFREE(fis);
GRN_MUNMAP(&grn_gctx, NULL, &(fi.fmo), &fi, header, b);
}
grn_close(ctx, &fi);
grn_fileinfo_close(ctx, &fi);
}
return NULL;
}
Expand Down Expand Up @@ -627,7 +627,7 @@ grn_io_close(grn_ctx *ctx, grn_io *io)
int i;
for (i = 0; i < max_nfiles; i++) {
fileinfo *fi = &(io->fis[i]);
grn_close(ctx, fi);
grn_fileinfo_close(ctx, fi);
}
GRN_GFREE(io->fis);
}
Expand Down Expand Up @@ -1603,7 +1603,7 @@ grn_munmap(grn_ctx *ctx, grn_io *io,
}

inline static grn_rc
grn_close(grn_ctx *ctx, fileinfo *fi)
grn_fileinfo_close(grn_ctx *ctx, fileinfo *fi)
{
if (fi->fmo != NULL) {
CloseHandle(fi->fmo);
Expand Down Expand Up @@ -1715,10 +1715,10 @@ grn_opened(fileinfo *fi)
}

inline static grn_rc
grn_close(grn_ctx *ctx, fileinfo *fi)
grn_fileinfo_close(grn_ctx *ctx, fileinfo *fi)
{
if (fi->fd != -1) {
if (GRN_CLOSE(fi->fd) == -1) {
if (grn_close(fi->fd) == -1) {
SERR("close");
return ctx->rc;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/proc.c
Expand Up @@ -100,7 +100,7 @@ grn_bulk_put_from_file(grn_ctx *ctx, grn_obj *bulk, const char *path)
ERR(GRN_INVALID_ARGUMENT, "cannot stat file: <%s>", path);
}
exit :
GRN_CLOSE(fd);
grn_close(fd);
return ret;
}

Expand Down

0 comments on commit 08f8cbd

Please sign in to comment.