libite
Macros | Typedefs | Functions
lite.h File Reference

Collection of frog DNA. More...

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/param.h>
#include <unistd.h>
#include "strlite.h"
#include <sys/time.h>
Include dependency graph for lite.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LIBITE_LITE_H_
 
#define FPARSELN_UNESCESC   0x01
 Remove escape preceding an escaped comment. More...
 
#define FPARSELN_UNESCCONT   0x02
 Remove escape preceding an escaped continuation. More...
 
#define FPARSELN_UNESCCOMM   0x04
 Remove escape preceding an escaped escape. More...
 
#define FPARSELN_UNESCREST   0x08
 Remove escape preceding any other character. More...
 
#define FPARSELN_UNESCALL   0x0f
 All of the above. More...
 
#define LITE_FOPT_RSYNC_DELETE   0x01
 Prune files from destination that are not in source.
 
#define LITE_FOPT_COPYFILE_SYM   0x01
 Recreate symlink or follow to copy target.
 
#define LITE_FOPT_KEEP_MTIME   0x02
 Preserve modification time.
 
#define chardev(x, m, maj, min)   mknod((x), S_IFCHR|(m), makedev((maj),(min)))
 
#define blkdev(x, m, maj, min)   mknod((x), S_IFBLK|(m), makedev((maj),(min)))
 
#define S_ISEXEC(m)   (((m) & S_IXUSR) == S_IXUSR)
 
#define ISCLR(word, bit)   ((word & (1 << (bit)) ? 0 : 1))
 Is bit cleared in word?
 
#define ISSET(word, bit)   ((word & (1 << (bit)) ? 1 : 0))
 Is bit set in word?
 
#define ISOTHER(word, bit)   ((word & ~(1 << (bit)) ? 1 : 0))
 Is any other bit set?
 
#define SETBIT(word, bit)   (word |= (1 << (bit)))
 Set bit in word. More...
 
#define CLRBIT(word, bit)   (word &= ~(1 << (bit)))
 Clear bit in word. More...
 
#define NELEMS(array)   (sizeof(array) / sizeof(array[0]))
 Number of elements in array. More...
 
#define copy_filep(src, dst)   fcopyfile(src, dst)
 
#define pidfile_read_pid(file)   pidfile_read(file)
 
#define signal_pidfile(file, signo)   pidfile_signal(file, signo)
 

Typedefs

typedef struct lfile lfile_t
 Opqaue context struct for lfile APIs.
 
typedef struct sdbuf sdbuf_t
 Opqaue context struct for telnet APIs.
 

Functions

char * chomp (char *str)
 Perl like chomp function, chop off last char(s) if newline. More...
 
