Description: Fix all issues with -Wunused-result
 Eg:
 dcmqrcnf.cc:294:43: warning: ignoring return value of 'char* fgets(char*, int,
 FILE*)', declared with attribute warn_unused_result [-Wunused-result]
Author: Mathieu Malaterre <malat@debian.org>
Forwarded: no

--- dcmtk-3.6.1~20131114.orig/dcmimage/libsrc/dicoimg.cc
+++ dcmtk-3.6.1~20131114/dcmimage/libsrc/dicoimg.cc
@@ -680,8 +680,9 @@ int DiColorImage::writeRawPPM(FILE *stre
             if ((OutputData != NULL) && (OutputData->getData() != NULL))
             {
                 fprintf(stream, "P6\n%u %u\n%lu\n", Columns, Rows, DicomImageClass::maxval(bits));
-                fwrite(OutputData->getData(), OFstatic_cast(size_t, OutputData->getCount()), OutputData->getItemSize(), stream);
-                return 1;
+                size_t tobewritten = OutputData->getItemSize();
+                size_t written = fwrite(OutputData->getData(), OFstatic_cast(size_t, OutputData->getCount()), OutputData->getItemSize(), stream);
+                if( written == tobewritten) return 1;
             }
         }
     }
--- dcmtk-3.6.1~20131114.orig/dcmsign/libsrc/simaccon.cc
+++ dcmtk-3.6.1~20131114/dcmsign/libsrc/simaccon.cc
@@ -61,8 +61,15 @@ OFCondition SiMACConstructor::flushBuffe
   stream.flushBuffer(bufptr, bufLen);
   if (bufLen > 0)
   {
-    if (dumpFile) fwrite(bufptr, 1, (size_t)bufLen, dumpFile);
-    result = mac.digest((unsigned char *)bufptr, (unsigned long)bufLen);
+    size_t written = (size_t)bufLen;
+    if (dumpFile)
+      {
+      written = fwrite(bufptr, 1, (size_t)bufLen, dumpFile);
+      }
+    if( written == (size_t)bufLen )
+      result = mac.digest((unsigned char *)bufptr, (unsigned long)bufLen);
+    else
+      result = EC_DirectoryNotWritable;
   }
   return result;
 }
