PatchworkOS
Loading...
Searching...
No Matches

System IO header. More...

Data Structures

struct  pollfd_t
 Poll file descriptor structure. More...
 
struct  stat_t
 Stat type. More...
 
struct  dirent_t
 Directory entry struct. More...
 
struct  key_t
 Key type. More...
 

Macros

#define STDIN_FILENO   0
 
#define STDOUT_FILENO   1
 
#define STDERR_FILENO   2
 
#define PIPE_READ   0
 Pipe read end.
 
#define PIPE_WRITE   1
 Pipe write end.
 
#define POLL_SPECIAL   (POLLERR | POLLHUP | POLLNVAL)
 Poll event values that will always be checked and included even if not specified.
 
#define KEY_SIZE   16
 Size of keys in bytes.
 

Typedefs

typedef uint8_t seek_origin_t
 Type for the seek() origin argument.
 
typedef uint64_t inode_number_t
 Inode number enum.
 

Enumerations

enum  poll_events_t {
  POLLNONE = 0 ,
  POLLIN = (1 << 0) ,
  POLLOUT = (1 << 1) ,
  POLLERR = (1 << 2) ,
  POLLHUP = (1 << 3) ,
  POLLNVAL = (1 << 4)
}
 Poll events type. More...
 
enum  inode_type_t {
  INODE_FILE ,
  INODE_DIR
}
 Inode type enum. More...
 

Functions

fd_t open (const char *path)
 System call for opening files.
 
fd_t openf (const char *_RESTRICT format,...)
 Wrapper for opening files with a formatted path.
 
fd_t vopenf (const char *_RESTRICT format, va_list args)
 Wrapper for opening files with a formatted path, using a va_list.
 
uint64_t open2 (const char *path, fd_t fd[2])
 System call for opening 2 file descriptors from one file.
 
uint64_t close (fd_t fd)
 System call for closing files.
 
uint64_t read (fd_t fd, void *buffer, uint64_t count)
 System call for reading from files.
 
uint64_t readf (fd_t fd, const char *_RESTRICT format,...)
 Wrapper for reading a formatted string from a file.
 
uint64_t vreadf (fd_t fd, const char *_RESTRICT format, va_list args)
 Wrapper for reading a formatted string from a file with a va_list.
 
uint64_t write (fd_t fd, const void *buffer, uint64_t count)
 System call for writing to files.
 
uint64_t writef (fd_t fd, const char *_RESTRICT format,...)
 Wrapper for writing a formatted string to a file.
 
uint64_t vwritef (fd_t fd, const char *_RESTRICT format, va_list args)
 Wrapper for writing a formatted string to a file with a va_list.
 
uint64_t readfile (const char *path, void *buffer, uint64_t count, uint64_t offset)
 Wrapper for reading a file directly using a path.
 
uint64_t readfilef (const char *path, const char *_RESTRICT format,...)
 Wrapper for reading a formatted string from a file directly using a path.
 
uint64_t vreadfilef (const char *path, const char *_RESTRICT format, va_list args)
 Wrapper for reading a formatted string from a file directly using a path with a va_list.
 
uint64_t writefile (const char *path, const void *buffer, uint64_t count, uint64_t offset)
 Wrapper for writing a file directly using a path.
 
uint64_t writefilef (const char *path, const char *_RESTRICT format,...)
 Wrapper for writing a formatted string to a file directly using a path.
 
uint64_t vwritefilef (const char *path, const char *_RESTRICT format, va_list args)
 Wrapper for writing a formatted string to a file directly using a path with a va_list.
 
uint64_t seek (fd_t fd, int64_t offset, seek_origin_t origin)
 System call for changing the file offset.
 
uint64_t chdir (const char *path)
 System call for changing the cwd.
 
uint64_t poll (pollfd_t *fds, uint64_t amount, clock_t timeout)
 System call for polling files.
 
poll_events_t poll1 (fd_t fd, poll_events_t events, clock_t timeout)
 Wrapper for polling one file.
 
uint64_t stat (const char *path, stat_t *stat)
 System call for retrieving info about a file or directory.
 
uint64_t ioctl (fd_t fd, uint64_t request, void *argp, uint64_t size)
 System call for extended driver behaviour.
 
fd_t dup (fd_t oldFd)
 System call for duplicating file descriptors.
 
