/* * utility functions */ #include #include "util.h" #include "config.h" /* * effectively mkdir -p * create directory PATH, including any required parent directories, * using MODE as the file mode for each newly created directory. */ gboolean mkpath( char *path, mode_t mode ) { gchar *dir; struct stat statbuf; gboolean retval; if ( stat( path, &statbuf ) == 0 ) { if ( S_ISDIR( statbuf.st_mode )) { return TRUE; } else { return FALSE; } } if ( errno != ENOENT ) { return FALSE; } if ( mkdir( path, mode ) == 0 ) { return TRUE; } if ( errno != ENOENT ) { return FALSE; } dir = g_dirname( path ); retval = mkpath( dir, mode ); g_free( dir ); return retval; } time_t fat_to_unix( guint32 fatts ) { time_t unixts = 0; struct tm unixtm; memset( &unixtm, 0, sizeof( struct tm )); unixtm.tm_sec = ( fatts & 0x0000001f ); unixtm.tm_min = ( fatts & 0x000007e0 ) >> 5; unixtm.tm_hour = ( fatts & 0x0000f800 ) >> 11; unixtm.tm_mday = ( fatts & 0x001f0000 ) >> 16; unixtm.tm_mon = ( fatts & 0x01e00000 ) >> 21; unixtm.tm_year = ( fatts & 0xfe000000 ) >> 25; /* fixups */ unixtm.tm_sec *= 2; unixtm.tm_mon -= 1; unixtm.tm_year += 80; unixts = mktime( &unixtm ); return unixts; } guint32 unix_to_fat( time_t unixts ) { guint32 fatts = 0; struct tm *unixtm; unixtm = localtime( &unixts ); /* fixups */ unixtm->tm_sec /= 2; unixtm->tm_mon += 1; unixtm->tm_year -= 80; fatts = unixtm->tm_sec | ( unixtm->tm_min << 5 ) | ( unixtm->tm_hour << 11 ) | ( unixtm->tm_mday << 16 ) | ( unixtm->tm_mon << 21 ) | ( unixtm->tm_year << 25 ); return fatts; } /* * for some reason, libid3tag doesn't deal with UTF16BE, only UTF16LE. */ id3_utf16_t *id3_ucs4_utf16beduplicate( const id3_ucs4_t *in ) { id3_utf16_t *out = NULL; return out; } id3_ucs4_t *id3_utf16be_ucs4duplicate( const id3_utf16_t *in, guint16 len ) { id3_ucs4_t *out = NULL; id3_utf16_t *utf16string; guint16 i; /* swap the bytes. can't do it in-place because we'll destroy the original */ utf16string = g_malloc0( len ); for ( i = 0; i < len; i++ ) { utf16string[i] = GUINT16_FROM_BE( in[i] ); } /* now convert */ out = id3_utf16_ucs4duplicate( utf16string ); g_free( utf16string ); return out; }