--- dcmtk-3.6.1~20131114.orig/dcmdata/libsrc/dcvrobow.cc
+++ dcmtk-3.6.1~20131114/dcmdata/libsrc/dcvrobow.cc
@@ -214,13 +214,21 @@ void DcmOtherByteOtherWord::printPixel(S
                     {
                         swapIfNecessary(EBO_LittleEndian, gLocalByteOrder, data, getLengthField(), sizeof(Uint16));
                         setByteOrder(EBO_LittleEndian);
-                        fwrite(data, sizeof(Uint16), OFstatic_cast(size_t, getLengthField() / sizeof(Uint16)), file);
+                        size_t tobewritten = OFstatic_cast(size_t, getLengthField() / sizeof(Uint16));
+                        size_t written = fwrite(data, sizeof(Uint16), tobewritten, file);
+                        if( written != tobewritten )
+                          DCMDATA_WARN("DcmOtherByteOtherWord: Some bytes were not written: " << (tobewritten - written) );
                     }
                 } else {
                     Uint8 *data = NULL;
                     getUint8Array(data);
                     if (data != NULL)
-                        fwrite(data, sizeof(Uint8), OFstatic_cast(size_t, getLengthField()), file);
+                      {
+                      size_t tobewritten = OFstatic_cast(size_t, getLengthField());
+                      size_t written = fwrite(data, sizeof(Uint8), tobewritten, file);
+                      if( written != tobewritten )
+                        DCMDATA_WARN("DcmOtherByteOtherWord: Some bytes were not written: " << (tobewritten - written) );
+                      }
                 }
                 fclose(file);
             } else {
--- dcmtk-3.6.1~20131114.orig/dcmimgle/libsrc/diimage.cc
+++ dcmtk-3.6.1~20131114/dcmimgle/libsrc/diimage.cc
@@ -809,31 +809,40 @@ int DiImage::writeBMP(FILE *stream,
                     swapBytes(OFreinterpret_cast(Uint8 *, palette), 256 * 4 /*byteLength*/, 4 /*valWidth*/);
             }
             /* write bitmap file header: do not write the struct because of 32-bit alignment */
-            fwrite(&fileHeader.bfType, sizeof(fileHeader.bfType), 1, stream);
-            fwrite(&fileHeader.bfSize, sizeof(fileHeader.bfSize), 1, stream);
-            fwrite(&fileHeader.bfReserved1, sizeof(fileHeader.bfReserved1), 1, stream);
-            fwrite(&fileHeader.bfReserved2, sizeof(fileHeader.bfReserved2), 1, stream);
-            fwrite(&fileHeader.bfOffBits, sizeof(fileHeader.bfOffBits), 1, stream);
+            size_t singleitem; // should always be equal to 1 in the following:
+            singleitem = fwrite(&fileHeader.bfType, sizeof(fileHeader.bfType), 1, stream);
+            singleitem = singleitem && fwrite(&fileHeader.bfSize, sizeof(fileHeader.bfSize), 1, stream);
+            singleitem = singleitem && fwrite(&fileHeader.bfReserved1, sizeof(fileHeader.bfReserved1), 1, stream);
+            singleitem = singleitem && fwrite(&fileHeader.bfReserved2, sizeof(fileHeader.bfReserved2), 1, stream);
+            singleitem = singleitem && fwrite(&fileHeader.bfOffBits, sizeof(fileHeader.bfOffBits), 1, stream);
             /* write bitmap info header: do not write the struct because of 32-bit alignment  */
-            fwrite(&infoHeader.biSize, sizeof(infoHeader.biSize), 1, stream);
-            fwrite(&infoHeader.biWidth, sizeof(infoHeader.biWidth), 1, stream);
-            fwrite(&infoHeader.biHeight, sizeof(infoHeader.biHeight), 1, stream);
-            fwrite(&infoHeader.biPlanes, sizeof(infoHeader.biPlanes), 1, stream);
-            fwrite(&infoHeader.biBitCount, sizeof(infoHeader.biBitCount), 1, stream);
-            fwrite(&infoHeader.biCompression, sizeof(infoHeader.biCompression), 1, stream);
-            fwrite(&infoHeader.biSizeImage, sizeof(infoHeader.biSizeImage), 1, stream);
-            fwrite(&infoHeader.biXPelsPerMeter, sizeof(infoHeader.biXPelsPerMeter), 1, stream);
-            fwrite(&infoHeader.biYPelsPerMeter, sizeof(infoHeader.biYPelsPerMeter), 1, stream);
-            fwrite(&infoHeader.biClrUsed, sizeof(infoHeader.biClrUsed), 1, stream);
-            fwrite(&infoHeader.biClrImportant, sizeof(infoHeader.biClrImportant), 1, stream);
+            singleitem = singleitem && fwrite(&infoHeader.biSize, sizeof(infoHeader.biSize), 1, stream);
+            singleitem = singleitem && fwrite(&infoHeader.biWidth, sizeof(infoHeader.biWidth), 1, stream);
+            singleitem = singleitem && fwrite(&infoHeader.biHeight, sizeof(infoHeader.biHeight), 1, stream);
+            singleitem = singleitem && fwrite(&infoHeader.biPlanes, sizeof(infoHeader.biPlanes), 1, stream);
+            singleitem = singleitem && fwrite(&infoHeader.biBitCount, sizeof(infoHeader.biBitCount), 1, stream);
+            singleitem = singleitem && fwrite(&infoHeader.biCompression, sizeof(infoHeader.biCompression), 1, stream);
+            singleitem = singleitem && fwrite(&infoHeader.biSizeImage, sizeof(infoHeader.biSizeImage), 1, stream);
+            singleitem = singleitem && fwrite(&infoHeader.biXPelsPerMeter, sizeof(infoHeader.biXPelsPerMeter), 1, stream);
+            singleitem = singleitem && fwrite(&infoHeader.biYPelsPerMeter, sizeof(infoHeader.biYPelsPerMeter), 1, stream);
+            singleitem = singleitem && fwrite(&infoHeader.biClrUsed, sizeof(infoHeader.biClrUsed), 1, stream);
+            singleitem = singleitem && fwrite(&infoHeader.biClrImportant, sizeof(infoHeader.biClrImportant), 1, stream);
             /* write color palette (if applicable) */
-            if (palette != NULL)
-                fwrite(palette, 4, 256, stream);
+            if (singleitem && palette != NULL)
+              {
+              size_t paletteitems = fwrite(palette, 4, 256, stream);
+              if( paletteitems != 256 ) singleitem = 0;
+              }
             /* write pixel data */
-            fwrite(data, 1, OFstatic_cast(size_t, bytes), stream);
+            if( singleitem )
+              {
+              size_t pddata = fwrite(data, 1, OFstatic_cast(size_t, bytes), stream);
+              if( pddata != OFstatic_cast(size_t, bytes)) singleitem = 0;
+              }
             /* delete color palette */
             delete[] palette;
-            result = 1;
+            if( singleitem )
+              result = 1;
         }
         /* delete pixel data */
         delete OFstatic_cast(char *, data);     // type cast necessary to avoid compiler warnings using gcc >2.95
