From: Date: Sun, 8 Dec 2013 20:22:58 +0000 (-0800) Subject: untested attempt to add error checking X-Git-Url: https://diplodocus.org/git/flac-archive/commitdiff_plain/43f4f00bc3b007afe6bcf702d21956ca252b8f4c?hp=c7f3078d9716ad1ed0d727ff425bc1279bcd5676 untested attempt to add error checking untested because, oh look, i never submitted any build rules! --- diff --git a/apic-read.cc b/apic-read.cc index 0438a02..fd83ac8 100644 --- a/apic-read.cc +++ b/apic-read.cc @@ -1,4 +1,5 @@ #include +#include #include #include @@ -37,8 +38,19 @@ main(int argc, char **argv) (TagLib::ID3v2::AttachedPictureFrame *)(*it); TagLib::ByteVector data = frame->picture(); int fd = open(argv[2], O_CREAT | O_WRONLY); - write(fd, data.data(), data.size()); - close(fd); + ssize_t size = data.size(); + ssize_t status = write(fd, data.data(), size); + if (status < 0) { + perror("write"); + return 2; + } + if (status != size) { + fprintf(stderr, "wrote only %d bytes out of %d\n", status, size); + return 3; + } + if (close(fd) < 0) { + perror("close"); + } } return 0;