fd_t dup2 (fd_t oldFd, fd_t newFd)
 System call for duplicating file descriptors, with a destination.
 
uint64_t getdents (fd_t fd, dirent_t *buffer, uint64_t count)
 System call for reading directory entires.
 
uint64_t mkdir (const char *path)
 Wrapper for creating a directory.
 
uint64_t rmdir (const char *path)
 Wrapper for removing a directory.
 
uint64_t link (const char *oldPath, const char *newPath)
 System call for creating a hardlink.
 
uint64_t unlink (const char *path)
 Wrapper for removing a file.
 
uint64_t removef (const char *format,...)
 Wrapper for removing a file with a formatted path.
 
uint64_t vremovef (const char *format, va_list args)
 Wrapper for removing a file with a formatted path, using a va_list.
 
uint64_t share (key_t *key, fd_t fd, clock_t timeout)
 System call for sharing a file descriptor with another process.
 
fd_t claim (key_t *key)
 System call for claiming a shared file descriptor.
 
uint64_t bind (fd_t source, const char *mountpoint)
 System call for binding a file descriptor to a mountpoint.
 

Detailed Description

System IO header.

The sys/io.h header handles interaction with PatchworkOS's file system, following the philosophy that everything is a file. This means interacting with physical devices, inter-process communication (like shared memory), and much more is handled via files.

Flags

Functions like open() do not have a specific argument for flags, instead the filepath itself contains the flags. This means that for example there is no need for a special "truncate" redirect in a shell (>>) instead you can just add the "trunc" flag to the filepath and use a normal redirect (>).

Here is an example filepath: /this/is/a/path:with:some:flags.

Check the 'src/kernel/fs/path.h' file for a list of available flags.

Macro Definition Documentation

◆ KEY_SIZE

#define KEY_SIZE   16

Size of keys in bytes.

Definition at line 495 of file io.h.

◆ PIPE_READ

#define PIPE_READ   0

Pipe read end.

The PIPE_READ constant defines which file descriptor in fd from a open2 call on the /dev/pipe file will be the read end of the pipe.

Definition at line 55 of file io.h.

◆ PIPE_WRITE

#define PIPE_WRITE   1

Pipe write end.

The PIPE_WRITE constant defines which file descriptor in fd from a open2 call on the /dev/pipe file will be the write end of the pipe.

Definition at line 63 of file io.h.

◆ POLL_SPECIAL

#define POLL_SPECIAL   (POLLERR | POLLHUP | POLLNVAL)

Poll event values that will always be checked and included even if not specified.

Definition at line 300 of file io.h.

◆ STDERR_FILENO

#define STDERR_FILENO   2

Definition at line 46 of file io.h.

◆ STDIN_FILENO

#define STDIN_FILENO   0

Definition at line 44 of file io.h.

◆ STDOUT_FILENO

#define STDOUT_FILENO   1

Definition at line 45 of file io.h.

Typedef Documentation

◆ inode_number_t

Inode number enum.

Definition at line 353 of file io.h.

◆ seek_origin_t

Type for the seek() origin argument.

Definition at line 262 of file io.h.

Enumeration Type Documentation

◆ inode_type_t

Inode type enum.

Enumerator
INODE_FILE 

Is a file.

INODE_DIR 

Is a directory.

Definition at line 343 of file io.h.

◆ poll_events_t

Poll events type.

Enumerator
POLLNONE 

None.

POLLIN 

File descriptor is ready to read.

POLLOUT 

File descriptor is ready to write.

POLLERR 

File descriptor caused an error.

POLLHUP 

Stream socket peer closed connection, or shut down writing of connection.

POLLNVAL 

Invalid file descriptor.

Definition at line 287 of file io.h.

Function Documentation

◆ bind()

uint64_t bind ( fd_t  source,
const char *  mountpoint 
)

System call for binding a file descriptor to a mountpoint.

Parameters
sourceThe file descriptor to bind, must represent a directory.
mountpointThe mountpoint path.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 5 of file bind.c.

References _syscall_bind(), _syscall_errno(), ERR, and errno.

Referenced by SYSCALL_DEFINE().

◆ chdir()

uint64_t chdir ( const char *  path)

System call for changing the cwd.

Parameters
pathThe path to the new directory.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 9 of file chdir.c.

References _syscall_chdir(), _syscall_errno(), ERR, and errno.

Referenced by builtin_cd().

