MeatAxe  2.4
Programs for working with modular representations
Operating System Interface

Detailed Description

The MeatAxe is written for a UNIX-like operating environment and uses many functions of the standard C library. To make the MeatAxe more portable between different operating systems, some C library and system calls are accessed through wrapper functions. These wrapper functions have names that begin with 'Sys'. For example SysFree() is the wrapper function for free().


#define FM_READ   0x01
 File mode: read.
#define FM_CREATE   0x02
 File mode: write.
#define FM_APPEND   0x03
 File mode: append.


int SysReadLong32 (FILE *f, long *buf, int n)
 Read long integers. More...
int SysWriteLong32 (FILE *f, const long *buf, int n)
 Write long integers. More...
void SysInit ()
 OS-specific initialization. More...
long SysTimeUsed (void)
 CPU time. More...
void SysSetTimeLimit (long nsecs)
 Set CPU time limit. More...
FILE * SysFopen (const char *name, int mode)
 Open a file. More...
int SysFseek (FILE *file, long pos)
 Set file pointer. More...
int SysRemoveFile (const char *name)
 Remove a file This function deletes a file. More...
int SysRemoveDirectory (const char *name)
 Removes a directory (which must be empty). More...
int SysCreateDirectory (const char *name)
 Create a directory. More...
int SysFseekRelative (FILE *file, long distance)
 Set file pointer relative to current position. More...
void * SysMalloc (size_t nbytes)
 Allocate memory. More...
void * SysRealloc (void *buf, size_t nbytes)
 Resizes a memory block. More...
void SysFree (void *x)
 Free memory block. More...
int SysGetPid ()
 Get process id. More...

Function Documentation

int SysCreateDirectory ( const char *  name)

Create a directory.

This function creates a new directory. If the directory cannot be created for some reason, a run-time error is generated and the function returns -1.

See also
nameName of the directory.
0 on success, -1 on error.
FILE* SysFopen ( const char *  name,
int  mode 

Open a file.

This function opens a file, like fopen(). The second argument, must be one of the predfined constants FM_READ (open for reading), FM_CREAT (create a new file and open for writing, or FM_APPEND (append to existing file or create a new file). Additional flags may be or'ed to the mode:

If the file does not exist in the current directory, look in the library directory. The library directory is defined either by the environment variable MTXLIB, or at compile-time by the macro MTXLIB.
Open in text mode. This flag must be used on some systems (e.g., MS-DOS) to open text files. By default, files are assumed to contain binary data.
Do not generate an error if the file does not exist.
See also
FfReadHeader() FfWriteHeader()
A pointer to the open file or NULL on error.
void SysFree ( void *  x)

Free memory block.

This function works like free() but checks if the argument is not NULL. Otherwise, an appropriate error message is generated.

xPointer to the memory block.
int SysFseek ( FILE *  file,
long  pos 

Set file pointer.

This function sets the file pointer to a given position. If pos is greater than or equal to zero, it is interpreted as an absolute position (relative to start of file). If pos is negative, the file pointer is moved to the end of file.

See also
SysFseekRelative(), FfSeekRow()
fileFile handle.
posNew position of file pointer.
0 on success, nonzero otherwise.
int SysFseekRelative ( FILE *  file,
long  distance 

Set file pointer relative to current position.

This function moves the file pointer by a given number of bytes, which may be positive or negative.

fileThe file handle.
distanceThe number of bytes by which the file pointer shall be moved.
0 on success, nonzero on error.
See also
SysFseek(), FfSeekRow()
int SysGetPid ( )

Get process id.

This function returns a number which uniquely identifies the calling process on the local system. The exact meaning of this number depends on the operating system. In an UNIX environment, it is the process id (PID).

Process id.
void SysInit ( void  )

OS-specific initialization.

This function is called during library initialization. It performs any OS-specific actions. Applications should never call this function directly. Use MtxInit() instead.

void* SysMalloc ( size_t  nbytes)

Allocate memory.

This function works like malloc(), but the return value is never 0, even when the function was called with a 0 argument.

nbytesSize of memory block to allocate.
Pointer to memory block or NULL on error.
int SysReadLong32 ( FILE *  f,
long *  buf,
int  n 

Read long integers.

This function reads @ n long integers from the file f into the array buf. buf must point to a memory area of at least n*sizeof(long) bytes and the file must be open for reading. The return value indicates how many integers have actually been read. This number may be less than n because the end of file was encountered while reading. A negative return value indicates a file i/o error.

SysReadLong32() expects that the numbers in the file are 4-byte integers in little-endian format, i.e. the least significant byte first. Using a machine-independent data format makes MeatAxe data files more portable, but there are also some disadvantages:

  • The conversion to and from machine-independent format involves several arithmetic operations for each number read/written.
  • The highest number which can be read/written is 232-1.
    fFile to read from.
    bufPointer to buffer.
    nNumber of integers to read.
    Number of integers that were actually read, or $/1$ on error.
void* SysRealloc ( void *  buf,
size_t  nbytes 

Resizes a memory block.

This function works like realloc() but handles zero-length blocks differently (namely, by allocating 1 byte instead) to avoid problems with broken realloc() implementations.

bufPointer to the memory block.
nbytesDesired new size.
Pointer to resized memory block or NULL on error.
int SysRemoveDirectory ( const char *  name)

Removes a directory (which must be empty).

See also
nameName of the directory to be removed.
0 on success, -1 on error.
int SysRemoveFile ( const char *  name)

Remove a file This function deletes a file.

On a UNIX system, SysRemoveFile() just calls remove(). If the file to be deleted does not exist or cannot be removed for some other reason, run-time error error is generated.

void SysSetTimeLimit ( long  nsecs)

Set CPU time limit.

This function sets a CPU time limit for the calling process. When the limit is exceeded the process is killed.

nsecsCPU time limit in seconds.
This function is not available on all platforms.
long SysTimeUsed ( void  )

CPU time.

This function returns the CPU time used by the calling process in units of 1/10 seconds.

See also
CPU time used.
int SysWriteLong32 ( FILE *  f,
const long *  buf,
int  n 

Write long integers.

This function writes n long integers from the the array buf to the file f. buf must point to a memory area of at least n*sizeof(long) bytes and f must be open for writing. The numbers are written in a machine-independent format which can be read by SysReadLong().

fFile to write to.
bufPointer to buffer.
nNumber of integers to write.
Number of integers that were written, or $-1$ on error.

MeatAxe 2.4 documentation, generated on Wed Jan 7 2015 08:38:36