--- dcmtk-3.6.1~20131114.orig/dcmimgle/libsrc/dimoimg.cc
+++ dcmtk-3.6.1~20131114/dcmimgle/libsrc/dimoimg.cc
@@ -2143,9 +2143,10 @@ int DiMonoImage::writeRawPPM(FILE *strea
                 fprintf(stream, "P6\n%u %u\n255\n", Columns, Rows);
             else
                 fprintf(stream, "P5\n%u %u\n%lu\n", Columns, Rows, DicomImageClass::maxval(bits));
-            fwrite(OutputData->getData(), OFstatic_cast(size_t, OutputData->getCount()), OutputData->getItemSize(), stream);
+            size_t tobewritten = OutputData->getItemSize();
+            size_t written = fwrite(OutputData->getData(), OFstatic_cast(size_t, OutputData->getCount()), OutputData->getItemSize(), stream);
             deleteOutputData();
-            return 1;
+            if( written == tobewritten ) return 1;
         }
     }
     return 0;
--- dcmtk-3.6.1~20131114.orig/dcmqrdb/libsrc/dcmqrcnf.cc
+++ dcmtk-3.6.1~20131114/dcmqrdb/libsrc/dcmqrcnf.cc
@@ -291,7 +291,12 @@ int DcmQueryRetrieveConfig::readConfigLi
    char *c;
 
    while (!feof(cnffp)) {
-      fgets(rcline, sizeof(rcline), cnffp); /* read line in configuration file */
+      char *ret = fgets(rcline, sizeof(rcline), cnffp); /* read line in configuration file */
+      if( !ret )
+        {
+        error = 1;
+        break;
+        }
       lineno++;
       if (feof(cnffp)) continue;
       if (rcline[0] == '#' || rcline[0] == 10 || rcline[0] == 13)
@@ -413,7 +418,12 @@ int DcmQueryRetrieveConfig::readHostTabl
    DcmQueryRetrieveConfigHostEntry *helpentry;
 
    while (!feof(cnffp)) {
-      fgets(rcline, sizeof(rcline), cnffp); /* read line in configuration file */
+      char *ret = fgets(rcline, sizeof(rcline), cnffp); /* read line in configuration file */
+      if( !ret )
+        {
+        error = 1;
+        break;
+        }
       (*lineno)++;
       if (feof(cnffp)) continue;
       if (rcline[0] == '#' || rcline[0] == 10 || rcline[0] == 13)
@@ -469,7 +479,12 @@ int DcmQueryRetrieveConfig::readVendorTa
    DcmQueryRetrieveConfigHostEntry *helpentry;
 
    while (!feof(cnffp)) {
-      fgets(rcline, sizeof(rcline), cnffp); /* read line in configuration file */
+      char * ret = fgets(rcline, sizeof(rcline), cnffp); /* read line in configuration file */
+      if( !ret )
+        {
+        error = 1;
+        break;
+        }
       (*lineno)++;
       if (feof(cnffp)) continue;
       if (rcline[0] == '#' || rcline[0] == 10 || rcline[0] == 13)
@@ -525,7 +540,12 @@ int DcmQueryRetrieveConfig::readAETable(
    DcmQueryRetrieveConfigAEEntry *helpentry;
 
    while (!feof(cnffp)) {
-      fgets(rcline, sizeof(rcline), cnffp); /* read line in configuration file */
+      char * ret = fgets(rcline, sizeof(rcline), cnffp); /* read line in configuration file */
+      if( !ret )
+        {
+        error = 1;
+        break;
+        }
       (*lineno)++;
       if (feof(cnffp)) continue;
       if (rcline[0] == '#' || rcline[0] == 10 || rcline[0] == 13)
--- dcmtk-3.6.1~20131114.orig/dcmqrdb/libsrc/dcmqrdbi.cc
+++ dcmtk-3.6.1~20131114/dcmqrdb/libsrc/dcmqrdbi.cc
@@ -3416,7 +3416,8 @@ OFCondition DcmQueryRetrieveIndexDatabas
 
       record.hstat = DVIF_objectIsNotNew;
       DB_lseek(handle_->pidx, OFstatic_cast(long, SIZEOF_STUDYDESC + idx * SIZEOF_IDXRECORD), SEEK_SET);
-      write(handle_->pidx, OFreinterpret_cast(char *, &record), SIZEOF_IDXRECORD);
+      ssize_t written = write(handle_->pidx, OFreinterpret_cast(char *, &record), SIZEOF_IDXRECORD);
+      if( written != SIZEOF_IDXRECORD ) result = EC_DirectoryNotWritable;
       DB_lseek(handle_->pidx, 0L, SEEK_SET);
       DB_unlock();
     }
--- dcmtk-3.6.1~20131114.orig/dcmpstat/apps/dcmp2pgm.cc
+++ dcmtk-3.6.1~20131114/dcmpstat/apps/dcmp2pgm.cc
@@ -363,9 +363,12 @@ static void dumpPresentationState(DVPres
         if (ofile)
         {
            fprintf(ofile, "P5\n%d %d 255\n", overlayWidth, overlayHeight);
-           fwrite(overlayData, overlayWidth, overlayHeight, ofile);
+           size_t written = fwrite(overlayData, overlayWidth, overlayHeight, ofile);
            fclose(ofile);
-           oss << " - written." << OFendl;
+           if( written == overlayHeight )
+             oss << " - written." << OFendl;
+           else
+             oss << " -write error-" << OFendl;
         } else oss << " -write error-" << OFendl;
       } else {
         oss << "        unable to access overlay data!" << OFendl;
@@ -546,8 +549,12 @@ int main(int argc, char *argv[])
                 {
                     OFLOG_DEBUG(dcmp2pgmLogger, "writing PGM file: " << opt_pgmName);
                     fprintf(outfile, "P5\n%ld %ld 255\n", width, height);
-                    fwrite(pixelData, (size_t)width, (size_t)height, outfile);
+                    size_t written = fwrite(pixelData, (size_t)width, (size_t)height, outfile);
                     fclose(outfile);
+                    if( written != (size_t)height ) {
+                      OFLOG_FATAL(dcmp2pgmLogger, "Can't create output data.");
+                      return 10;
+                    }
                 } else {
                     OFLOG_FATAL(dcmp2pgmLogger, "Can't create output file.");
                     return 10;
