Pointwise Plugin SDK
|
#include <cstdlib>
#include <memory>
#include <string.h>
#include <sys/stat.h>
#include <vector>
#include <stdlib.h>
#include "apiUtils.h"
#include "pwpPlatform.h"
Go to the source code of this file.
Macros | |
#define | chrAPPEND(p, c) ((nullptr != p) ? (*p++ = c) : 0) |
#define | FILENAME_MAX 512 |
#define | isMODE(allBits, modeBits) (((allBits) & (modeBits)) == modeBits) |
#define | strOK(ss) ((nullptr != ss) && ('\0' != ss[0])) |
#define | sysBinaryMode 'b' |
#define | sysFileno(fp) fileno(fp) |
#define | sysFstat fstat |
#define | sysGetCwd() ::getcwd(0, FILENAME_MAX) |
#define | sysTextMode '\0' |
Typedefs | |
using | DirUniquePtr = std::unique_ptr< char, decltype(free) * > |
using | SysStatBuf = struct stat |
Functions | |
int | pwpCwdPop (void) |
Restore the current directory. More... | |
int | pwpCwdPush (const char *dir) |
Change the current directory using a stack. More... | |
int | pwpFileClose (FILE *fp) |
Closes a file opened with pwpFileOpen(). More... | |
int | pwpFileDelete (const char *filename) |
Delete a file. More... | |
int | pwpFileEof (FILE *fp) |
Queries end-of-file status. More... | |
int | pwpFileFlush (FILE *fp) |
Flush a file to disk. More... | |
int | pwpFileGetpos (FILE *fp, sysFILEPOS *pos) |
Query the current file position. More... | |
int | pwpFileGetSize (FILE *fp, size_t *size) |
Get the file's size in bytes. More... | |
int | pwpFilenameGetSize (const char *filename, size_t *size) |
Get the file's size in bytes. More... | |
FILE * | pwpFileOpen (const char *filename, int mode) |
Opens a file for I/O. More... | |
size_t | pwpFileRead (void *buf, size_t size, size_t count, FILE *fp) |
Read an collection of data items from a file. More... | |
void | pwpFileRewind (FILE *fp) |
Reset position to the beginning of the file. More... | |
int | pwpFileSetpos (FILE *fp, const sysFILEPOS *pos) |
Set the current file position. More... | |
size_t | pwpFileWrite (const void *buf, size_t size, size_t count, FILE *fp) |
Write an collection of data items to a file. More... | |
size_t | pwpFileWriteStr (const char *str, FILE *fp) |
Write a null-terminated string to a file. More... | |
int | pwpSetCurDir (const char *dir) |
Change the current directory. More... | |
#define chrAPPEND | ( | p, | |
c | |||
) | ((nullptr != p) ? (*p++ = c) : 0) |
Definition at line 55 of file pwpPlatform.cxx.
#define FILENAME_MAX 512 |
Definition at line 60 of file pwpPlatform.cxx.
#define isMODE | ( | allBits, | |
modeBits | |||
) | (((allBits) & (modeBits)) == modeBits) |
Definition at line 57 of file pwpPlatform.cxx.
#define strOK | ( | ss | ) | ((nullptr != ss) && ('\0' != ss[0])) |
Definition at line 54 of file pwpPlatform.cxx.
#define sysBinaryMode 'b' |
Definition at line 43 of file pwpPlatform.cxx.
#define sysFileno | ( | fp | ) | fileno(fp) |
Definition at line 44 of file pwpPlatform.cxx.
#define sysFstat fstat |
Definition at line 45 of file pwpPlatform.cxx.
#define sysGetCwd | ( | ) | ::getcwd(0, FILENAME_MAX) |
Definition at line 46 of file pwpPlatform.cxx.
#define sysTextMode '\0' |
Definition at line 42 of file pwpPlatform.cxx.
using DirUniquePtr = std::unique_ptr<char, decltype(free)*> |
Definition at line 49 of file pwpPlatform.cxx.
using SysStatBuf = struct stat |
Definition at line 48 of file pwpPlatform.cxx.
int pwpCwdPop | ( | void | ) |
Restore the current directory.
This call is only valid after calling pwpCwdPush().
Definition at line 486 of file pwpPlatform.cxx.
References pwpCwdPush().
Referenced by caeuFileClose(), caeuFileOpen(), PwpCwd::popDir(), and PwCaeGridWrite().
int pwpCwdPush | ( | const char * | dir | ) |
Change the current directory using a stack.
Before changing the cwd, the current directory is pushed onto a stack and can be restored by calling pwpCwdPop().
dir | The directory to change to. |
Definition at line 461 of file pwpPlatform.cxx.
References pwpSetCurDir(), strOK, and sysGetCwd.
Referenced by caeuFileOpen(), fileDestCwdPush(), PwpCwd::pushDir(), and pwpCwdPop().
int pwpFileClose | ( | FILE * | fp | ) |
Closes a file opened with pwpFileOpen().
fp | A file pointer obtained from pwpFileOpen(). |
Definition at line 285 of file pwpPlatform.cxx.
References sysEOF.
Referenced by caeuFileClose(), and PwpFile::close().
int pwpFileDelete | ( | const char * | filename | ) |
Delete a file.
filename | The name of an existing file to delete. |
Definition at line 429 of file pwpPlatform.cxx.
References strOK.
Referenced by caeuFileClose(), and PwpFile::unlink().
int pwpFileEof | ( | FILE * | fp | ) |
Queries end-of-file status.
fp | A file pointer obtained from pwpFileOpen(). |
Definition at line 296 of file pwpPlatform.cxx.
Referenced by PwpFile::isEof().
int pwpFileFlush | ( | FILE * | fp | ) |
Flush a file to disk.
fp | A file pointer obtained from pwpFileOpen(). |
Definition at line 303 of file pwpPlatform.cxx.
Referenced by PwpFile::flush().
int pwpFileGetpos | ( | FILE * | fp, |
sysFILEPOS * | pos | ||
) |
Query the current file position.
fp | A file pointer obtained from pwpFileOpen(). |
pos | Pointer to a sysFILEPOS object. |
Definition at line 310 of file pwpPlatform.cxx.
Referenced by PwpFile::getPos(), PwuUnfRecBegin(), and PwuUnfRecEnd().
int pwpFileGetSize | ( | FILE * | fp, |
size_t * | size | ||
) |
Get the file's size in bytes.
fp | A valid file pointer obtained from pwpFileOpen(). |
size | Pointer to the size variable. |
Definition at line 332 of file pwpPlatform.cxx.
References ASSERT_COMPILE(), sysFileno, and sysFstat.
Referenced by PwpFile::getSize().
int pwpFilenameGetSize | ( | const char * | filename, |
size_t * | size | ||
) |
Get the file's size in bytes.
filename | The name of an existing file. |
size | Pointer to the size variable. |
Definition at line 353 of file pwpPlatform.cxx.
Referenced by PwpFile::getSize().
FILE* pwpFileOpen | ( | const char * | filename, |
int | mode | ||
) |
Opens a file for I/O.
filename | The name of file to open. |
mode | Controls how the file is opened. This value is built from the bitwise OR of 2 sysFILEMODE flags. |
Definition at line 230 of file pwpPlatform.cxx.
References chrAPPEND, isMODE, pwpAppend, pwpAscii, pwpBinary, pwpFormatted, pwpRead, pwpUnformatted, pwpWrite, strOK, sysBinaryMode, and sysTextMode.
Referenced by PwpFile::open(), and openFileName().
size_t pwpFileRead | ( | void * | buf, |
size_t | size, | ||
size_t | count, | ||
FILE * | fp | ||
) |
Read an collection of data items from a file.
buf | Pointer to the read buffer. |
size | The size of each item. |
count | The number of items to read. |
fp | A file pointer obtained from pwpFileOpen(). |
Definition at line 391 of file pwpPlatform.cxx.
Referenced by PwpFile::checkAscii(), and PwpFile::read().
void pwpFileRewind | ( | FILE * | fp | ) |
Reset position to the beginning of the file.
fp | A file pointer obtained from pwpFileOpen(). |
Definition at line 420 of file pwpPlatform.cxx.
Referenced by PwpFile::rewind().
int pwpFileSetpos | ( | FILE * | fp, |
const sysFILEPOS * | pos | ||
) |
Set the current file position.
fp | A file pointer obtained from pwpFileOpen(). |
pos | Pointer to an sysFILEPOS object obtained from a call to pwpFileGetpos(). |
Definition at line 321 of file pwpPlatform.cxx.
Referenced by PwuUnfRecEnd(), PwpFile::setIntPos(), and PwpFile::setPos().
size_t pwpFileWrite | ( | const void * | buf, |
size_t | size, | ||
size_t | count, | ||
FILE * | fp | ||
) |
Write an collection of data items to a file.
buf | Pointer to the buffer to write. |
size | The size of each item. |
count | The number of items to write. |
fp | A file pointer obtained from pwpFileOpen(). |
Definition at line 402 of file pwpPlatform.cxx.
Referenced by pwpFileWriteStr(), PwuUnfRecWriteArr(), unfHdrLenWrite(), PwpBinaryWriter::write(), PwpFile::writeAt(), PwpBinaryWriter::writeOrdered(), and PwpAnchoredFileValueWriter< ValType >::writeUnf().
size_t pwpFileWriteStr | ( | const char * | str, |
FILE * | fp | ||
) |
Write a null-terminated string to a file.
str | The string to write. The null-byte is not written. |
fp | A file pointer obtained from pwpFileOpen(). |
Definition at line 413 of file pwpPlatform.cxx.
References pwpFileWrite().
int pwpSetCurDir | ( | const char * | dir | ) |
Change the current directory.
Changes the cwd without first saving current directory to stack. Typically, a plugin should instead use pwpCwdPush() and pwpCwdPop().
dir | The directory to change to. |
Definition at line 450 of file pwpPlatform.cxx.
References pwpSetCurDir().
Referenced by pwpCwdPush(), and pwpSetCurDir().