Pointwise Plugin SDK
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_ */
pwpBinary
@ pwpBinary
Definition: pwpPlatform.h:89
sysFILEPOS
fpos_t sysFILEPOS
File position data type.
Definition: pwpPlatform.h:51
pwpFileOpen
FILE * pwpFileOpen(const char *filename, int mode)
Opens a file for I/O.
Definition: pwpPlatform.cxx:230
pwpFileSetpos
int pwpFileSetpos(FILE *fp, const sysFILEPOS *pos)
Set the current file position.
Definition: pwpPlatform.cxx:321
pwpRWExists
@ pwpRWExists
Definition: pwpPlatform.h:81
pwpFileGetSize
int pwpFileGetSize(FILE *fp, size_t *size)
Get the file's size in bytes.
Definition: pwpPlatform.cxx:332
pwpFileFlush
int pwpFileFlush(FILE *fp)
Flush a file to disk.
Definition: pwpPlatform.cxx:303
pwpFileWriteStr
size_t pwpFileWriteStr(const char *str, FILE *fp)
Write a null-terminated string to a file.
Definition: pwpPlatform.cxx:413
pwpUnformatted
@ pwpUnformatted
Definition: pwpPlatform.h:93
pwpFileRead
size_t pwpFileRead(void *buf, size_t size, size_t count, FILE *fp)
Read an collection of data items from a file.
Definition: pwpPlatform.cxx:391
pwpFileEof
int pwpFileEof(FILE *fp)
Queries end-of-file status.
Definition: pwpPlatform.cxx:296
pwpFileWrite
size_t pwpFileWrite(const void *buf, size_t size, size_t count, FILE *fp)
Write an collection of data items to a file.
Definition: pwpPlatform.cxx:402
pwpAscii
@ pwpAscii
Definition: pwpPlatform.h:95
pwpAppend
@ pwpAppend
Definition: pwpPlatform.h:79
pwpCwdPop
int pwpCwdPop(void)
Restore the current directory.
Definition: pwpPlatform.cxx:486
pwpFileDelete
int pwpFileDelete(const char *filename)
Delete a file.
Definition: pwpPlatform.cxx:429
sysFILEMODE
sysFILEMODE
Bit flags used for pwpFileOpen(mode)
Definition: pwpPlatform.h:60
pwpFileRewind
void pwpFileRewind(FILE *fp)
Reset position to the beginning of the file.
Definition: pwpPlatform.cxx:420
pwpRWTruncate
@ pwpRWTruncate
Definition: pwpPlatform.h:83
pwpFileGetpos
int pwpFileGetpos(FILE *fp, sysFILEPOS *pos)
Query the current file position.
Definition: pwpPlatform.cxx:310
pwpWrite
@ pwpWrite
Definition: pwpPlatform.h:77
pwpFilenameGetSize
int pwpFilenameGetSize(const char *filename, size_t *size)
Get the file's size in bytes.
Definition: pwpPlatform.cxx:353
pwpFormatted
@ pwpFormatted
Definition: pwpPlatform.h:91
pwpFileClose
int pwpFileClose(FILE *fp)
Closes a file opened with pwpFileOpen().
Definition: pwpPlatform.cxx:285
pwpSetCurDir
int pwpSetCurDir(const char *dir)
Change the current directory.
Definition: pwpPlatform.cxx:450
pwpCwdPush
int pwpCwdPush(const char *dir)
Change the current directory using a stack.
Definition: pwpPlatform.cxx:461
pwpRead
@ pwpRead
Definition: pwpPlatform.h:75
pwpReadAppend
@ pwpReadAppend
Definition: pwpPlatform.h:85