libite 2.6.1
lite.h File Reference
#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>

Go to the source code of this file.

Macros

#define LIBITE_LITE_H_
 
#define FPARSELN_UNESCESC   0x01
 
#define FPARSELN_UNESCCONT   0x02
 
#define FPARSELN_UNESCCOMM   0x04
 
#define FPARSELN_UNESCREST   0x08
 
#define FPARSELN_UNESCALL   0x0f
 
#define LITE_FOPT_RSYNC_DELETE   0x01
 
#define LITE_FOPT_COPYFILE_SYM   0x01
 
#define LITE_FOPT_KEEP_MTIME   0x02
 
#define chardev(x, m, maj, min)
 
#define blkdev(x, m, maj, min)
 
#define S_ISEXEC(m)
 
#define ISCLR(word, bit)
 
#define ISSET(word, bit)
 
#define ISOTHER(word, bit)
 
#define SETBIT(word, bit)
 
#define CLRBIT(word, bit)
 
#define NELEMS(array)
 
#define copy_filep(src, dst)
 
#define pidfile_read_pid(file)
 
#define signal_pidfile(file, signo)
 

Typedefs

typedef struct sdbuf sdbuf_t
 

Functions

char * chomp (char *str)
 
int erasef (const char *fmt,...) __attribute__((format(printf
 
int char * fparseln (FILE *, size_t *, size_t *, const char[3], int)
 
int fexist (const char *file)
 
int fexistf (const char *fmt,...) __attribute__((format(printf
 
int int fisdir (const char *path)
 
FILE * vfopenf (const char *mode, const char *fmt, va_list ap)
 
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)
 
ssize_t copyfile (const char *src, const char *dst, int len, int opt)
 
int movefile (const char *src, const char *dst)
 
int fcopyfile (FILE *src, FILE *dst)
 
ssize_t fsendfile (FILE *src, FILE *dst, size_t len)
 
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)
 
char * readsnf (char *line, size_t len, const char *fmt,...)
 
int writesf (const char *str, const char *mode, const char *fmt,...)
 
int vreadllf (long long *value, const char *fmt, va_list ap)
 
int readllf (long long *value, const char *fmt,...)
 
int readdf (int *value, const char *fmt,...)
 
int writellf (long long value, const char *mode, const char *fmt,...)
 
int writedf (int value, const char *mode, const char *fmt,...)
 
int ifconfig (const char *ifname, const char *addr, const char *mask, int up)
 
lfile_t * lfopen (const char *file, const char *sep)
 
void lfclose (lfile_t *lf)
 
char * lftok (lfile_t *lf)
 
char * lfgetkey (lfile_t *lf, const char *key)
 
int lfgetint (lfile_t *lf, const char *key)
 
int fgetint (const char *file, const char *sep, const char *key)
 
int fmkpath (mode_t mode, const char *fmt,...) __attribute__((format(printf
 
int int mkpath (const char *dir, mode_t mode)
 
int makepath (const char *dir)
 
int dir (const char *dir, const char *type, int(*filter)(const char *file), char ***list, int strip)
 
int rsync (char *src, char *dst, int opt, int(*filter)(const char *file))
 
FILE * popenf (const char *type, const char *fmt,...) __attribute__((format(printf
 
FILE int pidfile (const char *basename)
 
int pidfile_signal (const char *pidfile, int signal)
 
pid_t pidfile_read (const char *pidfile)
 
pid_t pidfile_poll (const char *pidfile)
 
void * reallocarray (void *optr, size_t nmemb, size_t size)
 
void progress (int percent, int max_width)
 
void progress_simple (int percent)
 
int runbg (char *const cmd[], int delay)
 
int systemf (const char *fmt,...) __attribute__((format(printf
 
int sdbuf_ttelnet_open (int addr, short port)
 
int telnet_close (sdbuf_t *ctx)
 
int telnet_expect (sdbuf_t *ctx, char *script[], FILE *output)
 
int telnet_session (int addr, short port, char *script[], FILE *output)
 
int touchf (const char *fmt,...) __attribute__((format(printf
 
int int yorn (const char *fmt,...) __attribute__((format(printf
 
int int char * which (const char *cmd)
 
int whichp (const char *cmd)
 

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/

Definition in file lite.h.

Macro Definition Documentation

◆ blkdev

#define blkdev ( x,
m,
maj,
min )
Value:
mknod((x), S_IFBLK|(m), makedev((maj),(min)))
#define min(a, b)
Definition strlite.h:49

Definition at line 218 of file lite.h.

◆ chardev

#define chardev ( x,
m,
maj,
min )
Value:
mknod((x), S_IFCHR|(m), makedev((maj),(min)))

Definition at line 215 of file lite.h.

◆ CLRBIT

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

Clear bit in word.

Definition at line 239 of file lite.h.

◆ copy_filep

#define copy_filep ( src,
dst )
Value:
fcopyfile(src, dst)
int fcopyfile(FILE *src, FILE *dst)
Definition copyfile.c:278

Definition at line 265 of file lite.h.

◆ FPARSELN_UNESCALL

#define FPARSELN_UNESCALL   0x0f

All of the above.

Definition at line 62 of file lite.h.

◆ FPARSELN_UNESCCOMM

#define FPARSELN_UNESCCOMM   0x04

Remove escape preceding an escaped escape.

Definition at line 60 of file lite.h.

◆ FPARSELN_UNESCCONT

#define FPARSELN_UNESCCONT   0x02

Remove escape preceding an escaped continuation.

Definition at line 59 of file lite.h.

◆ FPARSELN_UNESCESC

#define FPARSELN_UNESCESC   0x01

Remove escape preceding an escaped comment.

Definition at line 58 of file lite.h.

◆ FPARSELN_UNESCREST

#define FPARSELN_UNESCREST   0x08

Remove escape preceding any other character.

Definition at line 61 of file lite.h.

◆ ISCLR

#define ISCLR ( word,
bit )
Value:
((word & (1 << (bit)) ? 0 : 1))

Is bit cleared in word?

Definition at line 227 of file lite.h.

◆ ISOTHER

#define ISOTHER ( word,
bit )
Value:
((word & ~(1 << (bit)) ? 1 : 0))

Is any other bit set?

Definition at line 233 of file lite.h.

◆ ISSET

#define ISSET ( word,
bit )
Value:
((word & (1 << (bit)) ? 1 : 0))

Is bit set in word?

Definition at line 230 of file lite.h.

◆ LIBITE_LITE_H_

#define LIBITE_LITE_H_

Definition at line 42 of file lite.h.

◆ LITE_FOPT_COPYFILE_SYM

#define LITE_FOPT_COPYFILE_SYM   0x01

Recreate symlink or follow to copy target

Definition at line 68 of file lite.h.

◆ LITE_FOPT_KEEP_MTIME

#define LITE_FOPT_KEEP_MTIME   0x02

Preserve modification time

Definition at line 69 of file lite.h.

◆ LITE_FOPT_RSYNC_DELETE

#define LITE_FOPT_RSYNC_DELETE   0x01

Prune files from destination that are not in source

Definition at line 67 of file lite.h.

◆ NELEMS

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

Number of elements in array.

Definition at line 244 of file lite.h.

◆ pidfile_read_pid

#define pidfile_read_pid ( file)
Value:
pid_t pidfile_read(const char *pidfile)
Definition pidfilefn.c:49

Definition at line 266 of file lite.h.

◆ S_ISEXEC

#define S_ISEXEC ( m)
Value:
(((m) & S_IXUSR) == S_IXUSR)

Definition at line 222 of file lite.h.

◆ SETBIT

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

Set bit in word.

Definition at line 236 of file lite.h.

◆ signal_pidfile

#define signal_pidfile ( file,
signo )
Value:
pidfile_signal(file, signo)
int pidfile_signal(const char *pidfile, int signal)
Definition pidfilefn.c:114

Definition at line 267 of file lite.h.

Typedef Documentation

◆ sdbuf_t

typedef struct sdbuf sdbuf_t

Opqaue context struct for telnet APIs

Definition at line 72 of file lite.h.

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.

Definition at line 38 of file chomp.c.

◆ 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.

Definition at line 144 of file copyfile.c.

◆ dir()

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.

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.

Definition at line 82 of file dir.c.

◆ 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.

Definition at line 278 of file copyfile.c.

◆ 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).

Definition at line 45 of file fexist.c.

◆ 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.

Definition at line 177 of file lfile.c.

◆ 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).

Definition at line 40 of file fisdir.c.

◆ 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.

Definition at line 94 of file fparseln.c.

◆ 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.

Definition at line 51 of file fsendfile.c.

◆ 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.

Definition at line 53 of file ifconfig.c.

◆ lfclose()

void lfclose ( lfile_t * lf)

Close a parser context.

Parameters
lfPointer to lfile_t parser context from lfopen()

Definition at line 75 of file lfile.c.

◆ 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.

Definition at line 156 of file lfile.c.

◆ 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.

Definition at line 131 of file lfile.c.

◆ 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.

Definition at line 46 of file lfile.c.

◆ 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.

Definition at line 92 of file lfile.c.

◆ 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.

Definition at line 105 of file makepath.c.

◆ 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.

Definition at line 40 of file makepath.c.

◆ 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.

Definition at line 244 of file copyfile.c.

◆ 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.

Definition at line 71 of file pidfile.c.

◆ 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.

Definition at line 89 of file pidfilefn.c.

◆ 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.

Definition at line 49 of file pidfilefn.c.

◆ 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.

Definition at line 114 of file pidfilefn.c.

◆ 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.

Definition at line 66 of file progress.c.

◆ 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

Definition at line 99 of file progress.c.

◆ 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.

Definition at line 154 of file procval.c.

◆ 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.

Definition at line 133 of file procval.c.

◆ 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.

Definition at line 74 of file procval.c.

◆ 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.

Definition at line 44 of file reallocarray.c.

◆ rsync()

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

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.

Definition at line 70 of file rsync.c.

◆ 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.

Definition at line 46 of file runbg.c.

◆ 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).

Definition at line 116 of file telnet.c.

◆ 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.

Definition at line 174 of file telnet.c.

◆ 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.

Definition at line 56 of file telnet.c.

◆ 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.

Definition at line 295 of file telnet.c.

◆ 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.

Definition at line 59 of file tempfile.c.

◆ 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.

Definition at line 40 of file fopenf.c.

◆ vreadllf()

int vreadllf ( long long * value,
const char * fmt,
va_list ap )

Same as readllf() except it takes a va_list argument.

Definition at line 112 of file procval.c.

◆ 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().

Definition at line 44 of file procval.c.

◆ 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.

Definition at line 54 of file which.c.

◆ 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.

Definition at line 122 of file which.c.

◆ 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.

Definition at line 208 of file procval.c.

◆ 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.

Definition at line 184 of file procval.c.

◆ 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.

Definition at line 94 of file procval.c.