Pointwise Plugin SDK
Macros | Typedefs | Functions | Variables
pwpPlatform.cxx File Reference
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
#include "apiUtils.h"
#include "pwpPlatform.h"
+ Include dependency graph for pwpPlatform.cxx:

Go to the source code of this file.

Macros

#define chrAPPEND(p, c)   ((p && c) ? (*p++ = c) : 0)
 
#define FILENAME_MAX   512
 
#define isMODE(allBits, modeBits)   (((allBits) & (modeBits)) == modeBits)
 
#define MAXSTACK   50
 
#define strOK(ss)   ((ss) && (ss[0]))
 
#define sysBinaryMode   'b'
 
#define sysFileno(fp)   fileno(fp)
 
#define sysFstat   fstat
 
#define sysTextMode   '\0'
 

Typedefs

typedef struct stat sysStatBuf
 

Functions

int pwpCwdPop (void)
 Restore the current directory. More...
 
int pwpCwdPush (const char *dir)
 Change the current directory. 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...
 

Variables

static char * dirStack [50+1] = { 0 }
 
static int stackCnt = 0
 

Macro Definition Documentation

◆ chrAPPEND

#define chrAPPEND (   p,
 
)    ((p && c) ? (*p++ = c) : 0)

Definition at line 50 of file pwpPlatform.cxx.

Referenced by pwpFileOpen().

◆ FILENAME_MAX

#define FILENAME_MAX   512

Definition at line 55 of file pwpPlatform.cxx.

Referenced by fileDestCwdPush(), and pwpCwdPush().

◆ isMODE

#define isMODE (   allBits,
  modeBits 
)    (((allBits) & (modeBits)) == modeBits)

Definition at line 52 of file pwpPlatform.cxx.

Referenced by pwpFileOpen().

◆ MAXSTACK

#define MAXSTACK   50

Definition at line 440 of file pwpPlatform.cxx.

Referenced by pwpCwdPush().

◆ strOK

#define strOK (   ss)    ((ss) && (ss[0]))

Definition at line 49 of file pwpPlatform.cxx.

Referenced by pwpFileDelete(), and pwpFileOpen().

◆ sysBinaryMode

#define sysBinaryMode   'b'

Definition at line 40 of file pwpPlatform.cxx.

Referenced by pwpFileOpen().

◆ sysFileno

#define sysFileno (   fp)    fileno(fp)

Definition at line 41 of file pwpPlatform.cxx.

Referenced by pwpFileGetSize().

◆ sysFstat

#define sysFstat   fstat

Definition at line 43 of file pwpPlatform.cxx.

Referenced by pwpFileGetSize().

◆ sysTextMode

#define sysTextMode   '\0'

Definition at line 39 of file pwpPlatform.cxx.

Referenced by pwpFileOpen().

Typedef Documentation

◆ sysStatBuf

typedef struct stat sysStatBuf

Definition at line 44 of file pwpPlatform.cxx.

Function Documentation

◆ pwpCwdPop()

int pwpCwdPop ( void  )

Restore the current directory.

This call is only valid after calling pwpCwdPush().

Returns
0 on success, -1 on error.
See also
pwpCwdPush()

Definition at line 490 of file pwpPlatform.cxx.

References dirStack, and stackCnt.

Referenced by caeuFileClose(), caeuFileOpen(), PwpCwd::popDir(), and PwCaeGridWrite().

◆ pwpCwdPush()

int pwpCwdPush ( const char *  dir)

Change the current directory.

Before changing the cwd, the current directory is pushed onto a stack and can be restored by calling pwpCwdPop().

Parameters
dirThe directory to change to.
Returns
0 on success, -1 on error.
See also
pwpCwdPop()

Definition at line 451 of file pwpPlatform.cxx.

References dirStack, FILENAME_MAX, MAXSTACK, and stackCnt.

Referenced by caeuFileOpen(), fileDestCwdPush(), and PwpCwd::pushDir().

◆ pwpFileClose()

int pwpFileClose ( FILE *  fp)

Closes a file opened with pwpFileOpen().

Parameters
fpA file pointer obtained from pwpFileOpen().
Returns
0 on success, sysEOF on error.
See also
pwpFileOpen()

Definition at line 274 of file pwpPlatform.cxx.

References sysEOF.

Referenced by caeuFileClose(), and PwpFile::close().

◆ pwpFileDelete()

int pwpFileDelete ( const char *  filename)

Delete a file.

Parameters
filenameThe name of an existing file to delete.

Definition at line 419 of file pwpPlatform.cxx.

References strOK.

Referenced by caeuFileClose(), and PwpFile::unlink().

◆ pwpFileEof()

int pwpFileEof ( FILE *  fp)

Queries end-of-file status.

Parameters
fpA file pointer obtained from pwpFileOpen().
Returns
!0 if fp is at end-of-file.

Definition at line 285 of file pwpPlatform.cxx.

Referenced by PwpFile::isEof().

◆ pwpFileFlush()

int pwpFileFlush ( FILE *  fp)

Flush a file to disk.

