/* Write a libvips NULL-terminated utf-8 string into a entry tagged with a * encoding. UserComment is like this, for example. */ static void vips_exif_set_string_encoding( ExifData *ed, ExifEntry *entry, unsigned long component, const char *data ) { char *str; int len; str = drop_tail( data ); /* libexif can only really save ASCII to things like UserComment. */ #ifdef HAVE_G_STR_TO_ASCII { char *ascii; ascii = g_str_to_ascii( str, NULL ); g_free( str ); str = ascii; } #endif /*HAVE_G_STR_TO_ASCII*/ /* libexif comment strings are not NULL-terminated, and have an * encoding tag (always ASCII) in the first 8 bytes. */ len = strlen( str ); vips_exif_alloc_string( entry, sizeof( ASCII_COMMENT ) - 1 + len ); memcpy( entry->data, ASCII_COMMENT, sizeof( ASCII_COMMENT ) - 1 ); memcpy( entry->data + sizeof( ASCII_COMMENT ) - 1, str, len ); g_free( str ); }
/* Write a libvips NULL-terminated utf-8 string into an ASCII entry. Tags like * ImageDescription work like this. */ static void vips_exif_set_string_ascii( ExifData *ed, ExifEntry *entry, unsigned long component, const char *data ) { char *str; int len; str = drop_tail( data ); /* libexif can only really save ASCII to things like UserComment. */ #ifdef HAVE_G_STR_TO_ASCII { char *ascii; ascii = g_str_to_ascii( str, NULL ); g_free( str ); str = ascii; } #endif /*HAVE_G_STR_TO_ASCII*/ /* ASCII strings are NULL-terminated. */ len = strlen( str ); vips_exif_alloc_string( entry, len + 1 ); memcpy( entry->data, str, len + 1 ); entry->format = EXIF_FORMAT_ASCII; g_free( str ); }
int item_link(item *it) { int needed = it->ntotal; unsigned long long maxbytes; int maxitems; maxbytes = settings.maxbytes ? settings.maxbytes : UINT_MAX; maxitems = settings.maxitems ? settings.maxitems : INT_MAX; while(items_tail && (stats.curr_bytes + needed > maxbytes || stats.curr_items + 1 > maxitems)) { drop_tail(); } it->it_flags |= ITEM_LINKED; it->time = time(0); assoc_insert(it->key, (void *)it); stats.curr_bytes += needed; stats.curr_items += 1; stats.total_items += 1; item_link_q(it); return 1; }
/* Write a libvips NULL-terminated utf-8 string into a utf16 entry. */ static void vips_exif_set_string_utf16( ExifData *ed, ExifEntry *entry, unsigned long component, const char *data ) { char *str; gunichar2 *utf16; glong len; str = drop_tail( data ); utf16 = g_utf8_to_utf16( str, -1, NULL, &len, NULL ); /* libexif utf16 strings are NULL-terminated. */ vips_exif_alloc_string( entry, (len + 1) * 2 ); memcpy( entry->data, utf16, (len + 1) * 2 ); entry->format = EXIF_FORMAT_BYTE; g_free( utf16 ); g_free( str ); }