FARGOS/VISTA Object Management Environment Core  ..
FARGOS/VISTA Object Management Environment Core Table of Contents
Memory-Mapped File Functions

Utility functions to create and open memory-mapped files. More...

Macros

#define FILENAME_WITH_DATE   1
 
#define FILENAME_WITH_PID   2
 
#define FILENAME_WITH_DATE_AND_PID   3
 
#define FILENAME_WITH_TIME   4
 
#define FILENAME_WITH_DATE_AND_TIME   5
 
#define FILENAME_WITH_HOST   8
 
#define FILENAME_ADD_DIR_PREFIX   16
 
#define FILENAME_WITH_EVERYTHING   ~0
 
#define MAP_FILE_READONLY   0
 
#define MAP_FILE_READWRITE   1
 
#define MAP_FILE_RESET   2
 
#define MAP_FILE_INIT   3
 

Functions

uint_fast32_t makeQualifiedFileName (char *fileName, uint_fast32_t fileNameLen, const char *componentName, const char *suffix, const char *dirName, uint_fast32_t flags)
 Create a filename and optionally qualify with the current date and process Id. More...
 
size_t zeroFileContents (int descriptor, size_t fileLength)
 Write out zero-filled blocks to a file. More...
 
int createMappedFile (unsigned char **segment, const char *fileName, size_t *segmentLenPtr, uint_fast32_t doInit)
 Create or open a mapped file with the specified file name. More...
 
int expand_symlinks (char *resultPath, const uint_fast32_t bfrLen, const char *priorPath, uint_fast32_t priorLen, bool mustExist)
 Expand a path with symbolic links into its true name. More...
 
int findFileInPath (char *resultFile, uint_fast32_t resultBfrLen, const char *desiredFile, const char *searchPath, const char *suffix="")
 Search for file under colon-separated path. More...
 

Detailed Description

Utility functions to create and open memory-mapped files.

Macro Definition Documentation

◆ FILENAME_ADD_DIR_PREFIX

#define FILENAME_ADD_DIR_PREFIX   16

Unqualified filename should be prepended with default directory

◆ FILENAME_WITH_DATE

#define FILENAME_WITH_DATE   1

Filename should be date-qualified

◆ FILENAME_WITH_DATE_AND_PID

#define FILENAME_WITH_DATE_AND_PID   3

Filename should be date- and pid-qualified

◆ FILENAME_WITH_DATE_AND_TIME

#define FILENAME_WITH_DATE_AND_TIME   5

Filename should be date- and time-qualified

◆ FILENAME_WITH_EVERYTHING

#define FILENAME_WITH_EVERYTHING   ~0

Filename should be date-, time- and pid-qualified

◆ FILENAME_WITH_HOST

#define FILENAME_WITH_HOST   8

Filename should be hostname-qualified

◆ FILENAME_WITH_PID

#define FILENAME_WITH_PID   2

Filename should be pid-qualified

◆ FILENAME_WITH_TIME

#define FILENAME_WITH_TIME   4

Filename should be time-qualified

◆ MAP_FILE_INIT

#define MAP_FILE_INIT   3

Initialize mapped file

◆ MAP_FILE_READONLY

#define MAP_FILE_READONLY   0

Mapped file is read-only

◆ MAP_FILE_READWRITE

#define MAP_FILE_READWRITE   1

Mapped file is read/write

◆ MAP_FILE_RESET

#define MAP_FILE_RESET   2

Reset mapped file

Function Documentation

◆ createMappedFile()

int createMappedFile ( unsigned char **  segment,
const char *  fileName,
size_t *  segmentLenPtr,
uint_fast32_t  doInit 
)

Create or open a mapped file with the specified file name.

Parameters
segmentis pointer to variable into which will be stored the base of the mapped segment. A value of 0 (which would represent a null pointer) will be returned on any error and is a portable way to detect the condition.
fileNamespecifies the name of the file to be opened/created. The file must exist unless the MAP_FILE_RESET bit is set in the doInit argument.
segmentLenPtroptionally points to a variable into which the segment length will be stored. If a null pointer or the existing value in the pointed-to variable is zero, the current length of the file will be used to determine the size of the segment. A value must be provided if a new file is being created.
doInitindicates how the segment should be prepared. MAP_FILE_INIT is used to create new segments or reinitialize an existing one. MAP_FILE_READONLY is used to obtain read-only access to an existing segment. MAP_FILE_READWRITE is used to obtain writeable-access to an existing segment while preserving its existing content.
Returns
Descriptor of opened file. If segmentLenPtr was not null, the actual size of the segment will be saved in the indicated location.
Return values
-1(POSIX) file could not be opened
INVALID_HANDLE_VALUE(Windows) file could not be opened