◆ claim()

fd_t claim ( key_t key)

System call for claiming a shared file descriptor.

After claiming a shared file descriptor, the key is no longer valid and cannot be used again.

Parameters
keyPointer to the key identifying the shared file descriptor.
Returns
On success, the claimed file descriptor. On failure, ERR and errno is set.

Definition at line 6 of file claim.c.

References _syscall_claim(), _syscall_errno(), ERR, and errno.

Referenced by window_new().

◆ close()

◆ dup()

fd_t dup ( fd_t  oldFd)

System call for duplicating file descriptors.

Parameters
oldFdThe open file descriptor to duplicate.
Returns
On success, the new file descriptor. On failure, ERR and errno is set.

Definition at line 9 of file dup.c.

References _syscall_dup(), _syscall_errno(), ERR, and errno.

Referenced by pipeline_execute_builtin().

◆ dup2()

fd_t dup2 ( fd_t  oldFd,
fd_t  newFd 
)

System call for duplicating file descriptors, with a destination.

Parameters
oldFdThe open file descriptor to duplicate.
newFdThe desired new file descriptor.
Returns
On success, the new file descriptor. On failure, ERR and errno is set.

Definition at line 9 of file dup2.c.

References _syscall_dup2(), _syscall_errno(), ERR, and errno.

Referenced by _populate_std_descriptors(), main(), pipeline_execute_builtin(), and taskbar_new().

◆ getdents()

uint64_t getdents ( fd_t  fd,
dirent_t buffer,
uint64_t  count 
)

System call for reading directory entires.

Parameters
fdThe file descriptor of the directory to read.
bufferThe destination buffer.
countThe size of the buffer in bytes.
Returns
On success, the total number of bytes written to the buffer. On failure, returns ERR and errno is set.

Definition at line 9 of file getdents.c.

References _syscall_errno(), _syscall_getdents(), buffer, count, ERR, and errno.

Referenced by print_dir().

◆ ioctl()

uint64_t ioctl ( fd_t  fd,
uint64_t  request,
void *  argp,
uint64_t  size 
)

System call for extended driver behaviour.

The ioctl() function allows drivers to implement unusual behaviour that would be impossible or impractical with a normal file-based API.

Parameters
fdThe file descriptor of the file.
requestThe driver-dependent request code.
argpA pointer to an argument that depends on the request, can be NULL if size is 0.
sizeThe size of the argument pointed to by argp.
Returns
On success, the return value depends on the driver but is usually 0. On failure, ERR and errno is set.

Definition at line 9 of file ioctl.c.

References _syscall_errno(), _syscall_ioctl(), ERR, and errno.

◆ link()

uint64_t link ( const char *  oldPath,
const char *  newPath 
)

System call for creating a hardlink.

Parameters
oldPath
newPath
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 9 of file link.c.

References _syscall_errno(), _syscall_link(), ERR, and errno.

Referenced by main().

◆ mkdir()

uint64_t mkdir ( const char *  path)

Wrapper for creating a directory.

Parameters
pathThe path of the directory to create.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 10 of file mkdir.c.

References close(), ERR, and openf().

◆ open()

fd_t open ( const char *  path)

System call for opening files.

The open() function opens a file located at a given path.

Parameters
pathThe path to the desired file.
Returns
On success, the file descriptor, on failure returns ERR and errno is set.

Definition at line 9 of file open.c.

References _syscall_errno(), _syscall_open(), ERR, and errno.

Referenced by _heap_init(), _populate_std_descriptors(), display_new(), dwm_init(), frontbuffer_init(), image_new(), main(), main(), openf(), pipeline_init(), readfile(), spawn_program(), surface_new(), taskbar_new(), vopenf(), vreadfilef(), vwritefilef(), and writefile().

◆ open2()

uint64_t open2 ( const char *  path,
fd_t  fd[2] 
)

System call for opening 2 file descriptors from one file.

This is intended as a more generic implementation of system calls like pipe() in for example Linux. One example use case of this system call is pipes, if open2 is called on /dev/pipe then fd[0] will store the read end of the pipe and fd[1] will store the write end of the pipe. But if open() is called on /dev/pipe then the returned file descriptor would be both ends.

Parameters
pathThe path to the desired file.
fdAn array of two fd_t where the new file descriptors will be stored.
Returns
On success, 0, on failure returns ERR and errno is set.

