Navigation Menu

Skip to content

Commit

Permalink
windows: use _fsopen() instead of fopen_s()
Browse files Browse the repository at this point in the history
Because fopen_s() doesn't support shared open.
  • Loading branch information
kou committed Apr 16, 2015
1 parent 653b948 commit e2f27d9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
8 changes: 2 additions & 6 deletions include/groonga/portability.h
Expand Up @@ -68,13 +68,9 @@
#endif /* WIN32 */

#ifdef WIN32
# define grn_fopen(file, name, mode) do { \
if (fopen_s(&file, name, mode) != 0) { \
file = NULL; \
} \
} while (0)
# define grn_fopen(name, mode) _fsopen((name), (mode), _SH_DENYNO)
#else /* WIN32 */
# define grn_fopen(file, name, mode) (file) = fopen((name), (mode))
# define grn_fopen(name, mode) fopen((name), (mode))
#endif /* WIN32 */

#ifdef WIN32
Expand Down
6 changes: 5 additions & 1 deletion lib/ctx.c
Expand Up @@ -35,6 +35,10 @@
# include <netinet/in.h>
#endif /* HAVE_NETINET_IN_H */

#ifdef WIN32
# include <share.h>
#endif /* WIN32 */

#if defined(HAVE__LOCALTIME64_S) && defined(__GNUC__)
# ifdef _WIN64
# define localtime_s(tm, time) _localtime64_s(tm, time)
Expand Down Expand Up @@ -785,7 +789,7 @@ check_overcommit_memory(grn_ctx *ctx)
{
FILE *file;
int value;
grn_fopen(file, "/proc/sys/vm/overcommit_memory", "r");
file = grn_fopen("/proc/sys/vm/overcommit_memory", "r");
if (!file) { return; }
value = fgetc(file);
if (value != '1') {
Expand Down
8 changes: 6 additions & 2 deletions lib/logger.c
Expand Up @@ -24,6 +24,10 @@
#include <string.h>
#include <sys/stat.h>

#ifdef WIN32
# include <share.h>
#endif /* WIN32 */

#ifdef WIN32
# define fileno(file) _fileno(file)
#endif
Expand Down Expand Up @@ -65,7 +69,7 @@ default_logger_log(grn_ctx *ctx, grn_log_level level,
if (default_logger_path) {
CRITICAL_SECTION_ENTER(default_logger_lock);
if (!default_logger_file) {
grn_fopen(default_logger_file, default_logger_path, "a");
default_logger_file = grn_fopen(default_logger_path, "a");
default_logger_size = 0;
if (default_logger_file) {
struct stat stat;
Expand Down Expand Up @@ -330,7 +334,7 @@ default_query_logger_log(grn_ctx *ctx, unsigned int flag,
if (default_query_logger_path) {
CRITICAL_SECTION_ENTER(default_query_logger_lock);
if (!default_query_logger_file) {
grn_fopen(default_query_logger_file, default_query_logger_path, "a");
default_query_logger_file = grn_fopen(default_query_logger_path, "a");
default_query_logger_size = 0;
if (default_query_logger_file) {
struct stat stat;
Expand Down
8 changes: 6 additions & 2 deletions lib/mrb.c
@@ -1,6 +1,6 @@
/* -*- c-basic-offset: 2 -*- */
/*
Copyright(C) 2013 Brazil
Copyright(C) 2013-2015 Brazil
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -28,6 +28,10 @@

#include <ctype.h>

#ifdef WIN32
# include <share.h>
#endif /* WIN32 */

#define BUFFER_SIZE 2048
#define E_LOAD_ERROR (mrb_class_get(mrb, "LoadError"))

Expand Down Expand Up @@ -145,7 +149,7 @@ grn_mrb_load(grn_ctx *ctx, const char *path)
return mrb_nil_value();
}

grn_fopen(file, expanded_path, "r");
file = grn_fopen(expanded_path, "r");
if (!file) {
char message[BUFFER_SIZE];
mrb_value exception;
Expand Down

0 comments on commit e2f27d9

Please sign in to comment.