IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29875


Ignore:
Timestamp:
Nov 29, 2010, 11:39:01 AM (15 years ago)
Author:
eugene
Message:

if no compression is requested, use standard fopen / fwrite functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101103/psLib/src/types/psMetadataConfig.c

    r29827 r29875  
    16301630}
    16311631
    1632 # if (PS_SLURP_GZIP)
    1633 bool psMetadataConfigWrite(psMetadata *md,
    1634                            const char *filename, const char *compress)
    1635 {
    1636     PS_ASSERT_METADATA_NON_NULL(md, NULL);
    1637     PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
    1638 
     1632bool psMetadataConfigWrite(psMetadata *md, const char *filename, const char *compress)
     1633{
     1634  PS_ASSERT_METADATA_NON_NULL(md, NULL);
     1635  PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     1636
     1637  psString fileString = NULL;
     1638  fileString = psMetadataConfigFormat(md);
     1639  if (fileString == NULL) {
     1640    psError(PS_ERR_BAD_PARAMETER_NULL, false, "psMetadataConfigFormat returned NULL.\n");
     1641    return false;
     1642  }
     1643
     1644  if (compress) {
     1645    if (strlen(compress) > 2) {
     1646      psError(PS_ERR_BAD_PARAMETER_VALUE, true, "invalid compression options %s", compress);
     1647      psFree(fileString);
     1648      return false;
     1649    }
    16391650    char modeString[4];
    1640 
    1641     if (compress) {
    1642         if (strlen(compress) > 2) {
    1643             psError(PS_ERR_BAD_PARAMETER_VALUE, true, "invalid compression options %s", compress);
    1644             return false;
    1645         }
    1646         snprintf (modeString, 4, "w%s", compress);
    1647     } else {
    1648         strcpy (modeString, "w0");
    1649     }   
     1651    snprintf (modeString, 4, "w%s", compress);
    16501652
    16511653    gzFile file = gzopen(filename, modeString);
    16521654    if (file == Z_NULL) {
    1653         psError(PS_ERR_IO, true, "Failed to open specified file, %s\n", filename);
    1654         return false;
    1655     }
    1656 
    1657     psString fileString = NULL;
    1658     fileString = psMetadataConfigFormat(md);
    1659     if (fileString == NULL) {
    1660         psError(PS_ERR_BAD_PARAMETER_NULL, false, "psMetadataConfigFormat returned NULL.\n");
    1661         return false;
     1655      psError(PS_ERR_IO, true, "Failed to open specified file, %s\n", filename);
     1656      psFree(fileString);
     1657      return false;
    16621658    }
    16631659
    16641660    int nbytes = gzwrite (file, fileString, strlen(fileString));
    16651661    if (nbytes != strlen(fileString)) {
    1666         psError(PS_ERR_IO, true, "Failed to write contents of configuration file %s", filename);
    1667         psFree(fileString);
    1668         gzclose(file);
    1669         return false;
     1662      psError(PS_ERR_IO, true, "Failed to write contents of configuration file %s", filename);
     1663      psFree(fileString);
     1664      gzclose(file);
     1665      return false;
    16701666    }
    16711667    psFree(fileString);
    16721668    if (gzclose(file) != Z_OK) {
    1673         psError(PS_ERR_IO, true, "Failed to close file, %s\n", filename);
    1674         return false;
    1675     }
    1676     return true;
    1677 }
    1678 
    1679 # else
    1680 
    1681 bool psMetadataConfigWrite(psMetadata *md,
    1682                            const char *filename, const char *compress)
    1683 {
    1684     PS_ASSERT_METADATA_NON_NULL(md, NULL);
    1685     PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
    1686 
     1669      psError(PS_ERR_IO, true, "Failed to close file, %s\n", filename);
     1670      return false;
     1671    }
     1672  } else {
    16871673    FILE *file = fopen(filename, "w");
    16881674    if (file == NULL) {
    1689         psError(PS_ERR_IO, true,
    1690                 "Failed to open specified file, %s\n", filename);
    1691         return false;
    1692     }
    1693 
    1694     psString fileString = NULL;
    1695     fileString = psMetadataConfigFormat(md);
    1696     if (fileString == NULL) {
    1697         psError(PS_ERR_BAD_PARAMETER_NULL, false, "psMetadataConfigFormat returned NULL.\n");
    1698         return false;
     1675      psError(PS_ERR_IO, true, "Failed to open specified file, %s\n", filename);
     1676      psFree(fileString);
     1677      return false;
    16991678    }
    17001679
    17011680    int nbytes = fwrite(fileString, 1, strlen(fileString), file);
    17021681    if (nbytes != strlen(fileString)) {
    1703         psError(PS_ERR_IO, true, "Failed to write contents of configuration file %s", filename);
    1704         psFree(fileString);
    1705         fclose(file);
    1706         return false;
     1682      psError(PS_ERR_IO, true, "Failed to write contents of configuration file %s", filename);
     1683      psFree(fileString);
     1684      fclose(file);
     1685      return false;
    17071686    }
    17081687    psFree(fileString);
    17091688    if (fclose(file) == EOF) {
    1710         psError(PS_ERR_IO, true, "Failed to close file, %s\n", filename);
    1711         return false;
    1712     }
    1713     return true;
    1714 }
    1715 # endif /* PS_SLURP_GZIP */
     1689      psError(PS_ERR_IO, true, "Failed to close file, %s\n", filename);
     1690      return false;
     1691    }
     1692  }
     1693  return true;
     1694}
    17161695
    17171696bool psMetadataConfigPrint(FILE *stream,
Note: See TracChangeset for help on using the changeset viewer.