Definition at line 9 of file open2.c.

References _syscall_errno(), _syscall_open2(), ERR, and errno.

Referenced by pipeline_init(), and terminal_procedure().

◆ openf()

fd_t openf ( const char *_RESTRICT  format,
  ... 
)

Wrapper for opening files with a formatted path.

The openf() function opens a file located at a path specified by a format string and variable arguments. This is very usefull considering the amount of file path processing required for many of Patchworks APIs.

Parameters
formatThe format string specifying the path to the desired file.
...Variable arguments to be formatted into the path string.
Returns
On success, the file descriptor, on failure returns ERR and errno is set.

Definition at line 9 of file openf.c.

References MAX_PATH, open(), va_end, va_start, and vsnprintf().

Referenced by display_new(), dwm_client_accept(), dwm_init(), font_new(), fopen(), mkdir(), pipeline_execute(), print_dir(), system(), terminal_procedure(), and thrd_create().

◆ poll()

uint64_t poll ( pollfd_t fds,
uint64_t  amount,
clock_t  timeout 
)

System call for polling files.

Parameters
fdsAn array of pollfd_t structures, each specifying a file descriptor to poll in pollfd_t::fd and the events to wait for in pollfd_t::events.
amountThe number of pollfd_t structures in the fds array.
timeoutThe maximum time (in clock ticks) to wait for an event. If CLOCKS_NEVER, it waits forever.
Returns
On success, the number of file descriptors for which the events occurred. On timeout, 0. On failure, ERR and errno is set.

Definition at line 9 of file poll.c.

References _syscall_errno(), _syscall_poll(), ERR, and errno.

Referenced by display_next(), display_poll(), dwm_poll(), pipeline_execute(), and poll1().

◆ poll1()

poll_events_t poll1 ( fd_t  fd,
poll_events_t  events,
clock_t  timeout 
)

Wrapper for polling one file.

The poll1() function waits for events on a single file descriptor. Otherwise it is identical to poll() and exists simply for convenience.

Parameters
fdThe file descriptor to poll.
eventsThe events to wait for (e.g., POLLIN, POLLOUT).
timeoutThe maximum time (in clock ticks) to wait for an event. If CLOCKS_NEVER, it waits forever.
Returns
On success, the events that occurred. On timeout, 0. On failure, the POLLERR event bit is set and errno is set.

Definition at line 9 of file poll1.c.

References ERR, pollfd_t::fd, poll(), POLLERR, and pollfd_t::revents.

Referenced by dwm_kbd_read(), and dwm_mouse_read().

◆ read()

uint64_t read ( fd_t  fd,
void *  buffer,
uint64_t  count 
)

System call for reading from files.

Parameters
fdThe file descriptor to read from.
bufferA pointer to the buffer where the data will be stored.
countThe maximum number of bytes to read.
Returns
On success, the number of bytes read. On end-of-file, 0. On failure, ERR and errno is set.

Definition at line 9 of file read.c.

References _syscall_errno(), _syscall_read(), buffer, count, ERR, and errno.

Referenced by _file_fill_buffer(), client_receive_cmds(), cmdline_read(), display_events_pipe_read(), display_next(), display_wait(), dwm_kbd_read(), dwm_mouse_read(), font_new(), image_new(), interactive_shell(), pipeline_execute(), read_fd(), readfile(), system(), terminal_columns_get(), terminal_loop(), and vreadf().

◆ readf()

uint64_t readf ( fd_t  fd,
const char *_RESTRICT  format,
  ... 
)

Wrapper for reading a formatted string from a file.

Parameters
fdThe file descriptor to read from.
formatThe format string.
...Variable arguments to be formatted.
Returns
On success, the number of bytes read. On end-of-file, 0. On failure, ERR and errno is set.

Definition at line 6 of file readf.c.

References va_end, va_start, and vreadf().

◆ readfile()

uint64_t readfile ( const char *  path,
void *  buffer,
uint64_t  count,
uint64_t  offset 
)

Wrapper for reading a file directly using a path.

Equivalent to calling open(), seek(), read(), and close() in sequence.

Parameters
pathThe path to the file.
bufferA pointer to the buffer where the data will be stored.
countThe maximum number of bytes to read.
offsetThe offset in the file to start reading from.
Returns
On success, the number of bytes read. On end-of-file, 0. On failure, ERR and errno is set.

