size_t nr;
memset(buf, 0, sizeof(buf));
- fgetpos(f, &pos);
+ if ( !fgetpos(f, &pos) )
+ return FALSE;
rewind(f);
nr = fread(buf, 1, sizeof(buf) - 1, f);
- fsetpos(f, &pos);
+ if ( !fgetpos(f, &pos) )
+ return FALSE;
for (bp = buf; (bp < (buf + sizeof(buf) - 1)) && (nr > (bp - buf)); bp++) {
if (!(isspace(*bp)))
break;
void a_try_decompress_file (gchar *name)
{
#ifdef HAVE_MAGIC_H
+#ifdef MAGIC_VERSION
+ // Or magic_version() if available - probably need libmagic 5.18 or so
+ // (can't determine exactly which version the versioning became available)
+ g_debug ("%s: magic version: %d", __FUNCTION__, MAGIC_VERSION );
+#endif
magic_t myt = magic_open ( MAGIC_CONTINUE|MAGIC_ERROR|MAGIC_MIME );
gboolean zip = FALSE;
gboolean bzip2 = FALSE;
#ifdef WINDOWS
// We have to 'package' the magic database ourselves :(
// --> %PROGRAM FILES%\Viking\magic.mgc
- magic_load ( myt, "magic.mgc" );
+ int ml = magic_load ( myt, ".\\magic.mgc" );
#else
// Use system default
- magic_load ( myt, NULL );
+ int ml = magic_load ( myt, NULL );
#endif
- const char* magic = magic_file (myt, name);
- g_debug ("%s: magic output: %s", __FUNCTION__, magic );
+ if ( ml == 0 ) {
+ const char* magic = magic_file (myt, name);
+ g_debug ("%s: magic output: %s", __FUNCTION__, magic );
- if ( g_strcmp0 (magic, "application/zip; charset=binary") == 0 )
- zip = TRUE;
+ if ( g_strcmp0 (magic, "application/zip; charset=binary") == 0 )
+ zip = TRUE;
- if ( g_strcmp0 (magic, "application/x-bzip2; charset=binary") == 0 )
- bzip2 = TRUE;
+ if ( g_strcmp0 (magic, "application/x-bzip2; charset=binary") == 0 )
+ bzip2 = TRUE;
+ }
+ else {
+ g_critical ("%s: magic load database failure", __FUNCTION__ );
+ }
magic_close ( myt );
}
}
else if ( bzip2 ) {
gchar* bz2_name = uncompress_bzip2 ( name );
- g_remove ( name );
- g_rename ( bz2_name, name );
+ if ( bz2_name ) {
+ if ( g_remove ( name ) )
+ g_critical ("%s: remove file failed [%s]", __FUNCTION__, name );
+ if ( g_rename (bz2_name, name) )
+ g_critical ("%s: file rename failed [%s] to [%s]", __FUNCTION__, bz2_name, name );
+ }
}
return;
time_t tile_age = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "download_tile_age")->u;
/* Get the modified time of this file */
struct stat buf;
- g_stat ( fn, &buf );
+ (void)g_stat ( fn, &buf );
time_t file_time = buf.st_mtime;
if ( (time(NULL) - file_time) < tile_age ) {
/* File cache is too recent, so return */
} else {
gchar *dir = g_path_get_dirname ( fn );
- g_mkdir_with_parents ( dir , 0777 );
+ if ( g_mkdir_with_parents ( dir , 0777 ) != 0)
+ g_warning ("%s: Failed to mkdir %s", __FUNCTION__, dir );
g_free ( dir );
}
}
if (ret == CURL_DOWNLOAD_NO_NEWER_FILE) {
- g_remove ( tmpfilename );
+ (void)g_remove ( tmpfilename );
#if GLIB_CHECK_VERSION(2,18,0)
g_utime ( fn, NULL ); /* update mtime of local copy */
#else
}
tmp_file = fdopen(tmp_fd, "r+");
+ if ( !tmp_file )
+ return NULL;
if ( curl_download_uri ( uri, tmp_file, options, NULL, NULL ) ) {
// error
fclose ( tmp_file );
- g_remove ( tmpname );
+ (void)g_remove ( tmpname );
g_free ( tmpname );
return NULL;
}