int erasef (const char *fmt,...) __attribute__((format(printf
 
int char * fparseln (FILE *, size_t *, size_t *, const char[3], int)
 Read a line from a file parsing continuations and trailing newlines. More...
 
int fexist (const char *file)
 Check if a file exists in the file system. More...
 
int fexistf (const char *fmt,...) __attribute__((format(printf
 
int int fisdir (const char *path)
 Check if a path exists and is a directory. More...
 
FILE * vfopenf (const char *mode, const char *fmt, va_list ap)
 Similar to fopenf() except it takes a va_list argument. More...
 
FILE * fopenf (const char *mode, const char *fmt,...) __attribute__((format(printf
 
FILE int fremove (const char *fmt,...) __attribute__((format(printf
 
FILE int FILE * tempfile (void)
 A secure tmpfile() replacement. More...
 
ssize_t copyfile (const char *src, const char *dst, int len, int opt)
 Copy a file to another. More...
 
int movefile (const char *src, const char *dst)
 Move a file to another location. More...
 
int fcopyfile (FILE *src, FILE *dst)
 Copy between FILE *fp. More...
 
ssize_t fsendfile (FILE *src, FILE *dst, size_t len)
 Copy data between file streams. More...
 
int truncatef (off_t length, const char *fmt,...) __attribute__((format(printf
 
int char * vreadsnf (char *line, size_t len, const char *fmt, va_list ap)
 Similar to readsnf() except it takes a va_list argument. More...
 
char * readsnf (char *line, size_t len, const char *fmt,...)
 Read first line from a file composed from fmt and optional args. More...
 
int writesf (const char *str, const char *mode, const char *fmt,...)
 Write a string buffer to a file composed from fmt and optional args. More...
 
int vreadllf (long long *value, const char *fmt, va_list ap)
 Same as readllf() except it takes a va_list argument.
 
int readllf (long long *value, const char *fmt,...)
 Read 64-bit integer value from a file composed from fmt and optional args. More...
 
int readdf (int *value, const char *fmt,...)
 Read integer value from a file composed from fmt and optional args. More...
 
int writellf (long long value, const char *mode, const char *fmt,...)
 Write 64-bit integer value to a file composed from fmt and optional args. More...
 
int writedf (int value, const char *mode, const char *fmt,...)
 Write integer value to a file composed from fmt and optional args. More...
 
int ifconfig (const char *ifname, const char *addr, const char *mask, int up)
 Basic ifconfig like operations on an interface. More...
 
lfile_tlfopen (const char *file, const char *sep)
 Open file and return parsing context. More...
 
void lfclose (lfile_t *lf)
 Close a parser context. More...
 
char * lftok (lfile_t *lf)
 Get next token in file. More...
 
char * lfgetkey (lfile_t *lf, const char *key)
 Find key in file. More...
 
int lfgetint (lfile_t *lf, const char *key)
 Same as lfgetkey() but returns an integer. More...
 
int fgetint (const char *file, const char *sep, const char *key)
 Find the integer value for key in a file. More...
 
int fmkpath (mode_t mode, const char *fmt,...) __attribute__((format(printf
 
int int mkpath (const char *dir, mode_t mode)
 makepath() but takes a mode_t argument. More...
 
int makepath (const char *dir)
 Create all components of the specified directory. More...
 
int dir (const char *dir, const char *type, int(*filter)(const char *file), char ***list, int strip)
 List all files of a certain type in the given directory. More...
 
int rsync (char *src, char *dst, int opt, int(*filter)(const char *file))
 Synchronize contents and optionally remove non-existing backups. More...
 
FILE * popenf (const char *type, const char *fmt,...) __attribute__((format(printf
 
FILE int pidfile (const char *basename)
 Create or update mtime of process PID file. More...
 
int pidfile_signal (const char *pidfile, int signal)
 Send signal to a PID and cleanup pidfile afterwards. More...
 
pid_t pidfile_read (const char *pidfile)
 Reads a PID value from a pidfile. More...
 
pid_t pidfile_poll (const char *pidfile)
 Poll for the existence of a pidfile and return PID. More...
 
void * reallocarray (void *optr, size_t nmemb, size_t size)
 Similar to realloc() but for an array of items, like calloc() More...
 
void progress (int percent, int max_width)
 Advanced ASCII progress bar with spinner. More...
 
void progress_simple (int percent)
 Alternative progress bar on systems where progress() doesn't work. More...
 
int runbg (char *const cmd[], int delay)
 Run command in the background. More...
 
int systemf (const char *fmt,...) __attribute__((format(printf
 
int sdbuf_ttelnet_open (int addr, short port)
 Open telnet connection to addr:port and connect. More...
 
int telnet_close (sdbuf_t *ctx)
 Close a telnet session previously opened with telnet_open() More...
 
int telnet_expect (sdbuf_t *ctx, char *script[], FILE *output)
 Poor man's telnet expect. More...
 
int telnet_session (int addr, short port, char *script[], FILE *output)
 Very simple expect-like implementation for telnet. More...
 
int touchf (const char *fmt,...) __attribute__((format(printf
 
int int yorn (const char *fmt,...) __attribute__((format(printf
 
int int char * which (const char *cmd)
 Like which(1), or command -v foo More...
 
int whichp (const char *cmd)
 Predicate variant of which() More...
 

Detailed Description

Collection of frog DNA.

Author
Claudio Matsuoka (2008-2010)
Joachim Wiberg (2008-2023)

The latest version of this manual and the libite (-lite) software library are available at https://github.com/troglobit/libite/

Macro Definition Documentation

◆ CLRBIT

#define CLRBIT (   word,
  bit 
)    (word &= ~(1 << (bit)))

Clear bit in word.

◆ FPARSELN_UNESCALL

#define FPARSELN_UNESCALL   0x0f

All of the above.

◆ FPARSELN_UNESCCOMM

#define FPARSELN_UNESCCOMM   0x04

Remove escape preceding an escaped escape.

◆ FPARSELN_UNESCCONT

#define FPARSELN_UNESCCONT   0x02

Remove escape preceding an escaped continuation.

◆ FPARSELN_UNESCESC

#define FPARSELN_UNESCESC   0x01

Remove escape preceding an escaped comment.

◆ FPARSELN_UNESCREST

#define FPARSELN_UNESCREST   0x08

Remove escape preceding any other character.

◆ NELEMS

#define NELEMS (   array)    (sizeof(array) / sizeof(array[0]))

Number of elements in array.

◆ SETBIT

#define SETBIT (   word,
  bit 
)    (word |= (1 << (bit)))

Set bit in word.

Function Documentation

◆ chomp()

char* chomp ( char *  str)

Perl like chomp function, chop off last char(s) if newline.

Parameters
strString to chomp

This function is like Perl chomp, but it's set to chop of all trailing newlines. Useful in combination with fgets().

Returns
str, or NULL with errno set, if str is not a valid pointer.
Exceptions
EINVALif the input argument is not a valid pointer.

◆ copyfile()

ssize_t copyfile ( const char *  src,
const char *  dst,
int  len,
int  opt 
)

Copy a file to another.

Parameters
srcFull path name to source file.
dstFull path name to target file.
lenNumber of bytes to copy, zero (0) for entire file.
optAn option mask of LITE_FOPT_COPYFILE_SYM, LITE_FOPT_KEEP_MTIME

This is a C implementation of the command line cp(1) utility. It is one of the classic missing links in the UNIX C library. This version is from the finit project, http://helllabs.org/finit/, which is a reimplementation of fastinit for the Asus EeePC.

The opt field replaces the sym argument in previous releases and works as follows. To maintain backwards compatibility with sym the LITE_FOPT_COPYFILE_SYM has a value of 1. Supported option flags are:

Returns
The number of bytes copied, or zero, which may be an error (check errno, see Exceptions below), but it may also indicate that src was empty. See exceptions, below.
Exceptions
EISDIRif src is a directory, since copyfile() is not recursive.

◆ dir()

int dir ( const char *  dir,
const char *  type,
int(*)(const char *file)  filter,
char ***  list,
int  strip 
)

List all files of a certain type in the given directory.

Parameters
dirBase directory for dir operation.
typeFile type suffix, e.g. ".cfg".
filterOptional file name filter.
listPointer to an array of file names.
stripFlag, if set dir() strips the file type.

This function returns a list of files, matching the type suffix, in the given directory dir.

The list argument is a pointer to where to store the dynamically allocated list of file names. This list should be free'd by first calling free() on each file name and then on the list itself.

If filter is not NULL it will be called for each file found. If filter returns non-zero the file argument is included in the resulting list. If filter returns zero for given file it is discarded. If the strip flag is set the resulting list of files has their file type stripped, including the dot. So a match "config0.cfg" would be returned as "config0".

Returns
The number of files in list, zero if no matching files of type, or non-zero on error with errno set.

◆ fcopyfile()

int fcopyfile ( FILE *  src,
FILE *  dst 
)

Copy between FILE *fp.

Parameters
srcSource FILE.
dstDestination FILE.
Returns
POSIX OK(0), or non-zero with errno set on error.

◆ fexist()

int fexist ( const char *  file)

Check if a file exists in the file system.

Parameters
fileFile to look for, with full path.
Returns
TRUE(1) if the file exists, otherwise FALSE(0).

◆ fgetint()

int fgetint ( const char *  file,
const char *  sep,
const char *  key 
)

Find the integer value for key in a file.

Parameters
fileFile to search for key
sepSeparator for tokens in file
keyKey to look for in file

This is a convenience wrapper for lfopen(), lfgetint(), and lfclose().

Returns
The positive integer value for key, or -1 if not found.

◆ fisdir()

int int fisdir ( const char *  path)

Check if a path exists and is a directory.

Parameters
pathPath to file or directory
Returns
TRUE(1) if path exists and is a directory, otherwise FALSE(0).

◆ fparseln()

int char* fparseln ( FILE *  fp,
size_t *  size,
size_t *  lineno,
const char  str[3],
int  flags 
)

Read a line from a file parsing continuations and trailing newlines.

Parameters
fpFILE pointer to read from
sizeThe resulting length of the string, unused if NULL
linenoIncremented with number of lines read, unused if NULL
strCharacters to look for, escape character, continuation, and comment
flagsFPARSELN_UNESCCOMM, FPARSELN_UNESCCONT, FPARSELN_UNESCESC, FPARSELN_UNESCREST, FPARSELN_UNESCALL

This function reads a line from a file, parsing continuations ending in '\' and eliminating trailing newlines, or comments starting with the comment char '#'.

If size is not NULL, the resulting length of the returned string is stored in size.

If lineno is not NULL, it is incremented for each actual line read from fp.

Returns
the line read from fp, or NULL on EOF or error.

◆ fsendfile()

ssize_t fsendfile ( FILE *  src,
FILE *  dst,
size_t  len 
)

Copy data between file streams.

Parameters
srcSource stream
dstDestination stream
lenNumber of bytes to copy

The dst argument may be NULL, in which case len bytes are read and discarded from src. This can be useful for streams where seeking is not permitted. Additionally, len may be the special value zero (0), in which case fsendfile() copies until EOF is seen on src.

Returns
The number of bytes copied. If an error is detected -1 is returned and errno will be set accordingly.

◆ ifconfig()

int ifconfig ( const char *  ifname,
const char *  addr,
const char *  mask,
int  up 
)

Basic ifconfig like operations on an interface.

Parameters
ifnameName of interface to operate on
addrIf up then set this optional IPv4 address
maskIf up and addr, and addr is not INADDR_ANY, then set netmask
upControl IFF_UP flag on interface
Returns
POSIX OK(0) on success, or non-zero on error.

◆ lfclose()

void lfclose ( lfile_t lf)

Close a parser context.

Parameters
lfPointer to lfile_t parser context from lfopen()

◆ lfgetint()

int lfgetint ( lfile_t lf,
const char *  key 
)

Same as lfgetkey() but returns an integer.

Parameters
lfPointer to lfile_t parser context from lfopen()
keyKey to look for

This function is the same as lfgetkey() but returns the positive integer value for the matching key, if found.

Returns
The positive integer value for key, or -1 if not found.

◆ lfgetkey()

char* lfgetkey ( lfile_t lf,
const char *  key 
)

Find key in file.

Parameters
lfPointer to lfile_t parser context from lfopen()
keyKey to look for

Locate key from the current position in the file parser context returned from lfopen(). Please note, the search for key does not start from the beginning of the file, it searches from the current position. To restart search from the beginning use rewind() on the lf->fp.

Returns
The value to key, or NULL if not found.

◆ lfopen()

lfile_t* lfopen ( const char *  file,
const char *  sep 
)

Open file and return parsing context.

Parameters
fileFile to parse
sepSeparator(s) to use in lftok()
Returns
Pointer to an lfile_t parser context, or NULL on error.

◆ lftok()

char* lftok ( lfile_t lf)

Get next token in file.

Parameters
lfPointer to lfile_t parser context from lfopen()
Returns
Next token, read from file previously opened with lfopen(), or NULL if EOF.

◆ makepath()

int makepath ( const char *  dir)

Create all components of the specified directory.

Parameters
dirDirectory to create.
Note
It is strongly recommended to use mkpath() over this function since it has the mode argument while this function default to 0777, which in most cases is insecure.
Returns
POSIX OK (0) on success, otherwise -1 and errno set appropriately.
Exceptions
EINVALon bad argument, or
ENOMEMwhen it fails allocating temporary memory.

For other error codes see the mkdir(2) syscall description.

◆ mkpath()

int int mkpath ( const char *  dir,
mode_t  mode 
)

makepath() but takes a mode_t argument.

Parameters
dirDirectory to created, relative or absolute
modeA &mode_t mode to create dir with
Returns
POSIX OK(0) on success, otherwise -1 with errno set.

◆ movefile()

int movefile ( const char *  src,
const char *  dst 
)

Move a file to another location.

Parameters
srcSource file.
dstTarget file, or location.

This is a C implementation of the command line mv(1) utility. Usually the rename() API is sufficient, but not when moving across file system boundaries.

The src argument must include the full path to the source file, whereas the dst argument may only be a directory, in which case the same file name from src is used.

Returns
POSIX OK(0), or non-zero with errno set.

◆ pidfile()

FILE int pidfile ( const char *  basename)

Create or update mtime of process PID file.

Parameters
basenameProgram name, or NULL, may start with '/'

This function is intended to be used by UNIX daemons to save the PID of the main process responsible for handling signals. If basename is NULL the implicit __progname variable from the C-library is used. The basename may also start with '/', in which case it is interpreted as the absolute path to the PID file.

Returns
POSIX OK(0) on success, otherwise non-zero on error.

◆ pidfile_poll()

pid_t pidfile_poll ( const char *  pidfile)

Poll for the existence of a pidfile and return PID.

Parameters
pidfilePath to pidfile to poll for

This function polls for the pidfile at pidfile for at most 5 seconds before timing out. If the file is created within that time span the file is read and its PID contents returned.

Returns
The PID read from pidfile, or zero on timeout.

◆ pidfile_read()

pid_t pidfile_read ( const char *  pidfile)

Reads a PID value from a pidfile.

Parameters
pidfileFile containing PID, usually in /var/run/PROCNAME.pid

This function takes a pidfile and returns the PID found therein.

Returns
On invalid pidfile, -1 with errno set. If the pidfile is empty, or when its contents cannot be translated, this function returns zero (0), on success this function returns a PID value greater than one.
Note
PID 1 is reserved for the system init process.
Exceptions
EINVALon invalid pidfile, or
ENOENTwhen pidfile does not exist.

◆ pidfile_signal()

int pidfile_signal ( const char *  pidfile,
int  signal 
)

Send signal to a PID and cleanup pidfile afterwards.

Parameters
pidfileFile containing PID, usually in /var/run/PROCNAME.pid
signalSignal to send to PID found in pidfile.

If signal is any of SIGTERM or SIGKILL, or if kill(2) returns -1, the pidfile is removed.

Returns
POSIX OK(0) on success, non-zero otherwise.

◆ progress()

void progress ( int  percent,
int  max_width 
)

Advanced ASCII progress bar with spinner.

Parameters
percentStart first call with this set to 0, end with 100
max_widthMax width of progress bar, in total characters.

This function draws an advanced ASCII progressbar at the current line. It always start from the first column.

The progress bar will hide the cursor if started with percent 0 and show it again at the end, when called with percent 100.

While being called with the same percentage the spinner will spin, to show the user the process hasn't frozen.

If the output TTY cannot interpret control characters, like \r, it is advised to instead used the progress_simple() function.

◆ progress_simple()

void progress_simple ( int  percent)

Alternative progress bar on systems where progress() doesn't work.

Parameters
percentStart first call with this set to 0, end with 100

◆ readdf()

int readdf ( int *  value,
const char *  fmt,
  ... 
)

Read integer value from a file composed from fmt and optional args.

Parameters
valuePointer to where to store read integer value.
modeAn fopen() mode string, e.g. "w+".
fmtFormatted string to be composed into a pathname.
Returns
result of operation, with errno set on error.

◆ readllf()

int readllf ( long long *  value,
const char *  fmt,
  ... 
)

Read 64-bit integer value from a file composed from fmt and optional args.

Parameters
valuePointer to where to store read 64-bit integer value.
modeAn fopen() mode string, e.g. "w+".
fmtFormatted string to be composed into a pathname.
Returns
result of operation, with errno set on error.

◆ readsnf()

char* readsnf ( char *  line,
size_t  len,
const char *  fmt,
  ... 
)

Read first line from a file composed from fmt and optional args.

Parameters
linePointer to line buffer.
lenSize of line buffer.
fmtFormatted string to be composed into a pathname.
Returns
On success, this function returns the line read from the file, with any trailing '
' chomp()ed out. On error, NULL.

◆ reallocarray()

void* reallocarray ( void *  optr,
size_t  nmemb,
size_t  size 
)

Similar to realloc() but for an array of items, like calloc()

Parameters
optrPointer to old (current) array
nmembNumber of elements
sizeSize of each element, in bytes
Returns
A pointer to the new array, or NULL on error.

◆ rsync()

int rsync ( char *  src,
char *  dst,
int  opt,
int(*)(const char *file)  filter 
)

Synchronize contents and optionally remove non-existing backups.

Parameters
srcSource directory
dstDestination directory
optAn option mask of LITE_FOPT_RSYNC_DELETE, LITE_FOPT_KEEP_MTIME
filterOptional filtering function for source directory.

This is a miniature implementation of the famous rsync for local use only. In fact, it is not even a true rsync since it copies all files from src to dst. The LITE_FOPT_RSYNC_DELETE opt flag is useful for creating backups, when set all files removed from src since last backup are pruned from the destination (backup) directory.

The opt parameter to rsync() is an option mask for the most common rsync(1) options. Previously this argument was called delete and to maintain backwards compatibility the value 1 is reserved:

LITE_FOPT_RSYNC_DELETE: Prune files from dst that no longer exist in src. LITE_FOPT_KEEP_MTIME: Preserve modification time

The filter callback, filter, if provided, is used to determine what files to include from the source directory when backing up. If a file is to be skipped the callback should simply return zero.

Returns: POSIX OK(0), or non-zero with errno set on error.

◆ runbg()

int runbg ( char *const  cmd[],
int  delay 
)

Run command in the background.

Parameters
cmdNULL terminated list of command and optional arguments
delayMicroseconds after fork() to wait before calling cmd

This function forks to run the given command cmd in the background. To ensure there are no lingering zombies the function actuall forks twice, and also calls setsid(), before it calls usleep() with the delay argument. The command cmd is handed over to execvp().

Since it runs in the background it is not possible to get the return code of the command.

Returns
on successful (first) fork(), this function returns POSIX OK(0), otherwise -1 and errno is set to indicate the error.

◆ telnet_close()

int telnet_close ( sdbuf_t ctx)

Close a telnet session previously opened with telnet_open()

Parameters
ctxAn sdbuf_t socket buffer context
Returns
Always returns POSIX OK(0).

◆ telnet_expect()

int telnet_expect ( sdbuf_t ctx,
char *  script[],
FILE *  output 
)

Poor man's telnet expect.

Parameters
ctxTelnet session context from telnet_open()
scriptNULL terminated list of expect and response strings
outputOptional output from session

Issues script sequence on telnet session specified in ctx, with optional output from session.

The script consists of strings of expect and response pairs. For example, expect "ogin: " followed by response "root\n", expect "assword: "with response "secret\n", concluded by NULL.

Returns
POSIX OK(0) or non-zero on error.

◆ telnet_open()

int sdbuf_t* telnet_open ( int  addr,
short  port 
)

Open telnet connection to addr:port and connect.

Parameters
addrInteger encoded IPv4 address in network byte order
portInternet port number in network byte order
Returns
An sdbuf_t socket buffer context.

◆ telnet_session()

int telnet_session ( int  addr,
short  port,
char *  script[],
FILE *  output 
)

Very simple expect-like implementation for telnet.

Parameters
addrInteger encoded IPv4 address, in network byte order, use htonl().
portInternet port to connect to, in network byte order, use htons().
scriptExpect like script of paired 'expect', 'response' strings.
outputA FILE pointer to a tempfile() for output from the last command.

This is a very simple expect-like implementation for querying and operating daemons remotely over telnet.

The script is a query-response type of list of strings leading up to a final command, which output is then written to the given output file.

Returns
POSIX OK(0), or non-zero with errno set on error.

◆ tempfile()

FILE int FILE* tempfile ( void  )

A secure tmpfile() replacement.

This is the secure replacement for tmpfile() that does not exist in GLIBC. It uses the Linux specific O_TMPFILE and O_EXCL to hide the filename. When the FILE is fclose()'ed, the file contents is lost. The file is hidden in the _PATH_TMP ("/tmp") directory in the system.

This function requires Linux 3.11, or later, due to O_TMPFILE. Not all file systems support hidden inodes, in which case this function defaults to call tmpfile() as a fallback.

Returns
An open FILE pointer, or NULL on error.

◆ vfopenf()

FILE* vfopenf ( const char *  mode,
const char *  fmt,
va_list  ap 
)

Similar to fopenf() except it takes a va_list argument.

Parameters
modeAn fopen() mode string, e.g. "w+".
fmtFormatted string to be composed into a pathname.
apList of variable arguemnts from va_start().

See fopenf() for details.

Returns
a FILE pointer, or NULL on error.

◆ vreadsnf()

int char* vreadsnf ( char *  line,
size_t  len,
const char *  fmt,
va_list  ap 
)

Similar to readsnf() except it takes a va_list argument.

Parameters
linePointer to line buffer.
lenSize of line buffer.
fmtFormatted string to be composed into a pathname.
apList of variable arguemnts from va_start().

For details, see readsnf().

Returns
same as readsnf().

◆ which()

int int char* which ( const char *  cmd)

Like which(1), or command -v foo

Parameters
cmdCommand to look for in $PATH
Returns
A malloc()'ed path to cmd on success, or NULL.

◆ whichp()

int whichp ( const char *  cmd)

Predicate variant of which()

Parameters
cmdCommand to look for in $PATH
Returns
TRUE(1) or FALSE(0) if cmd exists in $PATH.

◆ writedf()

int writedf ( int  value,
const char *  mode,
const char *  fmt,
  ... 
)

Write integer value to a file composed from fmt and optional args.

Parameters
valueInteger value to write.
modeAn fopen() mode string, e.g. "w+".
fmtFormatted string to be composed into a pathname.
Returns
result of operation, with errno set on error.

◆ writellf()

int writellf ( long long  value,
const char *  mode,
const char *  fmt,
  ... 
)

Write 64-bit integer value to a file composed from fmt and optional args.

Parameters
value64-bit integer value to write.
modeAn fopen() mode string, e.g. "w+".
fmtFormatted string to be composed into a pathname.
Returns
result of operation, with errno set on error.

◆ writesf()

int writesf ( const char *  str,
const char *  mode,
const char *  fmt,
  ... 
)

Write a string buffer to a file composed from fmt and optional args.

Parameters
strPointer to string buffer, may be multiple lines.
modeAn fopen() mode string, e.g. "w+".
fmtFormatted string to be composed into a pathname.
Returns
result of operation, with errno set on error.