#include <glib/gi18n.h>
#include <string.h>
#include <stdlib.h>
+#include <stdio.h>
+#include <glib/gstdio.h>
#include "preferences.h"
#include "file.h"
g_error("Duplicate preferences group keys");
else {
g_ptr_array_add ( groups_names, g_strdup(name) );
- g_hash_table_insert ( groups_keys_to_indices, g_strdup(key), (gpointer) ((gint) groups_names->len ) ); /* index + 1 */
+ g_hash_table_insert ( groups_keys_to_indices, g_strdup(key), GINT_TO_POINTER ( (gint) groups_names->len ) ); /* index + 1 */
}
}
/* returns -1 if not found. */
static gint16 preferences_groups_key_to_index( const gchar *key )
{
- gint index = (gint) g_hash_table_lookup ( groups_keys_to_indices, key );
+ gint index = GPOINTER_TO_INT ( g_hash_table_lookup ( groups_keys_to_indices, key ) );
if ( ! index )
return VIK_LAYER_GROUP_NONE; /* which should be -1 anyway */
return (gint16) (index - 1);
*val = eq_pos + 1;
len = strlen(*val);
if ( len > 0 )
- (*val) [ len - 1 ] = '\0'; /* cut off newline */
+ if ( (*val)[len - 1] == '\n' )
+ (*val) [ len - 1 ] = '\0'; /* cut off newline */
return TRUE;
}
static gboolean preferences_load_from_file()
{
gchar *fn = g_build_filename(a_get_viking_dir(), VIKING_PREFS_FILE, NULL);
- FILE *f = fopen(fn, "r");
+ FILE *f = g_fopen(fn, "r");
g_free ( fn );
if ( f ) {
}
}
fclose(f);
+ f = NULL;
return TRUE;
}
return FALSE;
gchar *fn = g_build_filename(a_get_viking_dir(), VIKING_PREFS_FILE, NULL);
// TODO: error checking
- FILE *f = fopen(fn, "w");
+ FILE *f = g_fopen(fn, "w");
g_free ( fn );
if ( f ) {
file_write_layer_param ( f, param->name, val->type, val->data );
}
fclose(f);
+ f = NULL;
return TRUE;
}