libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
Data Structures | Functions
io.h File Reference

Defines safe file I/O functions. More...

#include "def.h"

Go to the source code of this file.

Data Structures

struct  ps_file_ctx
 Information captured in a file necessary for effective info/error reporting. More...
 

Functions

void ps_file_ctx_init (struct ps_file_ctx *file_ctx, STR filename, char *buffer, usize length)
 Initializes file_ctx to describe the given file (filename, buffer, length).
 
char * ps_read_file_safe (STR filename, isize *length_ext)
 Reads the contents the file at filename.
 

Detailed Description

Defines safe file I/O functions.

Author
Ethan Uppal

Definition in file io.h.

Function Documentation

◆ ps_file_ctx_init()

void ps_file_ctx_init ( struct ps_file_ctx file_ctx,
STR  filename,
char *  buffer,
usize  length 
)

Initializes file_ctx to describe the given file (filename, buffer, length).

Definition at line 7 of file io.c.

◆ ps_read_file_safe()

char * ps_read_file_safe ( STR  filename,
isize length_ext 
)

Reads the contents the file at filename.

The length is reported via length_ext, which must be a valid pointer. The program exits on file I/O error.

Returns
A null-terminated allocated string containing the file contents. You must free this.