- gint i;
- for ( i = 0; i < num_scales; i++ ) {
- if ( ABS(scale_mpps[i] - mpp) < ERROR_MARGIN ) {
- g_debug ( "mpp_to_zoom: %f -> %d", mpp, i );
- return i;
- }
- }
- // Handle mpp smaller than 1
- // return a useful value such that '17 - this number' gives a natural number.
- // Ideally should return '-1' or '0.5' but that's tricky with an unsigned int type!
- // (i.e. should rework to support zoom levels of 18 or 19)
- return 0;
+ GFileIOStream *gios;
+ GError *error = NULL;
+ gchar *tmpname = NULL;
+
+#if GLIB_CHECK_VERSION(2,32,0)
+ GFile *gf = g_file_new_tmp ( "vik-tmp.XXXXXX", &gios, &error );
+ tmpname = g_file_get_path (gf);
+#else
+ gint fd = g_file_open_tmp ( "vik-tmp.XXXXXX", &tmpname, &error );
+ if ( error ) {
+ g_warning ( "%s", error->message );
+ g_error_free ( error );
+ return NULL;
+ }
+ gios = g_file_open_readwrite ( g_file_new_for_path (tmpname), NULL, &error );
+ if ( error ) {
+ g_warning ( "%s", error->message );
+ g_error_free ( error );
+ return NULL;
+ }
+#endif
+
+ gios = g_file_open_readwrite ( g_file_new_for_path (tmpname), NULL, &error );
+ if ( error ) {
+ g_warning ( "%s", error->message );
+ g_error_free ( error );
+ return NULL;
+ }
+
+ GOutputStream *gos = g_io_stream_get_output_stream ( G_IO_STREAM(gios) );
+ if ( g_output_stream_write ( gos, buffer, count, NULL, &error ) < 0 ) {
+ g_critical ( "Couldn't write tmp %s file due to %s", tmpname, error->message );
+ g_free (tmpname);
+ tmpname = NULL;
+ }
+
+ g_output_stream_close ( gos, NULL, &error );
+ g_object_unref ( gios );
+
+ return tmpname;