Definition at line 3 of file readfile.c.

References buffer, close(), count, ERR, open(), read(), seek(), and SEEK_SET.

Referenced by display_new(), dwm_init(), frontbuffer_init(), and interactive_prompt().

◆ readfilef()

uint64_t readfilef ( const char *  path,
const char *_RESTRICT  format,
  ... 
)

Wrapper for reading a formatted string from a file directly using a path.

Equivalent to calling open(), readf(), and close() in sequence.

Parameters
pathThe path to the file.
formatThe format string.
...Variable arguments to be formatted.
Returns
On success, the number of bytes read. On end-of-file, 0. On failure, ERR and errno is set.

Definition at line 3 of file readfilef.c.

References va_end, va_start, and vreadfilef().

◆ removef()

uint64_t removef ( const char *  format,
  ... 
)

Wrapper for removing a file with a formatted path.

Parameters
formatThe format string specifying the path of the file to remove.
...Variable arguments to be formatted into the path string.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 3 of file removef.c.

References va_end, va_start, and vremovef().

Referenced by rmdir().

◆ rmdir()

uint64_t rmdir ( const char *  path)

Wrapper for removing a directory.

Parameters
pathThe path of the directory to remove.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 5 of file rmdir.c.

References removef().

◆ seek()

uint64_t seek ( fd_t  fd,
int64_t  offset,
seek_origin_t  origin 
)

System call for changing the file offset.

Parameters
fdThe file descriptor.
offsetThe offset to move the file pointer.
originThe origin that the offset is relative to (e.g., SEEK_SET, SEEK_CUR, SEEK_END).
Returns
On success, the new offset from the beginning of the file. On failure, ERR and errno is set.

Definition at line 9 of file seek.c.

References _syscall_errno(), _syscall_seek(), ERR, and errno.

Referenced by _file_seek(), font_new(), image_new(), readfile(), and writefile().

◆ share()

uint64_t share ( key_t key,
fd_t  fd,
clock_t  timeout 
)

System call for sharing a file descriptor with another process.

Note that the file descriptor itself is not whats sent but the underlying file object.

Parameters
keyOutput pointer to store the generated key.
fdThe file descriptor to share.
timeoutThe time until the shared file descriptor expires. If CLOCKS_NEVER, it never expires.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 6 of file share.c.

References _syscall_errno(), _syscall_share(), ERR, and errno.

Referenced by client_action_surface_new().

◆ stat()

uint64_t stat ( const char *  path,
stat_t stat 
)

System call for retrieving info about a file or directory.

Parameters
pathThe path to the file or directory.
statA pointer to a stat_t structure where the file information will be stored.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 9 of file stat.c.

References _syscall_errno(), _syscall_stat(), ERR, errno, and info.

Referenced by pipeline_execute_cmd(), print_stat(), start_services(), statistics_cpu_read(), statistics_interrupt_begin(), and statistics_interrupt_end().

◆ unlink()

uint64_t unlink ( const char *  path)

Wrapper for removing a file.

Parameters
pathThe path of the file to remove.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 5 of file unlink.c.

References _syscall_errno(), _syscall_remove(), ERR, and errno.

◆ vopenf()

fd_t vopenf ( const char *_RESTRICT  format,
va_list  args 
)

Wrapper for opening files with a formatted path, using a va_list.

Parameters
formatThe format string specifying the path to the desired file.
argsA va_list containing the arguments to be formatted into the path string.
Returns
On success, the file descriptor, on failure returns ERR and errno is set.

Definition at line 9 of file vopenf.c.

References MAX_PATH, open(), and vsnprintf().

◆ vreadf()

uint64_t vreadf ( fd_t  fd,
const char *_RESTRICT  format,
va_list  args 
)

Wrapper for reading a formatted string from a file with a va_list.

Parameters
fdThe file descriptor to read from.
formatThe format string.
argsA va_list containing the arguments to be formatted.
Returns
On success, the number of bytes read. On end-of-file, 0. On failure, ERR and errno is set.

Definition at line 6 of file vreadf.c.

References buffer, EINVAL, ERR, errno, read(), and vsscanf().

Referenced by readf(), and vreadfilef().

◆ vreadfilef()

uint64_t vreadfilef ( const char *  path,
const char *_RESTRICT  format,
va_list  args 
)

Wrapper for reading a formatted string from a file directly using a path with a va_list.

