Navigation Menu

Skip to content

Commit

Permalink
windows: use fopen_s() on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 15, 2015
1 parent 442f9b0 commit 7801f02
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
10 changes: 10 additions & 0 deletions include/groonga/portability.h
Expand Up @@ -61,4 +61,14 @@
} while (0)
#endif /* WIN32 */

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

#endif /* GROONGA_PORTABILITY_H */
2 changes: 1 addition & 1 deletion lib/ctx.c
Expand Up @@ -785,7 +785,7 @@ check_overcommit_memory(grn_ctx *ctx)
{
FILE *file;
int value;
file = fopen("/proc/sys/vm/overcommit_memory", "r");
grn_fopen(file, "/proc/sys/vm/overcommit_memory", "r");
if (!file) { return; }
value = fgetc(file);
if (value != '1') {
Expand Down
4 changes: 2 additions & 2 deletions lib/logger.c
Expand Up @@ -65,7 +65,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) {
default_logger_file = fopen(default_logger_path, "a");
grn_fopen(default_logger_file, default_logger_path, "a");
default_logger_size = 0;
if (default_logger_file) {
struct stat stat;
Expand Down Expand Up @@ -330,7 +330,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) {
default_query_logger_file = fopen(default_query_logger_path, "a");
grn_fopen(default_query_logger_file, default_query_logger_path, "a");
default_query_logger_size = 0;
if (default_query_logger_file) {
struct stat stat;
Expand Down
2 changes: 1 addition & 1 deletion lib/mrb.c
Expand Up @@ -145,7 +145,7 @@ grn_mrb_load(grn_ctx *ctx, const char *path)
return mrb_nil_value();
}

file = fopen(expanded_path, "r");
grn_fopen(file, expanded_path, "r");
if (!file) {
char message[BUFFER_SIZE];
mrb_value exception;
Expand Down
2 changes: 1 addition & 1 deletion plugins/query_expanders/tsv.c
Expand Up @@ -210,7 +210,7 @@ load_synonyms(grn_ctx *ctx)
} else {
path = get_system_synonyms_file();
}
file = fopen(path, "r");
grn_fopen(file, path, "r");
if (!file) {
GRN_LOG(ctx, GRN_LOG_WARNING,
"[plugin][query-expander][tsv] "
Expand Down

0 comments on commit 7801f02

Please sign in to comment.