mirror of
https://github.com/troglobit/libite.git
synced 2026-10-16 10:39:30 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1b3b76ea3 | ||
|
|
8108b8ec14 | ||
|
|
0e2d365eb9 | ||
|
|
8b499aa9cd | ||
|
|
f4fa44fe60 | ||
|
|
be08bcd09d | ||
|
|
1495a3f858 | ||
|
|
5eb816b4c0 | ||
|
|
456c58d52d | ||
|
|
59869b876e | ||
|
|
113c3487bd | ||
|
|
de73e268d3 | ||
|
|
b57c257f09 | ||
|
|
94d42b3df7 | ||
|
|
94ad65a121 | ||
|
|
f3f6947604 | ||
|
|
613d397161 |
No files matched your search
+16
-1
@@ -3,6 +3,19 @@ Change Log
|
|||||||
|
|
||||||
All notable changes to the project are documented in this file.
|
All notable changes to the project are documented in this file.
|
||||||
|
|
||||||
|
[v1.7.0][] - 2016-06-05
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
- Add support for GNU `strdupa()`, for [Inadyn][] on NetBSD.
|
||||||
|
- Add support for GNU `strndupa()` and `strnlen()`
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
|
||||||
|
- Fix `mkpath()` to handle creating relative directories.
|
||||||
|
|
||||||
|
|
||||||
[v1.6.0][] - 2016-05-13
|
[v1.6.0][] - 2016-05-13
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
@@ -164,7 +177,8 @@ problems this may cause!
|
|||||||
Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
|
Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
|
||||||
|
|
||||||
|
|
||||||
[UNRELEASED]: https://github.com/troglobit/libite/compare/v1.6.0...HEAD
|
[UNRELEASED]: https://github.com/troglobit/libite/compare/v1.7.0...HEAD
|
||||||
|
[v1.7.0]: https://github.com/troglobit/libite/compare/v1.6.0...v1.7.0
|
||||||
[v1.6.0]: https://github.com/troglobit/libite/compare/v1.5.1...v1.6.0
|
[v1.6.0]: https://github.com/troglobit/libite/compare/v1.5.1...v1.6.0
|
||||||
[v1.5.1]: https://github.com/troglobit/libite/compare/v1.5.0...v1.5.1
|
[v1.5.1]: https://github.com/troglobit/libite/compare/v1.5.0...v1.5.1
|
||||||
[v1.5.0]: https://github.com/troglobit/libite/compare/v1.4.4...v1.5.0
|
[v1.5.0]: https://github.com/troglobit/libite/compare/v1.4.4...v1.5.0
|
||||||
@@ -179,6 +193,7 @@ Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
|
|||||||
[v1.1.0]: https://github.com/troglobit/libite/compare/v1.0.0...v1.1.0
|
[v1.1.0]: https://github.com/troglobit/libite/compare/v1.0.0...v1.1.0
|
||||||
[v1.0.0]: https://github.com/troglobit/libite/compare/TAIL...v1.0.0
|
[v1.0.0]: https://github.com/troglobit/libite/compare/TAIL...v1.0.0
|
||||||
[Finit]: https://github.com/troglobit/finit/
|
[Finit]: https://github.com/troglobit/finit/
|
||||||
|
[Inadyn]: https://github.com/troglobit/inadyn/
|
||||||
[Mg]: https://github.com/troglobit/mg
|
[Mg]: https://github.com/troglobit/mg
|
||||||
[README]: https://github.com/troglobit/libite/blob/v1.0.0/README.md
|
[README]: https://github.com/troglobit/libite/blob/v1.0.0/README.md
|
||||||
|
|
||||||
|
|||||||
+84
@@ -0,0 +1,84 @@
|
|||||||
|
Maintenance and Release Checklist
|
||||||
|
=================================
|
||||||
|
|
||||||
|
Maintenance
|
||||||
|
-----------
|
||||||
|
|
||||||
|
* Leverage GitHub issues for milestone planning
|
||||||
|
* Reference issues from GitHub pull requests to alert issue subscribers
|
||||||
|
* Bump library ABI version just before release!
|
||||||
|
|
||||||
|
|
||||||
|
Release Checklist
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
* Update ChangeLog, follow http://keepachangelog.com/ loosely
|
||||||
|
- Inform users in a plain language of changes and bug fixes
|
||||||
|
- Do *not* copy-paste GIT commit logs!
|
||||||
|
- Order entrys according to importance, most relevant first
|
||||||
|
* Do we need to bump the ABI version? (Probably, see below)
|
||||||
|
* Tag
|
||||||
|
* Push last commit(s) *and* tags to GitHub
|
||||||
|
* Make release
|
||||||
|
|
||||||
|
make distclean
|
||||||
|
./autogen.sh
|
||||||
|
./configure
|
||||||
|
make release
|
||||||
|
|
||||||
|
* Create new release in GitHub releases page
|
||||||
|
* Copy and paste ChangeLog entry, check any stale links!
|
||||||
|
* Upload release tarball and MD5 files
|
||||||
|
|
||||||
|
|
||||||
|
Library Versioning
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Libite (-lite) relies on GNU Libtool for building the library. For a
|
||||||
|
user of the library it is important to maintain a clear ABI versioning
|
||||||
|
scheme. This is not the same as the library version, but rather the
|
||||||
|
library "compatibility level".
|
||||||
|
|
||||||
|
The ABI version is specified in `src/Makefile.am` and looks like this:
|
||||||
|
|
||||||
|
libite_la_LDFLAGS = -version-info 0:0:0
|
||||||
|
\ \ `-- age
|
||||||
|
\ `--- revision
|
||||||
|
`---- current
|
||||||
|
|
||||||
|
It must be updated according to the [GNU Libtool recommendations][1]:
|
||||||
|
|
||||||
|
1. Start with version information of `0:0:0` for each libtool library.
|
||||||
|
2. Update the version information only immediately before a public
|
||||||
|
release of your software. More frequent updates are unnecessary, and
|
||||||
|
only guarantee that the current interface number gets larger faster.
|
||||||
|
3. If the library *source code has changed at all* since the last update,
|
||||||
|
then increment revision (`c:r:a` becomes `c:r+1:a`).
|
||||||
|
4. If any *interfaces have been added, removed, or changed* since the
|
||||||
|
last update, increment current, and set revision to 0.
|
||||||
|
5. If any *interfaces have been added* since the last public release,
|
||||||
|
then increment age.
|
||||||
|
6. If any *interfaces have been removed or changed* since the last
|
||||||
|
public release, then set age to 0.
|
||||||
|
|
||||||
|
Usually, non-developers have no interest in running development versions
|
||||||
|
(releases are frequent enough), and developers are expected to know how
|
||||||
|
to juggle versions. In such an ideal world, it is good enough to bump
|
||||||
|
the library version just prior to a release, point 2.
|
||||||
|
|
||||||
|
However, if releases are few and far between, distributors may start to
|
||||||
|
use snapshots. When a distributor uses a snapshot, the distributor has
|
||||||
|
to handle the library version manually. Things can get ugly when the
|
||||||
|
distributor has released an intermediate version with a bumped library
|
||||||
|
version, and when the official release is bumped to that version, the
|
||||||
|
distributor will then have to bump the library version for the official
|
||||||
|
release, and it can be confusing if someone reports bugs on versions
|
||||||
|
that you didn't even know existed.
|
||||||
|
|
||||||
|
The problem with bumping the version with every change is that if your
|
||||||
|
interface is not finished, the version number might run away, and it
|
||||||
|
looks pretty bad if a library is at version 262. It kind of tells the
|
||||||
|
user that the library interface is volatile, which is not good for
|
||||||
|
business.
|
||||||
|
|
||||||
|
[1]: https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
|
||||||
+2
-2
@@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I m4
|
|||||||
|
|
||||||
lib_LTLIBRARIES = libite.la
|
lib_LTLIBRARIES = libite.la
|
||||||
pkgincludedir = $(includedir)/lite
|
pkgincludedir = $(includedir)/lite
|
||||||
pkginclude_HEADERS = lite.h queue.h conio.h tree.h
|
pkginclude_HEADERS = lite.h queue.h conio.h tree.h strlite.h strdupa.h strndupa.h strnlen.h
|
||||||
libite_la_SOURCES = chomp.c copyfile.c dir.c fexist.c fisdir.c fmode.c fparseln.c \
|
libite_la_SOURCES = chomp.c copyfile.c dir.c fexist.c fisdir.c fmode.c fparseln.c \
|
||||||
fsendfile.c ifconfig.c lfile.c makepath.c pidfile.c pidfilefn.c \
|
fsendfile.c ifconfig.c lfile.c makepath.c pidfile.c pidfilefn.c \
|
||||||
progress.c reallocarray.c rsync.c strlcpy.c strlcat.c strtonum.c \
|
progress.c reallocarray.c rsync.c strlcpy.c strlcat.c strtonum.c \
|
||||||
@@ -10,7 +10,7 @@ libite_la_SOURCES = chomp.c copyfile.c dir.c fexist.c fisdir.c fmode.c fparsel
|
|||||||
|
|
||||||
libite_la_CPPFLAGS = -D_GNU_SOURCE
|
libite_la_CPPFLAGS = -D_GNU_SOURCE
|
||||||
libite_la_CFLAGS = -W -Wall -Wextra
|
libite_la_CFLAGS = -W -Wall -Wextra
|
||||||
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 2:2:0
|
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 2:3:0
|
||||||
|
|
||||||
pkgconfigdir = $(libdir)/pkgconfig
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
pkgconfig_DATA = libite.pc
|
pkgconfig_DATA = libite.pc
|
||||||
|
|||||||
@@ -282,6 +282,25 @@ Generic Functions
|
|||||||
set. The `path` argument should be a directory.
|
set. The `path` argument should be a directory.
|
||||||
|
|
||||||
|
|
||||||
|
GNU Functions
|
||||||
|
-------------
|
||||||
|
|
||||||
|
The following are useful GNU functions, that do not exist on *BSD, and
|
||||||
|
some other platforms.
|
||||||
|
|
||||||
|
- `strdupa(str)`
|
||||||
|
|
||||||
|
http://man7.org/linux/man-pages/man3/strdupa.3.html
|
||||||
|
|
||||||
|
- `strndupa(str)`
|
||||||
|
|
||||||
|
http://man7.org/linux/man-pages/man3/strndupa.3.html
|
||||||
|
|
||||||
|
- `strnlen(str, lim)`
|
||||||
|
|
||||||
|
http://man7.org/linux/man-pages/man3/strnlen.3.html
|
||||||
|
|
||||||
|
|
||||||
OpenBSD/NetBSD/FreeBSD Functions
|
OpenBSD/NetBSD/FreeBSD Functions
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
|
||||||
@@ -331,14 +350,19 @@ The following are popular functions and highly useful macros from the
|
|||||||
Build & Install
|
Build & Install
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
The library is built for and developed on GNU/Linux systems as a light
|
This library was initially built for and developed on GNU/Linux systems
|
||||||
weight utility library. Libite (LITE) employs the de facto standard GNU
|
as a light weight utility library, these days NetBSD should also work.
|
||||||
configure and build system:
|
Libite (LITE) employs the de facto standard GNU configure and build
|
||||||
|
system:
|
||||||
|
|
||||||
./configure
|
./configure
|
||||||
make -j5
|
make -j5
|
||||||
make install-strip
|
make install-strip
|
||||||
|
|
||||||
|
**Note:** When checking code from GitHub, use <kbd>./autogen.sh</kbd> to
|
||||||
|
generate a `configure` script. It is a generated file and otherwise only
|
||||||
|
included in released tarballs.
|
||||||
|
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
----
|
----
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
AC_INIT(libite, 1.6.0, https://github.com/troglobit/libite/issues)
|
AC_INIT(libite, 1.7.0, https://github.com/troglobit/libite/issues)
|
||||||
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz])
|
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz])
|
||||||
AM_SILENT_RULES([yes])
|
AM_SILENT_RULES([yes])
|
||||||
|
|
||||||
|
|||||||
@@ -28,11 +28,11 @@
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, INT32_MAX, etc. */
|
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, INT32_MAX, etc. */
|
||||||
#include <string.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
|
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "strlite.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fparseln() specific operation flags.
|
* fparseln() specific operation flags.
|
||||||
@@ -80,16 +80,6 @@ pid_t pidfile_poll (const char *pidfile);
|
|||||||
|
|
||||||
void *reallocarray(void *optr, size_t nmemb, size_t size);
|
void *reallocarray(void *optr, size_t nmemb, size_t size);
|
||||||
|
|
||||||
#ifndef strlcpy
|
|
||||||
size_t strlcpy (char *dst, const char *src, size_t siz);
|
|
||||||
#endif
|
|
||||||
#ifndef strlcat
|
|
||||||
size_t strlcat (char *dst, const char *src, size_t siz);
|
|
||||||
#endif
|
|
||||||
#ifndef strtonum
|
|
||||||
long long strtonum (const char *numstr, long long minval, long long maxval, const char **errstrp);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int tree(char *path, int show_perms);
|
int tree(char *path, int show_perms);
|
||||||
|
|
||||||
#ifndef touch
|
#ifndef touch
|
||||||
@@ -154,63 +144,6 @@ static inline int fisslashdir(char *dir)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert string to natural number (0-2147483647), returns -1 on error. */
|
|
||||||
static inline int atonum(const char *str)
|
|
||||||
{
|
|
||||||
int val = -1;
|
|
||||||
const char *errstr;
|
|
||||||
|
|
||||||
if (str) {
|
|
||||||
val = strtonum(str, 0, INT32_MAX, &errstr);
|
|
||||||
if (errstr)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Validate string, non NULL and not zero length */
|
|
||||||
static inline int string_valid(const char *s)
|
|
||||||
{
|
|
||||||
return s && strlen(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Relaxed comparison, e.g., sys_string_match("small", "smaller") => TRUE */
|
|
||||||
static inline int string_match(const char *a, const char *b)
|
|
||||||
{
|
|
||||||
size_t min = MIN(strlen(a), strlen(b));
|
|
||||||
|
|
||||||
return !strncasecmp(a, b, min);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Strict comparison, e.g., sys_string_match("small", "smaller") => FALSE */
|
|
||||||
static inline int string_compare (const char *a, const char *b)
|
|
||||||
{
|
|
||||||
return strlen(a) == strlen(b) && !strcmp(a, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Strict comparison, like sys_string_compare(), but case insensitive,
|
|
||||||
* e.g., sys_string_match("small", "SmAlL") => TRUE
|
|
||||||
*/
|
|
||||||
static inline int string_case_compare (const char *a, const char *b)
|
|
||||||
{
|
|
||||||
return strlen (a) == strlen (b) && !strcasecmp (a, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define min(a,b) \
|
|
||||||
({ \
|
|
||||||
__typeof__ (a) _a = (a); \
|
|
||||||
__typeof__ (b) _b = (b); \
|
|
||||||
_a < _b ? _a : _b; \
|
|
||||||
})
|
|
||||||
|
|
||||||
#define max(a,b) \
|
|
||||||
({ \
|
|
||||||
__typeof__ (a) _a = (a); \
|
|
||||||
__typeof__ (b) _b = (b); \
|
|
||||||
_a > _b ? _a : _b; \
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Compat */
|
/* Compat */
|
||||||
#define copy_filep(src,dst) fcopyfile(src,dst)
|
#define copy_filep(src,dst) fcopyfile(src,dst)
|
||||||
#define pidfile_read_pid(file) pifile_read(file)
|
#define pidfile_read_pid(file) pifile_read(file)
|
||||||
|
|||||||
+4
-1
@@ -25,12 +25,14 @@
|
|||||||
|
|
||||||
int mkpath(char *dir, mode_t mode)
|
int mkpath(char *dir, mode_t mode)
|
||||||
{
|
{
|
||||||
|
struct stat sb;
|
||||||
|
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(dir) == 1 && dir[0] == '/')
|
if (!stat(dir, &sb))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
mkpath(dirname(strdupa(dir)), mode);
|
mkpath(dirname(strdupa(dir)), mode);
|
||||||
@@ -96,6 +98,7 @@ int main(void)
|
|||||||
"/tmp/a/",
|
"/tmp/a/",
|
||||||
"/tmp/a/b",
|
"/tmp/a/b",
|
||||||
"/tmp/a/c/",
|
"/tmp/a/c/",
|
||||||
|
"../../sometestdir/arpa/inet",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,12 @@
|
|||||||
.PHONY: all clean distclean
|
|
||||||
|
|
||||||
# Figure out root of library, unless used as submodule
|
|
||||||
ROOTDIR ?= $(shell pwd)
|
|
||||||
|
|
||||||
CC ?= $(CROSS)gcc
|
|
||||||
AR ?= $(CROSS)ar
|
|
||||||
STRIP ?= $(CROSS)strip
|
|
||||||
INSTALL := install --backup=off
|
|
||||||
STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755
|
|
||||||
CFLAGS += -g -O0
|
CFLAGS += -g -O0
|
||||||
CPPFLAGS += -D_GNU_SOURCE
|
CPPFLAGS += -D_GNU_SOURCE
|
||||||
ARFLAGS = crus
|
|
||||||
|
|
||||||
# Default to silent build, use V=1 to get verbose mode.
|
|
||||||
ifeq ($V,1)
|
ifeq ($V,1)
|
||||||
Q =
|
|
||||||
PRINT = @true
|
|
||||||
REDIRECT =
|
|
||||||
MAKEFLAGS =
|
|
||||||
VERBOSE = -v
|
VERBOSE = -v
|
||||||
|
REDIRECT =
|
||||||
else
|
else
|
||||||
Q = @
|
|
||||||
PRINT = @printf
|
|
||||||
REDIRECT = >/dev/null
|
|
||||||
MAKEFLAGS = --no-print-directory --silent
|
|
||||||
VERBOSE =
|
VERBOSE =
|
||||||
|
REDIRECT = >/dev/null
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Some tests may need to be run as root, e.g. pidfile()
|
# Some tests may need to be run as root, e.g. pidfile()
|
||||||
@@ -34,35 +16,15 @@ else
|
|||||||
SUDO =
|
SUDO =
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Default install paths
|
all: $(TARGET)
|
||||||
prefix ?= /usr/local
|
|
||||||
libdir ?= $(prefix)/lib
|
|
||||||
datadir ?= $(prefix)/share/doc/$(LIBNAME)
|
|
||||||
incdir ?= $(prefix)/include
|
|
||||||
|
|
||||||
# Pretty printing and GCC -M for auto dep files
|
|
||||||
%.o: %.c
|
|
||||||
$(PRINT) " CC $(subst $(ROOTDIR)/,,$(shell pwd)/)$@\n"
|
|
||||||
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -c -MMD -MP -o $@ $<
|
|
||||||
|
|
||||||
%: %.o
|
|
||||||
$(PRINT) " LINK $(subst $(ROOTDIR)/,,$(shell pwd)/)$@\n"
|
|
||||||
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-Map,$@.map -o $@ $^ $(LDLIBS$(LDLIBS-$(@)))
|
|
||||||
|
|
||||||
.PHONY: %.test
|
|
||||||
%.test: %.c
|
%.test: %.c
|
||||||
$(PRINT) " TEST $(subst $(ROOTDIR)/,,$(shell pwd)/)$(@:.test=)\n"
|
@printf " TEST $@\n"
|
||||||
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -g -o $@ -DUNITTEST $< $(OBJS)
|
@$(CC) $(CFLAGS) $(CPPFLAGS) -g -o $@ -DUNITTEST $< $(OBJS)
|
||||||
$(Q)$(RM) $(OBJS)
|
@$(RM) $(OBJS)
|
||||||
$(Q)$(SUDO) ./$@ $(VERBOSE) $(REDIRECT)
|
@$(SUDO) ./$@ $(VERBOSE) $(REDIRECT)
|
||||||
|
|
||||||
|
|
||||||
# Default build rules for both main and unit test makefiles
|
|
||||||
all:: $(TARGET)
|
|
||||||
|
|
||||||
clean::
|
clean::
|
||||||
-$(Q)$(RM) $(OBJS) $(DEPS) $(TARGET) $(SOLIB) $(STATICLIB)
|
-@$(RM) $(OBJS) $(DEPS) $(TARGET) $(SOLIB) $(STATICLIB)
|
||||||
|
-@$(RM) $(JUNK) unittest *.o *.a *.so* *.unittest *.test
|
||||||
distclean::
|
|
||||||
-$(Q)$(RM) $(JUNK) unittest *.o *.a *.so* *.unittest *.test
|
|
||||||
|
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/* ==========================================================================
|
||||||
|
* strdupa.h - Re-implementation of glibc strdupa.
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Copyright (c) 2009 William Ahern
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||||
|
* persons to whom the Software is furnished to do so, subject to the
|
||||||
|
* following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included
|
||||||
|
* in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||||
|
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||||
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
* ==========================================================================
|
||||||
|
*/
|
||||||
|
#ifndef GNU_STRING_STRDUPA_H
|
||||||
|
#define GNU_STRING_STRDUPA_H
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(HAVE_STRDUPA)
|
||||||
|
#if defined(strdupa)
|
||||||
|
#define HAVE_STRDUPA 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if !HAVE_STRDUPA
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#include <stddef.h> /* size_t */
|
||||||
|
#include <string.h> /* memcpy(3) strlen(3) */
|
||||||
|
|
||||||
|
#define strdupa(src) (__extension__ ({ \
|
||||||
|
size_t len_ = strlen(src); \
|
||||||
|
char *dst_ = __builtin_alloca(len_ + 1); \
|
||||||
|
dst_[len_] = '\0'; \
|
||||||
|
(char *)memcpy(dst_, src, len_); \
|
||||||
|
}))
|
||||||
|
|
||||||
|
#else /* If not GCC, e.g. Clang */
|
||||||
|
#error strdupa() may use an unsupported GNU C API, please forward any fix to maintainer, cheers!
|
||||||
|
#endif /* __GNUC__ */
|
||||||
|
#endif /* !HAVE_STRDUPA */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* GNU_STRING_STRDUPA_H */
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/* Collection of frog DNA
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LITE_STRING_H_
|
||||||
|
#define LITE_STRING_H_
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "strdupa.h"
|
||||||
|
#include "strndupa.h"
|
||||||
|
#include "strnlen.h"
|
||||||
|
|
||||||
|
#ifndef strlcpy
|
||||||
|
size_t strlcpy (char *dst, const char *src, size_t siz);
|
||||||
|
#endif
|
||||||
|
#ifndef strlcat
|
||||||
|
size_t strlcat (char *dst, const char *src, size_t siz);
|
||||||
|
#endif
|
||||||
|
#ifndef strtonum
|
||||||
|
long long strtonum (const char *numstr, long long minval, long long maxval, const char **errstrp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Convert string to natural number (0-2147483647), returns -1 on error. */
|
||||||
|
static inline int atonum(const char *str)
|
||||||
|
{
|
||||||
|
int val = -1;
|
||||||
|
const char *errstr;
|
||||||
|
|
||||||
|
if (str) {
|
||||||
|
val = strtonum(str, 0, INT32_MAX, &errstr);
|
||||||
|
if (errstr)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Validate string, non NULL and not zero length */
|
||||||
|
static inline int string_valid(const char *s)
|
||||||
|
{
|
||||||
|
return s && strlen(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Relaxed comparison, e.g., sys_string_match("small", "smaller") => TRUE */
|
||||||
|
static inline int string_match(const char *a, const char *b)
|
||||||
|
{
|
||||||
|
size_t min = MIN(strlen(a), strlen(b));
|
||||||
|
|
||||||
|
return !strncasecmp(a, b, min);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Strict comparison, e.g., sys_string_match("small", "smaller") => FALSE */
|
||||||
|
static inline int string_compare(const char *a, const char *b)
|
||||||
|
{
|
||||||
|
return strlen(a) == strlen(b) && !strcmp(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Strict comparison, like sys_string_compare(), but case insensitive,
|
||||||
|
* e.g., sys_string_match("small", "SmAlL") => TRUE
|
||||||
|
*/
|
||||||
|
static inline int string_case_compare(const char *a, const char *b)
|
||||||
|
{
|
||||||
|
return strlen (a) == strlen (b) && !strcasecmp (a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define min(a,b) \
|
||||||
|
({ \
|
||||||
|
__typeof__ (a) _a = (a); \
|
||||||
|
__typeof__ (b) _b = (b); \
|
||||||
|
_a < _b ? _a : _b; \
|
||||||
|
})
|
||||||
|
|
||||||
|
#define max(a,b) \
|
||||||
|
({ \
|
||||||
|
__typeof__ (a) _a = (a); \
|
||||||
|
__typeof__ (b) _b = (b); \
|
||||||
|
_a > _b ? _a : _b; \
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* LITE_STRING_H_ */
|
||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
/* ==========================================================================
|
||||||
|
* strndupa.h - Re-implementation of glibc strndupa.
|
||||||
|
* --------------------------------------------------------------------------
|
||||||
|
* Copyright (c) 2009 William Ahern
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||||
|
* persons to whom the Software is furnished to do so, subject to the
|
||||||
|
* following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included
|
||||||
|
* in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||||
|
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||||
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
* ==========================================================================
|
||||||
|
*/
|
||||||
|
#ifndef GNU_STRING_STRNDUPA_H
|
||||||
|
#define GNU_STRING_STRNDUPA_H
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(HAVE_STRNDUPA)
|
||||||
|
#if defined(strndupa)
|
||||||
|
#define HAVE_STRNDUPA 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if !HAVE_STRNDUPA
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#include <stddef.h> /* size_t */
|
||||||
|
|
||||||
|
#include <string.h> /* memcpy(3) */
|
||||||
|
|
||||||
|
#include <gnu/string/strnlen.h>
|
||||||
|
|
||||||
|
#define strndupa(src, lim) (__extension__ ({ \
|
||||||
|
size_t len_ = strnlen(src, lim); \
|
||||||
|
char *dst_ = __builtin_alloca(len_ + 1); \
|
||||||
|
dst_[len_] = '\0'; \
|
||||||
|
(char *)memcpy(dst_, src, len_); \
|
||||||
|
}))
|
||||||
|
|
||||||
|
#else /* If not GCC, e.g. Clang */
|
||||||
|
+#error strndupa() may use an unsupported GNU C API, please forward any fix to maintainer, cheers!
|
||||||
|
#endif /* __GNUC__ */
|
||||||
|
#endif /* !HAVE_STRNDUPA */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* GNU_STRING_STRNDUPA_H */
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/* strnlen.h - Re-implementation of GLIBC strnlen()
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LITE_STRNLEN_H
|
||||||
|
#define LITE_STRNLEN_H
|
||||||
|
|
||||||
|
#if !defined(HAVE_STRNLEN)
|
||||||
|
#if defined(strnlen)
|
||||||
|
#define HAVE_STRNLEN 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if !HAVE_STRNLEN
|
||||||
|
#include <stddef.h> /* size_t */
|
||||||
|
|
||||||
|
#define strnlen(str, lim) xstrnlen(str, lim)
|
||||||
|
|
||||||
|
static inline size_t xstrnlen(const char *str, size_t lim)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
while (str[i] && i < lim)
|
||||||
|
i++;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* LITE_STRNLEN_H */
|
||||||
+2
-11
@@ -17,17 +17,9 @@
|
|||||||
|
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <fcntl.h> /* O_TMPFILE requires -D_GNU_SOURCE */
|
#include <fcntl.h> /* O_TMPFILE requires -D_GNU_SOURCE */
|
||||||
#include <linux/version.h>
|
|
||||||
#include <stdlib.h> /* mkstemp() */
|
|
||||||
#include <stdio.h> /* fdopen() */
|
#include <stdio.h> /* fdopen() */
|
||||||
#include <sys/stat.h> /* umask() */
|
#include <sys/stat.h> /* umask() */
|
||||||
|
|
||||||
#ifndef O_TMPFILE /* Too old GLIBC or kernel */
|
|
||||||
#warning O_TMPFILE missing on your system, tempfile() may not work!
|
|
||||||
#define __O_TMPFILE 020000000
|
|
||||||
#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY) /* Define and let it fail at runtime */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tempfile - A secure tmpfile() replacement
|
* tempfile - A secure tmpfile() replacement
|
||||||
*
|
*
|
||||||
@@ -43,7 +35,7 @@
|
|||||||
*/
|
*/
|
||||||
FILE *tempfile(void)
|
FILE *tempfile(void)
|
||||||
{
|
{
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)
|
#ifdef O_TMPFILE /* Only on Linux, with fairly recent (G)LIBC */
|
||||||
int fd;
|
int fd;
|
||||||
mode_t oldmask;
|
mode_t oldmask;
|
||||||
|
|
||||||
@@ -55,8 +47,7 @@ FILE *tempfile(void)
|
|||||||
|
|
||||||
return fdopen(fd, "rw");
|
return fdopen(fd, "rw");
|
||||||
#else
|
#else
|
||||||
#warning Too old kernel, reverting to wrap unsafe tmpfile() ...
|
return tmpfile(); /* Fallback on older GLIBC/Linux and actual UNIX systems */
|
||||||
return tmpfile();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user