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
43#define CST_WRONG_FORMAT -2
44#define CST_ERROR_FORMAT -1
45#define CST_OK_FORMAT 0
46
47#ifdef UNDER_CE
48/* File access stuff (WinCE 2.11 is really damaged) */
49#include <windows.h>
50#include <winbase.h>
51typedef HANDLE cst_file;
52#elif __palmos__
53#include <PalmOS.h>
54#include <System/StdIOPalm.h>
55typedef FILE * cst_file;
56#else
57#include <stdio.h>
58typedef FILE * cst_file;
59#endif
60
61/* File mapping stuff */
62#ifdef _WIN32
63#include <windows.h>
64typedef struct cst_filemap_struct {
65 void *mem;
66 cst_file fh;
67 size_t mapsize;
68 HANDLE h;
69} cst_filemap;
70#elif __palmos__
71typedef struct cst_filemap_struct {
72 void *mem;
73 cst_file fh;
74 unsigned int mapsize;
75 int fd;
76} cst_filemap;
77#else
78typedef struct cst_filemap_struct {
79 void *mem;
80 cst_file fh;
81 size_t mapsize;
82 int fd;
83} cst_filemap;
84#endif
85
86#define CST_OPEN_WRITE (1<<0)
87#define CST_OPEN_READ (1<<1)
88#define CST_OPEN_APPEND (1<<2)
89/* We actually ignore this -- files are always opened in in binary mode */
90#define CST_OPEN_BINARY (1<<3)
91
92#define CST_SEEK_ABSOLUTE 0
93#define CST_SEEK_RELATIVE 1
94#define CST_SEEK_ENDREL 2
95
96cst_file cst_fopen(const char *path, int mode);
97long cst_fwrite(cst_file fh, const void *buf, long size, long count);
98long cst_fread(cst_file fh, void *buf, long size, long count);
99int cst_fprintf(cst_file fh, const char *fmt, ...);
100int cst_sprintf(char *s, const char *fmt, ...);
101#ifdef _WIN32
102#define snprintf c99_snprintf
103
104__inline int c99_vsnprintf(char* str, size_t size, const char* format,
105va_list ap) {
106 int count = -1;
107 if (size != 0)
108 count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
109 if (count == -1)
110 count = _vscprintf(format, ap);
111 return count;
112 }
113__inline int c99_snprintf(char* str, size_t size, const char* format, ...)
114{
115 int count;
116 va_list ap;
117
118 va_start(ap, format);
119 count = c99_vsnprintf(str, size, format, ap);
120 va_end(ap);
121 return count;
122 }
123#endif
124#define cst_snprintf snprintf
125
126#if defined(__palmos__)
127#include <stdarg.h>
128int cst_vsprintf(char *s, const char *fmt, va_list args);
129#endif
130int cst_fclose(cst_file fh);
131int cst_fgetc(cst_file fh);
132
133/* These aren't LFS-compliant. I don't think we'll need >2G files. */
134long cst_ftell(cst_file fh);
135long cst_fseek(cst_file fh, long pos, int whence);
136long cst_filesize(cst_file fh);
137
138cst_filemap *cst_mmap_file(const char *path);
139int cst_munmap_file(cst_filemap *map);
140
141cst_filemap *cst_read_whole_file(const char *path);
142int cst_free_whole_file(cst_filemap *map);
143
144cst_filemap *cst_read_part_file(const char *path);
145int cst_free_part_file(cst_filemap *map);
146
147int cst_urlp(const char *url);
148cst_file cst_url_open(const char *url);
149
150#endif
151

source code of include/flite/cst_file.h