Changeset 29875
- Timestamp:
- Nov 29, 2010, 11:39:01 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20101103/psLib/src/types/psMetadataConfig.c
r29827 r29875 1630 1630 } 1631 1631 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 1632 bool 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 } 1639 1650 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); 1650 1652 1651 1653 gzFile file = gzopen(filename, modeString); 1652 1654 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; 1662 1658 } 1663 1659 1664 1660 int nbytes = gzwrite (file, fileString, strlen(fileString)); 1665 1661 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; 1670 1666 } 1671 1667 psFree(fileString); 1672 1668 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 { 1687 1673 FILE *file = fopen(filename, "w"); 1688 1674 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; 1699 1678 } 1700 1679 1701 1680 int nbytes = fwrite(fileString, 1, strlen(fileString), file); 1702 1681 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; 1707 1686 } 1708 1687 psFree(fileString); 1709 1688 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 } 1716 1695 1717 1696 bool psMetadataConfigPrint(FILE *stream,
Note:
See TracChangeset
for help on using the changeset viewer.
