x-engine-c v0.2.13
The C engine for x-lang
Loading...
Searching...
No Matches
x-sys.c File Reference

Implementation of system-level function wrappers. More...

#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include "x-sys.h"
#include "x-lib.h"

Macros

#define X_SYS_FUNC(F)   F
 

Functions

void x_sys_exit (int status)
 
void * x_sys_malloc (size_t size)
 
void x_sys_free (void *ptr)
 
ssize_t x_sys_read (int fd, void *p_buf, size_t size)
 
ssize_t x_sys_write (int fd, const void *p_buf, size_t size)
 
int x_sys_open (const char *path, int flags)
 
int x_sys_close (int fd)
 
int x_sys_read_char (int fd)
 

Detailed Description

Implementation of system-level function wrappers.

Author
Jon Ruttan (jonru.nosp@m.ttan.nosp@m.@gmai.nosp@m.l.co.nosp@m.m)

Macro Definition Documentation

◆ X_SYS_FUNC

#define X_SYS_FUNC (   F)    F

Function Documentation

◆ x_sys_close()

int x_sys_close ( int  fd)

Close a file descriptor.

Parameters
fdThe file descriptor to close.
Returns
0 on success, -1 on error.

◆ x_sys_exit()

void x_sys_exit ( int  status)

Terminate the process.

Parameters
statusExit status code returned to the parent process.

◆ x_sys_free()

void x_sys_free ( void *  ptr)

Free a previously allocated memory block.

Parameters
ptrPointer to the memory block to free.

◆ x_sys_malloc()

void * x_sys_malloc ( size_t  size)

Allocate a memory block from the heap.

Parameters
sizeThe number of bytes to allocate.
Returns
A pointer to the allocated memory, or NULL on failure.

◆ x_sys_open()

int x_sys_open ( const char *  path,
int  flags 
)

Open a file.

Parameters
pathThe file path to open.
flagsOpen flags (e.g. O_RDONLY).
Returns
A file descriptor on success, or -1 on error.

◆ x_sys_read()

ssize_t x_sys_read ( int  fd,
void *  p_buf,
size_t  size 
)

Read from a file descriptor.

Parameters
fdFile descriptor to read from.
p_bufPointer to the destination buffer.
sizeMaximum number of bytes to read.
Returns
The number of bytes read, or -1 on error.

◆ x_sys_read_char()

int x_sys_read_char ( int  fd)

Read a single character from a file descriptor.

Parameters
fdFile descriptor to read from.
Returns
The character read, or X_SYS_EOF on error or end-of-file.

◆ x_sys_write()

ssize_t x_sys_write ( int  fd,
const void *  p_buf,
size_t  size 
)

Write to a file descriptor.

Parameters
fdFile descriptor to write to.
p_bufPointer to the source buffer.
sizeNumber of bytes to write.
Returns
The number of bytes written, or -1 on error.