cst_file.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*************************************************************************/
  2. /* */
  3. /* Language Technologies Institute */
  4. /* Carnegie Mellon University */
  5. /* Copyright (c) 1999 */
  6. /* All Rights Reserved. */
  7. /* */
  8. /* Permission is hereby granted, free of charge, to use and distribute */
  9. /* this software and its documentation without restriction, including */
  10. /* without limitation the rights to use, copy, modify, merge, publish, */
  11. /* distribute, sublicense, and/or sell copies of this work, and to */
  12. /* permit persons to whom this work is furnished to do so, subject to */
  13. /* the following conditions: */
  14. /* 1. The code must retain the above copyright notice, this list of */
  15. /* conditions and the following disclaimer. */
  16. /* 2. Any modifications must be clearly marked as such. */
  17. /* 3. Original authors' names are not deleted. */
  18. /* 4. The authors' names are not used to endorse or promote products */
  19. /* derived from this software without specific prior written */
  20. /* permission. */
  21. /* */
  22. /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
  23. /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
  24. /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
  25. /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
  26. /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
  27. /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
  28. /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
  29. /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
  30. /* THIS SOFTWARE. */
  31. /* */
  32. /*************************************************************************/
  33. /* Author: Alan W Black (awb@cs.cmu.edu) */
  34. /* Date: August 2000 */
  35. /*************************************************************************/
  36. /* */
  37. /* Some File stuff */
  38. /* */
  39. /*************************************************************************/
  40. #ifndef _CST_FILE_H__
  41. #define _CST_FILE_H__
  42. #define CST_WRONG_FORMAT -2
  43. #define CST_ERROR_FORMAT -1
  44. #define CST_OK_FORMAT 0
  45. #ifdef UNDER_CE
  46. /* File access stuff (WinCE 2.11 is really damaged) */
  47. #include <windows.h>
  48. #include <winbase.h>
  49. typedef HANDLE cst_file;
  50. #elif __palmos__
  51. #include <PalmOS.h>
  52. #include <System/StdIOPalm.h>
  53. typedef FILE * cst_file;
  54. #else
  55. #include <stdio.h>
  56. typedef FILE * cst_file;
  57. #endif
  58. /* File mapping stuff */
  59. #ifdef _WIN32
  60. #include <windows.h>
  61. typedef struct cst_filemap_struct {
  62. void *mem;
  63. cst_file fh;
  64. size_t mapsize;
  65. HANDLE h;
  66. } cst_filemap;
  67. #elif __palmos__
  68. typedef struct cst_filemap_struct {
  69. void *mem;
  70. cst_file fh;
  71. unsigned int mapsize;
  72. int fd;
  73. } cst_filemap;
  74. #else
  75. typedef struct cst_filemap_struct {
  76. void *mem;
  77. cst_file fh;
  78. size_t mapsize;
  79. int fd;
  80. } cst_filemap;
  81. #endif
  82. #define CST_OPEN_WRITE (1<<0)
  83. #define CST_OPEN_READ (1<<1)
  84. #define CST_OPEN_APPEND (1<<2)
  85. #define CST_OPEN_BINARY (1<<3)
  86. #define CST_SEEK_ABSOLUTE 0
  87. #define CST_SEEK_RELATIVE 1
  88. #define CST_SEEK_ENDREL 2
  89. cst_file cst_fopen(const char *path, int mode);
  90. long cst_fwrite(cst_file fh, const void *buf, long size, long count);
  91. long cst_fread(cst_file fh, void *buf, long size, long count);
  92. int cst_fprintf(cst_file fh, const char *fmt, ...);
  93. int cst_sprintf(char *s, const char *fmt, ...);
  94. #if defined(__palmos__)
  95. #include <stdarg.h>
  96. int cst_vsprintf(char *s, const char *fmt, va_list args);
  97. #endif
  98. int cst_fclose(cst_file fh);
  99. int cst_fgetc(cst_file fh);
  100. /* These aren't LFS-compliant. I don't think we'll need >2G files. */
  101. long cst_ftell(cst_file fh);
  102. long cst_fseek(cst_file fh, long pos, int whence);
  103. long cst_filesize(cst_file fh);
  104. cst_filemap *cst_mmap_file(const char *path);
  105. int cst_munmap_file(cst_filemap *map);
  106. cst_filemap *cst_read_whole_file(const char *path);
  107. int cst_free_whole_file(cst_filemap *map);
  108. cst_filemap *cst_read_part_file(const char *path);
  109. int cst_free_part_file(cst_filemap *map);
  110. int cst_urlp(const char *url);
  111. cst_file cst_url_open(const char *url);
  112. #endif