sbase/util.h
FRIGN 007df69fc5 Add parseoffset()
This is a utility function to allow easy parsing of file or other
offsets, automatically taking in regard suffixes, proper bases and
so on, for instance used in split(1) -b or od -j, -N(1).
Of course, POSIX is very arbitrary when it comes to defining the
parsing rules for different tools.
The main focus here lies on being as flexible and consistent as
possible. One central utility-function handling the parsing makes
this stuff a lot more trivial.
2015-09-30 19:44:10 +01:00

79 lines
2.2 KiB
C

/* See LICENSE file for copyright and license details. */
#include <sys/types.h>
#include <regex.h>
#include <stddef.h>
#include <stdio.h>
#include "arg.h"
#include "compat.h"
#define UTF8_POINT(c) (((c) & 0xc0) != 0x80)
#undef MIN
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#undef MAX
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#undef LIMIT
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
#define LEN(x) (sizeof (x) / sizeof *(x))
extern char *argv0;
void *ecalloc(size_t, size_t);
void *emalloc(size_t);
void *erealloc(void *, size_t);
#undef reallocarray
void *reallocarray(void *, size_t, size_t);
void *ereallocarray(void *, size_t, size_t);
char *estrdup(const char *);
char *estrndup(const char *, size_t);
void *encalloc(int, size_t, size_t);
void *enmalloc(int, size_t);
void *enrealloc(int, void *, size_t);
char *enstrdup(int, const char *);
char *enstrndup(int, const char *, size_t);
void enfshut(int, FILE *, const char *);
void efshut(FILE *, const char *);
int fshut(FILE *, const char *);
void enprintf(int, const char *, ...);
void eprintf(const char *, ...);
void weprintf(const char *, ...);
double estrtod(const char *);
#undef strcasestr
char *strcasestr(const char *, const char *);
#undef strlcat
size_t strlcat(char *, const char *, size_t);
size_t estrlcat(char *, const char *, size_t);
#undef strlcpy
size_t strlcpy(char *, const char *, size_t);
size_t estrlcpy(char *, const char *, size_t);
#undef strsep
char *strsep(char **, const char *);
/* regex */
int enregcomp(int, regex_t *, const char *, int);
int eregcomp(regex_t *, const char *, int);
/* misc */
void enmasse(int, char **, int (*)(const char *, const char *, int));
void fnck(const char *, const char *, int (*)(const char *, const char *, int), int);
mode_t getumask(void);
char *humansize(off_t);
mode_t parsemode(const char *, mode_t, mode_t);
off_t parseoffset(const char *);
void putword(FILE *, const char *);
#undef strtonum
long long strtonum(const char *, long long, long long, const char **);
long long enstrtonum(int, const char *, long long, long long);
long long estrtonum(const char *, long long, long long);
size_t unescape(char *);
int mkdirp(const char *);