diff -Naur -x '*~' flac-1.1.3-beta2/src/metaflac/.gdb_history mine/src/metaflac/.gdb_history --- flac-1.1.3-beta2/src/metaflac/.gdb_history 1970-01-01 00:00:00.000000000 +0000 +++ mine/src/metaflac/.gdb_history 2006-10-28 08:24:22.000000000 +0000 @@ -0,0 +1,2 @@ +set height 0 +set width 0 diff -Naur -x '*~' flac-1.1.3-beta2/src/metaflac/operations.c mine/src/metaflac/operations.c --- flac-1.1.3-beta2/src/metaflac/operations.c 2006-09-28 18:18:45.000000000 +0000 +++ mine/src/metaflac/operations.c 2006-10-28 08:39:01.000000000 +0000 @@ -359,6 +359,7 @@ case OP__EXPORT_CUESHEET_TO: ok = do_shorthand_operation__cuesheet(filename, chain, operation, needs_write); break; + case OP__EXPORT_PICTURE: case OP__IMPORT_PICTURE: ok = do_shorthand_operation__picture(filename, chain, operation, needs_write); break; diff -Naur -x '*~' flac-1.1.3-beta2/src/metaflac/operations_shorthand_picture.c mine/src/metaflac/operations_shorthand_picture.c --- flac-1.1.3-beta2/src/metaflac/operations_shorthand_picture.c 2006-10-10 00:09:39.000000000 +0000 +++ mine/src/metaflac/operations_shorthand_picture.c 2006-10-29 08:15:36.000000000 +0000 @@ -16,6 +16,9 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include +#include + #if HAVE_CONFIG_H # include #endif @@ -29,11 +32,35 @@ static FLAC__bool import_pic_from(const char *filename, FLAC__StreamMetadata **picture, const char *specification, FLAC__bool *needs_write); +/* Write all of buf, even if write(2) is interrupted. */ +static ssize_t +full_write(int fd, const char *buf, size_t nbytes) +{ + ssize_t r, w = 0; + + /* Loop until nbytes of buf have been written. */ + while (w < nbytes) { + /* Keep trying until write succeeds without interruption. */ + do { + r = write(fd, buf + w, nbytes - w); + } while (r < 0 && errno == EINTR); + + if (r < 0) { + return r; + } + + w += r; + } + + return w; +} + FLAC__bool do_shorthand_operation__picture(const char *filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write) { FLAC__bool ok = true, has_type1 = false, has_type2 = false; FLAC__StreamMetadata *picture = 0; FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new(); + FLAC__StreamMetadata *block; if(0 == iterator) die("out of memory allocating iterator"); @@ -54,6 +81,43 @@ } } break; + case OP__EXPORT_PICTURE: + do { + block = FLAC__metadata_iterator_get_block(iterator); + ok &= (0 != block); + if(!ok) { + fprintf(stderr, "%s: ERROR: couldn't get block from chain\n", filename); + continue; + } + if (block->type != FLAC__METADATA_TYPE_PICTURE) + continue; + if (block->data.picture.type != FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER) + continue; + int fd = open(operation->argument.specification.value, O_WRONLY | O_EXCL | O_CREAT, 0644); + if (fd < 0) { + perror("open"); + ok = 0; + break; + } + + if(0 != block->data.picture.data) + if (full_write(fd, block->data.picture.data, block->data.picture.data_length) != block->data.picture.data_length) { + perror("write"); + ok = 0; + break; + } + if (fsync(fd) < 0) { + perror("fsync"); + ok = 0; + break; + } + if (close(fd) < 0) { + perror("close"); + ok = 0; + break; + } + } while(ok && FLAC__metadata_iterator_next(iterator)); + break; default: ok = false; FLAC__ASSERT(0); diff -Naur -x '*~' flac-1.1.3-beta2/src/metaflac/options.c mine/src/metaflac/options.c --- flac-1.1.3-beta2/src/metaflac/options.c 2006-09-26 00:52:23.000000000 +0000 +++ mine/src/metaflac/options.c 2006-10-28 10:47:20.000000000 +0000 @@ -72,6 +72,7 @@ { "export-tags-to", 1, 0, 0 }, { "import-cuesheet-from", 1, 0, 0 }, { "export-cuesheet-to", 1, 0, 0 }, + { "stupid-export-picture", 1, 0, 0 }, { "import-picture", 1, 0, 0 }, { "add-seekpoint", 1, 0, 0 }, { "add-replay-gain", 0, 0, 0 }, @@ -547,6 +548,14 @@ ok = false; } } + else if(0 == strcmp(opt, "stupid-export-picture")) { + op = append_shorthand_operation(options, OP__EXPORT_PICTURE); + FLAC__ASSERT(0 != option_argument); + if(!parse_string(option_argument, &(op->argument.specification.value))) { + fprintf(stderr, "ERROR (--%s): missing specification\n", opt); + ok = false; + } + } else if(0 == strcmp(opt, "import-picture")) { op = append_shorthand_operation(options, OP__IMPORT_PICTURE); FLAC__ASSERT(0 != option_argument); diff -Naur -x '*~' flac-1.1.3-beta2/src/metaflac/options.h mine/src/metaflac/options.h --- flac-1.1.3-beta2/src/metaflac/options.h 2006-09-25 15:21:49.000000000 +0000 +++ mine/src/metaflac/options.h 2006-10-28 07:50:44.000000000 +0000 @@ -60,6 +60,7 @@ OP__EXPORT_VC_TO, OP__IMPORT_CUESHEET_FROM, OP__EXPORT_CUESHEET_TO, + OP__EXPORT_PICTURE, OP__IMPORT_PICTURE, OP__ADD_SEEKPOINT, OP__ADD_REPLAY_GAIN,