Changeset 29934
- Timestamp:
- Dec 5, 2010, 9:29:03 PM (15 years ago)
- Location:
- trunk/psLib/src/types
- Files:
-
- 2 edited
-
psMetadataConfig.c (modified) (1 diff)
-
psMetadataConfig.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psMetadataConfig.c
r27056 r29934 1630 1630 } 1631 1631 1632 1633 bool psMetadataConfigWrite(psMetadata *md, 1634 const char *filename) 1635 { 1636 PS_ASSERT_METADATA_NON_NULL(md, NULL); 1637 PS_ASSERT_STRING_NON_EMPTY(filename, NULL); 1638 FILE *file; 1639 if ( !(file = fopen(filename, "w")) ) { 1640 psError(PS_ERR_IO, true, 1641 "Failed to open specified file, %s\n", filename); 1642 return false; 1643 } 1644 psString fileString = NULL; 1645 fileString = psMetadataConfigFormat(md); 1646 if (fileString == NULL) { 1647 psError(PS_ERR_BAD_PARAMETER_NULL, false, 1648 "psMetadataConfigFormat returned NULL.\n"); 1649 return false; 1650 } 1651 if (fprintf(file, "%s", fileString) != strlen(fileString)) { 1652 psError(PS_ERR_IO, true, "Failed to write contents of configuration file %s", filename); 1653 psFree(fileString); 1654 fclose(file); 1655 return false; 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 } 1650 char modeString[4]; 1651 snprintf (modeString, 4, "w%s", compress); 1652 1653 gzFile file = gzopen(filename, modeString); 1654 if (file == Z_NULL) { 1655 psError(PS_ERR_IO, true, "Failed to open specified file, %s\n", filename); 1656 psFree(fileString); 1657 return false; 1658 } 1659 1660 int nbytes = gzwrite (file, fileString, strlen(fileString)); 1661 if (nbytes != strlen(fileString)) { 1662 psError(PS_ERR_IO, true, "Failed to write contents of configuration file %s", filename); 1663 psFree(fileString); 1664 gzclose(file); 1665 return false; 1666 } 1667 psFree(fileString); 1668 if (gzclose(file) != Z_OK) { 1669 psError(PS_ERR_IO, true, "Failed to close file, %s\n", filename); 1670 return false; 1671 } 1672 } else { 1673 FILE *file = fopen(filename, "w"); 1674 if (file == NULL) { 1675 psError(PS_ERR_IO, true, "Failed to open specified file, %s\n", filename); 1676 psFree(fileString); 1677 return false; 1678 } 1679 1680 int nbytes = fwrite(fileString, 1, strlen(fileString), file); 1681 if (nbytes != strlen(fileString)) { 1682 psError(PS_ERR_IO, true, "Failed to write contents of configuration file %s", filename); 1683 psFree(fileString); 1684 fclose(file); 1685 return false; 1656 1686 } 1657 1687 psFree(fileString); 1658 1688 if (fclose(file) == EOF) { 1659 psError(PS_ERR_IO, true,1660 "Failed to close file, %s\n", filename);1661 return false;1662 }1663 return true;1689 psError(PS_ERR_IO, true, "Failed to close file, %s\n", filename); 1690 return false; 1691 } 1692 } 1693 return true; 1664 1694 } 1665 1695 -
trunk/psLib/src/types/psMetadataConfig.h
r11248 r29934 33 33 * a string, the formatting command must also be for a string. If the 34 34 * metadata type is any other data type, printing is not allowed. 35 * Currently, this function does not compress the output file 35 36 * 36 37 * @return psMetadataItem* : Pointer metadata item. … … 85 86 bool psMetadataConfigWrite( 86 87 psMetadata *md, ///< The metadata to convert 87 const char *filename ///< Name of file to write 88 const char *filename, ///< Name of file to write 89 const char *compress ///< Output compression options 88 90 ); 89 91 90 92 /** Converts a psMetadata structure (including any nested psMetadata) into a 91 93 * configuration file formatted string that is written a file stream. 94 * Currently, this function does not compress the output file 92 95 * 93 96 * @return bool: True if successful, otherwise false.
Note:
See TracChangeset
for help on using the changeset viewer.