Equivalent to calling open(), vreadf(), and close() in sequence.

Parameters
pathThe path to the file.
formatThe format string.
argsA va_list containing the arguments to be formatted.
Returns
On success, the number of bytes read. On end-of-file, 0. On failure, ERR and errno is set.

Definition at line 3 of file vreadfilef.c.

References close(), ERR, open(), and vreadf().

Referenced by readfilef().

◆ vremovef()

uint64_t vremovef ( const char *  format,
va_list  args 
)

Wrapper for removing a file with a formatted path, using a va_list.

Parameters
formatThe format string specifying the path of the file to remove.
argsA va_list containing the arguments to be formatted into the path string.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 8 of file vremovef.c.

References _syscall_errno(), _syscall_remove(), count, EINVAL, ERR, errno, MAX_PATH, and vsnprintf().

Referenced by removef().

◆ vwritef()

uint64_t vwritef ( fd_t  fd,
const char *_RESTRICT  format,
va_list  args 
)

Wrapper for writing a formatted string to a file with a va_list.

Parameters
fdThe file descriptor to write to.
formatThe format string.
argsA va_list containing the arguments to be formatted.
Returns
On success, the number of bytes written. On failure, ERR and errno is set.

Definition at line 6 of file vwritef.c.

References buffer, count, EINVAL, ERR, errno, vsnprintf(), and write().

Referenced by vwritefilef(), and writef().

◆ vwritefilef()

uint64_t vwritefilef ( const char *  path,
const char *_RESTRICT  format,
va_list  args 
)

Wrapper for writing a formatted string to a file directly using a path with a va_list.

Equivalent to calling open(), vwritef(), and close() in sequence.

Parameters
pathThe path to the file.
formatThe format string.
argsA va_list containing the arguments to be formatted.
Returns
On success, the number of bytes written. On failure, ERR and errno is set.

Definition at line 3 of file vwritefilef.c.

References close(), ERR, open(), and vwritef().

Referenced by writefilef().

◆ write()

uint64_t write ( fd_t  fd,
const void *  buffer,
uint64_t  count 
)

System call for writing to files.

Parameters
fdThe file descriptor to write to.
bufferA pointer to the buffer containing the data to write.
countThe number of bytes to write.
Returns
On success, the number of bytes written. On failure, ERR and errno is set.

Definition at line 9 of file write.c.

References _syscall_errno(), _syscall_write(), buffer, count, ERR, and errno.

Referenced by _file_flush_buffer(), _populate_std_descriptors(), client_send_all(), display_cmds_flush(), display_events_pipe_write(), pipeline_execute(), read_fd(), terminal_handle_input(), ternminal_execute_ansi(), vwritef(), and writefile().

◆ writef()

uint64_t writef ( fd_t  fd,
const char *_RESTRICT  format,
  ... 
)

Wrapper for writing a formatted string to a file.

Parameters
fdThe file descriptor to write to.
formatThe format string.
...Variable arguments to be formatted.
Returns
On success, the number of bytes written. On failure, ERR and errno is set.

Definition at line 9 of file writef.c.

References va_end, va_start, and vwritef().

Referenced by display_new(), dwm_init(), main(), pipeline_execute(), read_fd(), and terminal_procedure().

◆ writefile()

uint64_t writefile ( const char *  path,
const void *  buffer,
uint64_t  count,
uint64_t  offset 
)

Wrapper for writing a file directly using a path.

Equivalent to calling open(), seek(), write(), and close() in sequence.

Parameters
pathThe path to the file.
bufferA pointer to the buffer containing the data to write.
countThe number of bytes to write.
offsetThe offset in the file to start writing to.
Returns
On success, the number of bytes written. On failure, ERR and errno is set.

Definition at line 3 of file writefile.c.

References buffer, close(), count, ERR, open(), seek(), SEEK_SET, and write().

◆ writefilef()

uint64_t writefilef ( const char *  path,
const char *_RESTRICT  format,
  ... 
)

Wrapper for writing a formatted string to a file directly using a path.

Equivalent to calling open(), writef(), and close() in sequence.

Parameters
pathThe path to the file.
formatThe format string.
...Variable arguments to be formatted.
Returns
On success, the number of bytes written. On failure, ERR and errno is set.

Definition at line 3 of file writefilef.c.

References va_end, va_start, and vwritefilef().