References errno, flags, INVALID_HANDLE_VALUE, MAP_FILE_READWRITE, MAP_FILE_RESET, NULL, and zeroFileContents().

Referenced by createMappedVars(), SharedMemoryVariableManager::createSegment(), and MetaDataLoaderForFormat< RECORD_CLASS >::loadMetaDataHeader().

◆ expand_symlinks()

int expand_symlinks ( char *  resultPath,
const uint_fast32_t  bfrLen,
const char *  priorPath,
uint_fast32_t  priorLen,
bool  mustExist 
)

Expand a path with symbolic links into its true name.

Parameters
resultPathpoints to the output buffer into which the result will be stored. Unlink realpath(), the result is not forced to be an absolute path name.
bfrLenindicates the size of the provided output buffer.
priorPathpoints to the path to be expanded; it does not have to be null-terminated.
priorLenindicates the length of the path to be expanded.
mustExistis a Boolean that indicates if all path components must reference directory entries that exist.
Returns
the length of the expanded string placed into resultPath is returned.
Return values
-1is returned if mustExist is true and a path element does not exist. The last path component present in resultPath does not exist.

References MAX_PATH_ELEMENTS.

◆ findFileInPath()

int findFileInPath ( char *  resultFile,
uint_fast32_t  resultBfrLen,
const char *  desiredFile,
const char *  searchPath,
const char *  suffix = "" 
)

Search for file under colon-separated path.

Parameters
resultFilepoints to a buffer into which the name of the located file will be stored
resultBfrLenspecifies the size of the provided buffer
desiredFilespecifies the base element to be searched
searchPathspecifies the colon-separated path elements to be searched
suffixspecifies an optional suffix to be added to the end of the desiredFile element.
Returns
-1 is returned if the file cannot be found; otherwise the length of the generated path name that first matched the desired file is returned. The complete file name will be found in the resultFile buffer.

References F_OK.

◆ makeQualifiedFileName()

uint_fast32_t makeQualifiedFileName ( char *  fileName,
uint_fast32_t  fileNameLen,
const char *  componentName,
const char *  suffix,
const char *  dirName,
uint_fast32_t  flags 
)

Create a filename and optionally qualify with the current date and process Id.

Parameters
fileNamepoints to a buffer into which the constructed file name will be stored.
fileNameLenspecifies the length of the fileName buffer.
componentNamespecifies the name of the component creating the file.
suffixspecifies a suffix for the constructed file name, often something like ".log" or ".txt".
dirNamespecifies the directory in which the file should reside.
flagsis a bit mask that specifies a combination of attributes that should be included in the filename. FILENAME_WITH_EVERYTHING includes all components whereas FILENAME_WITH_DATE would only include the current date.
Returns
Length of constructed file name that was stored in fileName.

References TimeAsDayAndYear::day, FILENAME_ADD_DIR_PREFIX, FILENAME_WITH_DATE, FILENAME_WITH_HOST, FILENAME_WITH_PID, FILENAME_WITH_TIME, flags, getTodaysDate(), TimeAsHourMinSec::hour, TimeAsHourMinSec::min, TimeAsDayAndYear::month, OME_EXPECT_TRUE, TimeAsHourMinSec::sec, and TimeAsDayAndYear::year.

Referenced by SharedMemoryVariableManager::createAndAttachStandardSegment().

◆ zeroFileContents()

size_t zeroFileContents ( int  descriptor,
size_t  fileLength 
)

Write out zero-filled blocks to a file.

Parameters
descriptorreferences a file already opened for write.
fileLengthspecifies the number of bytes to be written.

References NULL.

Referenced by createMappedFile().

Generated: Fri Jul 31 2020 18:19:16
Support Information