Make GMappedFile optional.
authorJelmer Vernooij <jelmer@samba.org>
Wed, 7 Mar 2007 23:07:34 +0000 (00:07 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 7 Mar 2007 23:07:34 +0000 (00:07 +0100)
src/help.c
src/help.h

index f7990f15954d446405e31360ae9c6b6208f6e2ce..3ed543616307966f1c0de5219f2856b8427551b2 100644 (file)
 
 void help_free(help_t *h)
 {
+#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 8
        g_mapped_file_free(h->file);
+#else
+       g_free(h->file);
+#endif
        g_hash_table_destroy(h->entries);
        g_free(h);
 }
@@ -75,6 +79,7 @@ help_t *help_load_file( const char *helpfile )
        
        h = g_new0 (help_t, 1);
        
+#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 8
        h->file = g_mapped_file_new(helpfile, TRUE, &error);
        if (h->file != NULL) {
                len = g_mapped_file_get_length(h->file);
@@ -84,15 +89,21 @@ help_t *help_load_file( const char *helpfile )
        if( h->file == NULL ) {
                log_global(LOG_WARNING, "Unable to open help file `%s': %s", helpfile, 
                                  error->message);
-               g_free( h );
+               help_free( h );
                return NULL;
        }
+#else
+       if (!g_file_get_contents(helpfile, &h->file, &len, &error)) {
+               log_global(LOG_WARNING, "Unable to open help file `%s': %s", helpfile, 
+                                 error->message);
+               help_free( h );
+               return NULL;
+
+       } 
+#endif
 
        h->entries = help_build_hash(data, len);
-       if (h->entries == NULL) {
-               g_mapped_file_free(h->file);
-               g_free(h);
-       }
+
        return h;
 }
 
index 6d456cb1823ae5f4fce79d3489c0389224993893..cb4af51cc5450b936101f3dab3793c49bdb3abb2 100644 (file)
 
 typedef struct help
 {
+#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 8
        GMappedFile *file;
+#else
+       char *file;
+#endif
        GHashTable *entries;
 } help_t;