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"
Implementation of system-level function wrappers.
- Author
- Jon Ruttan (jonru.nosp@m.ttan.nosp@m.@gmai.nosp@m.l.co.nosp@m.m)
- Copyright
- 2021 Jon Ruttan @license MIT No Attribution (MIT-0)
., .,
{O,O}
( )
" "
◆ X_SYS_FUNC
| #define X_SYS_FUNC |
( |
|
F | ) |
F |
◆ x_sys_close()
| int x_sys_close |
( |
int |
fd | ) |
|
Close a file descriptor.
- Parameters
-
| fd | The file descriptor to close. |
- Returns
- 0 on success, -1 on error.
◆ x_sys_exit()
| void x_sys_exit |
( |
int |
status | ) |
|
Terminate the process.
- Parameters
-
| status | Exit status code returned to the parent process. |
◆ x_sys_free()
| void x_sys_free |
( |
void * |
ptr | ) |
|
Free a previously allocated memory block.
- Parameters
-
| ptr | Pointer to the memory block to free. |
◆ x_sys_malloc()
| void * x_sys_malloc |
( |
size_t |
size | ) |
|
Allocate a memory block from the heap.
- Parameters
-
| size | The 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
-
| path | The file path to open. |
| flags | Open 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
-
| fd | File descriptor to read from. |
| p_buf | Pointer to the destination buffer. |
| size | Maximum 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
-
| fd | File 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
-
| fd | File descriptor to write to. |
| p_buf | Pointer to the source buffer. |
| size | Number of bytes to write. |
- Returns
- The number of bytes written, or -1 on error.