Parameters
fpA file pointer obtained from pwpFileOpen().
Returns
0 on success, sysEOF on error.

Definition at line 292 of file pwpPlatform.cxx.

Referenced by PwpFile::flush().

◆ pwpFileGetpos()

int pwpFileGetpos ( FILE *  fp,
sysFILEPOS pos 
)

Query the current file position.

Parameters
fpA file pointer obtained from pwpFileOpen().
posPointer to a sysFILEPOS object.
Returns
0 on success, !0 on error.
See also
pwpFileSetpos()

Definition at line 299 of file pwpPlatform.cxx.

Referenced by PwpFile::getPos(), PwuUnfRecBegin(), and PwuUnfRecEnd().

◆ pwpFileGetSize()

int pwpFileGetSize ( FILE *  fp,
size_t *  size 
)

Get the file's size in bytes.

Parameters
fpA valid file pointer obtained from pwpFileOpen().
sizePointer to the size variable.
Returns
0 on success, !0 on error.

Definition at line 321 of file pwpPlatform.cxx.

References ASSERT_COMPILE, sysFileno, and sysFstat.

Referenced by PwpFile::getSize().

◆ pwpFilenameGetSize()

int pwpFilenameGetSize ( const char *  filename,
size_t *  size 
)

Get the file's size in bytes.

Parameters
filenameThe name of an existing file.
sizePointer to the size variable.
Returns
0 on success, !0 on error.

Definition at line 342 of file pwpPlatform.cxx.

Referenced by PwpFile::getSize().

◆ pwpFileOpen()

FILE* pwpFileOpen ( const char *  filename,
int  mode 
)

Opens a file for I/O.

Parameters
filenameThe name of file to open.
modeControls how the file is opened. This value is built from the bitwise OR of 2 sysFILEMODE flags.
Returns
Pointer to the file or 0 if file could not be opened.
See also
sysFILEMODE, pwpFileClose()

Definition at line 217 of file pwpPlatform.cxx.

References chrAPPEND, isMODE, pwpAppend, pwpAscii, pwpBinary, pwpFormatted, pwpRead, pwpUnformatted, pwpWrite, strOK, sysBinaryMode, and sysTextMode.

Referenced by PwpFile::open(), and openFileName().

◆ pwpFileRead()

size_t pwpFileRead ( void *  buf,
size_t  size,
size_t  count,
FILE *  fp 
)

Read an collection of data items from a file.

Parameters
bufPointer to the read buffer.
sizeThe size of each item.
countThe number of items to read.
fpA file pointer obtained from pwpFileOpen().
Returns
The number of full items read. Will be < count on an error.

Definition at line 381 of file pwpPlatform.cxx.

Referenced by PwpFile::read().

◆ pwpFileRewind()

void pwpFileRewind ( FILE *  fp)

Reset position to the beginning of the file.

Parameters
fpA file pointer obtained from pwpFileOpen().
See also
pwpFileSetpos(), pwpFileGetpos()

Definition at line 410 of file pwpPlatform.cxx.

Referenced by PwpFile::rewind().

◆ pwpFileSetpos()

int pwpFileSetpos ( FILE *  fp,
const sysFILEPOS pos 
)

Set the current file position.

Parameters
fpA file pointer obtained from pwpFileOpen().
posPointer to an sysFILEPOS object obtained from a call to pwpFileGetpos().
Returns
0 on success, !0 on error.
See also
pwpFileGetpos()

Definition at line 310 of file pwpPlatform.cxx.

Referenced by PwuUnfRecEnd(), and PwpFile::setPos().

◆ pwpFileWrite()

size_t pwpFileWrite ( const void *  buf,
size_t  size,
size_t  count,
FILE *  fp 
)

Write an collection of data items to a file.

Parameters
bufPointer to the buffer to write.
sizeThe size of each item.
countThe number of items to write.
fpA file pointer obtained from pwpFileOpen().
Returns
The number of full items written. Will be < count on an error.

Definition at line 392 of file pwpPlatform.cxx.

Referenced by pwpFileWriteStr(), PwuUnfRecWriteArr(), unfHdrLenWrite(), PwpBinaryWriter::write(), PwpFile::writeAt(), PwpBinaryWriter::writeOrdered(), and PwpAnchoredFileValueWriter< ValType >::writeUnf().

◆ pwpFileWriteStr()

size_t pwpFileWriteStr ( const char *  str,
FILE *  fp 
)

Write a null-terminated string to a file.

Parameters
strThe string to write. The null-byte is not written.
fpA file pointer obtained from pwpFileOpen().
Returns
1 on success, 0 on error.

Definition at line 403 of file pwpPlatform.cxx.

References pwpFileWrite().

Variable Documentation

◆ dirStack

char* dirStack[50+1] = { 0 }
static

Definition at line 444 of file pwpPlatform.cxx.

Referenced by pwpCwdPop(), and pwpCwdPush().

◆ stackCnt

int stackCnt = 0
static

Definition at line 447 of file pwpPlatform.cxx.

Referenced by pwpCwdPop(), and pwpCwdPush().