saveutils.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* =============================================================================
  2. * PROGRAM: ularn
  3. * FILENAME: saveutils.h
  4. *
  5. * DESCRIPTION:
  6. * This module contains utilities used in loading and saving games.
  7. *
  8. * =============================================================================
  9. * EXPORTED VARIABLES
  10. *
  11. * FileSum : The current checksum for the file being written/read.
  12. *
  13. * =============================================================================
  14. * EXPORTED FUNCTIONS
  15. *
  16. * sum : Checksum calculation function
  17. * bwrite : Binary write with checksum update
  18. * bread : Binary read with checksum update.
  19. *
  20. * =============================================================================
  21. */
  22. #ifndef __SAVEUTILS_H
  23. #define __SAVEUTILS_H
  24. #include <stdio.h>
  25. /*
  26. * This is the current checksum value for bread and bwrite.
  27. */
  28. extern int FileSum;
  29. /* =============================================================================
  30. * FUNCTION: sum
  31. *
  32. * DESCRIPTION:
  33. * Checksum calculation function.
  34. *
  35. * PARAMETERS:
  36. *
  37. * data : A pointer to the data to be checksummed
  38. *
  39. * n : The number of bytes in Data to be checksummed
  40. *
  41. * RETURN VALUE:
  42. *
  43. * The checksum of data.
  44. */
  45. unsigned int sum(unsigned char *data, int n);
  46. /* =============================================================================
  47. * FUNCTION: bwrite
  48. *
  49. * DESCRIPTION:
  50. * Binary write function with checksum update.
  51. * Writes the binary data to the specified file and updates the FileSum for
  52. * the data written.
  53. *
  54. * PARAMETERS:
  55. *
  56. * fp : A pointer to the file being written
  57. *
  58. * buf : A pointer to the buffer to write.
  59. *
  60. * num : The number of characters in buf to write.
  61. *
  62. * RETURN VALUE:
  63. *
  64. * None.
  65. */
  66. void bwrite(FILE *fp, char *buf, long num);
  67. /* =============================================================================
  68. * FUNCTION: bread
  69. *
  70. * DESCRIPTION:
  71. * Binary read function with checksum update.
  72. * Read the binary data from the specified file and updates the FileSum for
  73. * the data read.
  74. *
  75. * PARAMETERS:
  76. *
  77. * fp : A pointer to the file being read
  78. *
  79. * buf : A pointer to the buffer to store the read data.
  80. *
  81. * num : The number of characters be read into buf.
  82. *
  83. * RETURN VALUE:
  84. *
  85. * None.
  86. */
  87. void bread(FILE *fp, char *buf, long num);
  88. #endif