MeatAxe: Operating System Interface

MeatAxe 2.4

- Main Page
- Related Pages
- Modules
- Data Structures

Defines | Functions
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()`.

## Defines
#define | FM_READ 0x01
| File mode: read.
#define | FM_CREATE 0x02
| File mode: write.
#define | FM_APPEND 0x03
| File mode: append.
## Functions
void | SysInit ()
| OS-specific initialization.
long | SysTimeUsed (void)
| CPU time.
void | SysSetTimeLimit (long nsecs)
| Set CPU time limit.
FILE * | SysFopen (const char *name, int mode)
| Open a file.
int | SysFseek (FILE *file, long pos)
| Set file pointer.
int | SysRemoveFile (const char *name)
| Remove a file This function deletes a file.
int | SysRemoveDirectory (const char *name)
| Remove a directory.
int | SysCreateDirectory (const char *name)
| Create a directory.
int | SysFseekRelative (FILE *file, long distance)
| Set file pointer relative to current position.
void * | SysMalloc (size_t nbytes)
| Allocate memory.
void * | SysRealloc (void *buf, size_t nbytes)
| Resize memory block.
void | SysFree (void *x)
| Free memory block.
int | SysGetPid ()
| Get process id.

## 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:
  SysRemoveDirectory()

Parameters:

  name | Name of the directory.

Returns:
  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:

FM_LIB
  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`.

FM_TEXT
  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.

FM_NOERROR
  Do not generate an error if the file does not exist.

See also:
  FfReadHeader() FfWriteHeader()

Returns:
  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.

Parameters:

  x | Pointer 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()

Parameters:

  file | File handle.
  pos | New position of file pointer.

Returns:
  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.

Parameters:

  file | The file handle.
  distance | The number of bytes by which the file pointer shall be moved.

Returns:
  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).

Returns:
  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.

Parameters:

  nbytes | Size of memory block to allocate.

Returns:
  Pointer to memory block or NULL on error.

void* SysRealloc | ( | void * | buf,
|  | size_t | nbytes
| ) |  |

Resize 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.

Parameters:

  buf | Pointer to memory block.
  nbytes | Desired new size.

Returns:
  Pointer to resized memory block or NULL on error.

int SysRemoveDirectory | ( | const char * | name | ) |

Remove a directory.

This function removes the specified directory.

See also:
  SysCreateDirectory().

Parameters:

  name | Name of the directory.

Returns:
  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.

Parameters:

  nsecs | CPU time limit in seconds.

Attention:
  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:
  SysSetTimeLimit()

Returns:
  CPU time used.