Pointwise Plugin SDK
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pwpPlatform.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Pointwise Plugin cross platform functions
4  *
5  * (C) 2021 Cadence Design Systems, Inc. All rights reserved worldwide.
6  *
7  ***************************************************************************/
8 
9 #ifndef _PWPPLATFORM_H_
10 #define _PWPPLATFORM_H_
11 
12 #include <stdio.h>
13 
14 // defines memory management functions malloc/calloc/free
15 #if defined(WINDOWS)
16 # include <malloc.h>
17 #else
18 # include <stdlib.h>
19 #endif /* WINDOWS */
20 
21 
22 extern "C" {
23 
36 /*-----------------------------------------------------*/
43 #if defined(WINDOWS)
44 # define sysEOF EOF
45  typedef fpos_t sysFILEPOS;
46 
47 #else /* *nix or mac */
48 # include <unistd.h>
49 # include <stddef.h>
50 # define sysEOF EOF
51  typedef fpos_t sysFILEPOS;
52 
53 #endif /* WINDOWS */
54 
55 
60 typedef enum sysFILEMODE_e {
61  // base flags.
62  // do not use these directly.
64  pwpRead_ = 0x01,
65  pwpWrite_ = 0x02,
66  pwpAppend_ = 0x04,
67  pwpPlus_ = 0x08,
68 
69  pwpMaskBase_ = 0x0F,
70  pwpMaskFormat_ = 0xF0, // sdkINTERNALS
72 
73  // combine one of these modes:
75  pwpRead = pwpRead_,
77  pwpWrite = pwpWrite_,
79  pwpAppend = pwpAppend_,
81  pwpRWExists = (pwpRead_ | pwpPlus_),
83  pwpRWTruncate = (pwpWrite_ | pwpPlus_),
85  pwpReadAppend = (pwpAppend_ | pwpPlus_),
86 
87  // with one of these formats:
89  pwpBinary = 0x10,
91  pwpFormatted = 0x20,
95  pwpAscii = 0x80
96 }
98 
99 
100 /*---------------------------------------------------------*/
114 FILE *
115 pwpFileOpen (const char *filename, int mode);
116 
117 
118 /*---------------------------------------------------------*/
128 int
129 pwpFileClose (FILE *fp);
130 
131 
132 /*---------------------------------------------------------*/
140 int
141 pwpFileEof (FILE *fp);
142 
143 
144 /*---------------------------------------------------------*/
152 int
153 pwpFileFlush (FILE *fp);
154 
155 
156 /*---------------------------------------------------------*/
169 int
170 pwpFileGetpos (FILE *fp, sysFILEPOS *pos);
171 
172 
173 /*---------------------------------------------------------*/
186 int
187 pwpFileSetpos (FILE *fp, const sysFILEPOS *pos);
188 
189 
190 /*---------------------------------------------------------*/
201 int
202 pwpFileGetSize(FILE *fp, size_t *size);
203 
204 
205 /*---------------------------------------------------------*/
216 int
217 pwpFilenameGetSize(const char *filename, size_t *size);
218 
219 
220 /*---------------------------------------------------------*/
237 size_t
238 pwpFileRead (void *buf, size_t size, size_t count, FILE *fp);
239 
240 
241 /*---------------------------------------------------------*/
258 size_t
259 pwpFileWrite (const void *buf, size_t size, size_t count, FILE *fp);
260 
261 
262 /*---------------------------------------------------------*/
273 size_t
274 pwpFileWriteStr (const char *str, FILE *fp);
275 
276 
277 /*---------------------------------------------------------*/
285 void
286 pwpFileRewind (FILE *fp);
287 
288 
289 /*---------------------------------------------------------*/
295 int
296 pwpFileDelete (const char *filename);
297 
298 
299 /*---------------------------------------------------------*/
312 int
313 pwpSetCurDir(const char *dir);
314 
315 
316 /*---------------------------------------------------------*/
329 int
330 pwpCwdPush (const char *dir);
331 
332 
333 /*---------------------------------------------------------*/
342 int
343 pwpCwdPop (void);
344 
345 
346 } /* extern "C" */
347 
348 #endif /* _PWPPLATFORM_H_ */
int pwpFileEof(FILE *fp)
Queries end-of-file status.
sysFILEMODE
Bit flags used for pwpFileOpen(mode)
Definition: pwpPlatform.h:60
int pwpFileClose(FILE *fp)
Closes a file opened with pwpFileOpen().
size_t pwpFileWriteStr(const char *str, FILE *fp)
Write a null-terminated string to a file.
int pwpFileSetpos(FILE *fp, const sysFILEPOS *pos)
Set the current file position.
FILE * pwpFileOpen(const char *filename, int mode)
Opens a file for I/O.
size_t pwpFileRead(void *buf, size_t size, size_t count, FILE *fp)
Read an collection of data items from a file.
fpos_t sysFILEPOS
File position data type.
Definition: pwpPlatform.h:51
int pwpFileFlush(FILE *fp)
Flush a file to disk.
int pwpCwdPop(void)
Restore the current directory.
int pwpFileGetpos(FILE *fp, sysFILEPOS *pos)
Query the current file position.
size_t pwpFileWrite(const void *buf, size_t size, size_t count, FILE *fp)
Write an collection of data items to a file.
void pwpFileRewind(FILE *fp)
Reset position to the beginning of the file.
int pwpSetCurDir(const char *dir)
Change the current directory.
int pwpFileDelete(const char *filename)
Delete a file.
int pwpFilenameGetSize(const char *filename, size_t *size)
Get the file&#39;s size in bytes.
int pwpCwdPush(const char *dir)
Change the current directory using a stack.
int pwpFileGetSize(FILE *fp, size_t *size)
Get the file&#39;s size in bytes.