/* metaflac - Command-line FLAC metadata editor
- * Copyright (C) 2001,2002,2003,2004,2005,2006 Josh Coalson
+ * Copyright (C) 2001,2002,2003,2004,2005,2006,2007,2008,2009 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
#include "options.h"
#include "utils.h"
#include "FLAC/assert.h"
-#include "share/grabbag.h" /* for grabbag__picture_parse_specification */
+#include "share/grabbag.h" /* for grabbag__picture_parse_specification() etc */
+
+#include "operations_shorthand.h"
static FLAC__bool import_pic_from(const char *filename, FLAC__StreamMetadata **picture, const char *specification, FLAC__bool *needs_write);
static FLAC__bool export_pic_to(const char *filename, const FLAC__StreamMetadata *picture, const char *pic_filename);
FLAC__metadata_iterator_init(iterator, chain);
switch(operation->type) {
- case OP__IMPORT_PICTURE:
+ case OP__IMPORT_PICTURE_FROM:
ok = import_pic_from(filename, &picture, operation->argument.specification.value, needs_write);
if(ok) {
/* append PICTURE block */
return false;
}
if(0 == strcmp(pic_filename, "-"))
- f = stdout;
+ f = grabbag__file_get_binary_stdout();
else
- f = fopen(pic_filename, "w");
+ f = fopen(pic_filename, "wb");
if(0 == f) {
fprintf(stderr, "%s: ERROR: can't open export file %s: %s\n", filename, pic_filename, strerror(errno));
if(fwrite(picture->data.picture.data, 1, len, f) != len) {
fprintf(stderr, "%s: ERROR: writing PICTURE data to file\n", filename);
+ if(f != stdout)
+ fclose(f);
return false;
}