libreis  0.1.0
A simple header-based drop-in library
Functions
io.c File Reference

New functions related to file handling and writing to stdout. More...

#include <reis/io.h>
#include <reis/string.h>
#include <errno.h>
#include <stdarg.h>

Functions

char fpeek (FILE *stream)
 View the next character in stream, doesn't move pointer. More...
 
wchar_t fpeek_wc (FILE *stream)
 Same as fpeek but for wchar_t. More...
 
char fspeek (FILE *stream, long int offset, int position)
 View a character at position without moving pointer; Peeks a seek. More...
 
int frpeek (FILE *stream, char c)
 A recursive peek that goes to end of line or EOF to get # of occurences. More...
 
int frdpeek (FILE *stream, char d)
 A recursive peek that goes till the delimter d. More...
 
int fcounts (FILE *stream)
 Character count of current line of buffer. More...
 
void fcopy (FILE *dest, FILE *src)
 Copies data from src file to dest file. More...
 
const char * ExtractFileExtension (const char *filename)
 Returns file extension. More...
 
const char * ExtractFileName (const char *path)
 Returns filename. More...
 
bool fmove (char *oldpath, char *newpath)
 Move data from oldpath file to newpath. More...
 
bool fexists (const char *file)
 Checks if file exists. More...
 
bool dexists (const char *path)
 Checks if directory exists. More...
 
void sgets (char *str, int n)
 A safe way to read input that ensures no misc LF or breaks in read string. More...
 
bool PromptYesOrNo (const char *question)
 Prompts the user with a yes or no question. More...
 
 CHECK_PRINTF_FMT (1, 2)
 Makes writing error to stderr slightly simpler. More...
 
void eprintf (const char *fmt,...)
 
 CHECK_PRINTF_FMT (1, 3)
 Easy color printing. More...
 
void cprintf (const char *color, const char *fmt,...)
 
FilesystemrsNewFilesystem (char *path)
 Create a Filesystem object. More...
 
void rsFreeFilesystem (Filesystem *fs)
 Terminates a Filesystem object. More...
 

Detailed Description

New functions related to file handling and writing to stdout.

Author
yung-turabian
Date
22 1 2025

Function Documentation

◆ CHECK_PRINTF_FMT() [1/2]

CHECK_PRINTF_FMT ( ,
 
)

Makes writing error to stderr slightly simpler.

Returns
nothing.

◆ CHECK_PRINTF_FMT() [2/2]

CHECK_PRINTF_FMT ( ,
 
)

Easy color printing.

Parameters
colorA provided macro for VT100 escapes, or your own.
fmtA format string.
...Completions for the format.
Returns
nothing. @usage cprintf( ANSI_GREEN, "Hello %s!", "World" );

◆ dexists()

bool dexists ( const char *  path)

Checks if directory exists.

Returns
a boolean.

◆ ExtractFileExtension()

const char* ExtractFileExtension ( const char *  filename)

Returns file extension.

Returns
file exteionsion.

◆ ExtractFileName()

const char* ExtractFileName ( const char *  path)

Returns filename.

Returns
a filename.

◆ fcopy()

void fcopy ( FILE *  dest,
FILE *  src 
)

Copies data from src file to dest file.

Returns
void.

◆ fcounts()

int fcounts ( FILE *  stream)

Character count of current line of buffer.

Returns
A count.

◆ fexists()

bool fexists ( const char *  file)

Checks if file exists.

Returns
a boolean.

◆ fmove()

bool fmove ( char *  oldpath,
char *  newpath 
)

Move data from oldpath file to newpath.

Returns
a boolean if was succesful or not.

◆ fpeek()

char fpeek ( FILE *  stream)

View the next character in stream, doesn't move pointer.

Returns
the character.

◆ fpeek_wc()

wchar_t fpeek_wc ( FILE *  stream)

Same as fpeek but for wchar_t.

Returns
the character.

◆ frdpeek()

int frdpeek ( FILE *  stream,
char  d 
)

A recursive peek that goes till the delimter d.

Returns
The number of occurences.

◆ frpeek()

int frpeek ( FILE *  stream,
char  c 
)

A recursive peek that goes to end of line or EOF to get # of occurences.

Returns
the number of occurences.

◆ fspeek()

char fspeek ( FILE *  stream,
long int  offset,
int  position 
)

View a character at position without moving pointer; Peeks a seek.

Returns
seeked and peeked character.

◆ PromptYesOrNo()

bool PromptYesOrNo ( const char *  question)

Prompts the user with a yes or no question.

Returns
boolean response.

◆ rsFreeFilesystem()

void rsFreeFilesystem ( Filesystem fs)

Terminates a Filesystem object.

Returns
nothing.

◆ rsNewFilesystem()

Filesystem* rsNewFilesystem ( char *  path)

Create a Filesystem object.

Returns
The new structure.

◆ sgets()

void sgets ( char *  str,
int  n 
)

A safe way to read input that ensures no misc LF or breaks in read string.

Parameters
[str]A buffer.
[n]The buffer's length.
Returns
nothing.