[Groonga-commit] groonga/groonga at 7801f02 [master] windows: use fopen_s() on Windows

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Wed Apr 15 22:22:35 JST 2015


Kouhei Sutou	2015-04-15 22:22:35 +0900 (Wed, 15 Apr 2015)

  New Revision: 7801f0285c3ca26996ba2d18a38ea07913541901
  https://github.com/groonga/groonga/commit/7801f0285c3ca26996ba2d18a38ea07913541901

  Message:
    windows: use fopen_s() on Windows

  Modified files:
    include/groonga/portability.h
    lib/ctx.c
    lib/logger.c
    lib/mrb.c
    plugins/query_expanders/tsv.c

  Modified: include/groonga/portability.h (+10 -0)
===================================================================
--- include/groonga/portability.h    2015-04-15 22:16:19 +0900 (4a15ba1)
+++ include/groonga/portability.h    2015-04-15 22:22:35 +0900 (02cbec0)
@@ -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 */

  Modified: lib/ctx.c (+1 -1)
===================================================================
--- lib/ctx.c    2015-04-15 22:16:19 +0900 (992faa0)
+++ lib/ctx.c    2015-04-15 22:22:35 +0900 (a5fc477)
@@ -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') {

  Modified: lib/logger.c (+2 -2)
===================================================================
--- lib/logger.c    2015-04-15 22:16:19 +0900 (b42733a)
+++ lib/logger.c    2015-04-15 22:22:35 +0900 (48821f8)
@@ -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;
@@ -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;

  Modified: lib/mrb.c (+1 -1)
===================================================================
--- lib/mrb.c    2015-04-15 22:16:19 +0900 (64df928)
+++ lib/mrb.c    2015-04-15 22:22:35 +0900 (ea17f35)
@@ -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;

  Modified: plugins/query_expanders/tsv.c (+1 -1)
===================================================================
--- plugins/query_expanders/tsv.c    2015-04-15 22:16:19 +0900 (51cb661)
+++ plugins/query_expanders/tsv.c    2015-04-15 22:22:35 +0900 (17385d2)
@@ -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] "
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index