mirror of
https://github.com/troglobit/libite.git
synced 2026-10-14 10:19:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
261cf3a01b | ||
|
|
2c9c13bd07 | ||
|
|
59ce0c0dc4 | ||
|
|
a603208da9 | ||
|
|
eaac01871b | ||
|
|
8cefa12675 | ||
|
|
5893010074 | ||
|
|
d84bcb3847 | ||
|
|
a9a3a2dda1 | ||
|
|
20af39300c | ||
|
|
7b612cda83 | ||
|
|
60406c33f6 | ||
|
|
1d21b11802 | ||
|
|
a3badc85f8 | ||
|
|
ac936448f5 | ||
|
|
3a26ab28b2 | ||
|
|
123108fbf9 | ||
|
|
3545d63d2e | ||
|
|
3e921d72e5 |
No files matched your search
+26
-7
@@ -4,6 +4,30 @@ Change Log
|
||||
All notable changes to the project are documented in this file.
|
||||
|
||||
|
||||
[v2.0.1][] - 2017-12-22
|
||||
-----------------------
|
||||
|
||||
### Changes
|
||||
- Add missing `initscr()` declaration, regression in [v2.0.0][]
|
||||
- Add `#ifdef` guards around `min()` and `max()` macros
|
||||
- Add `const` to `char *` args in multiple API:s:
|
||||
- `fexist()`
|
||||
- `fgetint()`
|
||||
- `fisslashdir()`
|
||||
- `copyfile()`
|
||||
- `movefile()`
|
||||
- `ifconfig()`
|
||||
- `lfopen()`
|
||||
- `lfgetkey()`
|
||||
- `lfgetint()`
|
||||
|
||||
### Fixes
|
||||
- Fix #9, uncommon location of `which` command in unit test
|
||||
- Fix #10, supply unit test with a default `$PATH`
|
||||
- Fix #11, `touch()` command cannot handle relative paths when updating
|
||||
the mtime of an existing file
|
||||
|
||||
|
||||
[v2.0.0][] - 2017-11-22
|
||||
-----------------------
|
||||
|
||||
@@ -292,7 +316,8 @@ problems this may cause!
|
||||
Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
|
||||
|
||||
|
||||
[UNRELEASED]: https://github.com/troglobit/libite/compare/v2.0.0...HEAD
|
||||
[UNRELEASED]: https://github.com/troglobit/libite/compare/v2.0.1...HEAD
|
||||
[v2.0.1]: https://github.com/troglobit/libite/compare/v2.0.0...v2.0.1
|
||||
[v2.0.0]: https://github.com/troglobit/libite/compare/v1.9.3...v2.0.0
|
||||
[v1.9.3]: https://github.com/troglobit/libite/compare/v1.9.2...v1.9.3
|
||||
[v1.9.2]: https://github.com/troglobit/libite/compare/v1.9.1...v1.9.2
|
||||
@@ -320,9 +345,3 @@ Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
|
||||
[Inadyn]: https://github.com/troglobit/inadyn/
|
||||
[Mg]: https://github.com/troglobit/mg
|
||||
[README]: https://github.com/troglobit/libite/blob/v1.0.0/README.md
|
||||
|
||||
<!--
|
||||
-- Local Variables:
|
||||
-- mode: markdown
|
||||
-- End:
|
||||
-->
|
||||
@@ -20,24 +20,19 @@ Table of Contents
|
||||
Introduction
|
||||
------------
|
||||
|
||||
Libite is a lightweight library of *frog DNA*. It can be used to fill
|
||||
Libite is a lightweight library of *frog DNA* that can be used to fill
|
||||
the gaps in any dinosaur project. It holds useful functions and macros
|
||||
developed by both [Finit][1] and the [OpenBSD][2] project. Most notably
|
||||
the string functions: [strlcpy(3)][3], [strlcat(3)][3] and the highly
|
||||
useful *BSD [sys/queue.h][4] and [sys/tree.h][7] API's.
|
||||
|
||||
Libite is the frog DNA missing in GNU libc. However, -lite does not aim
|
||||
to become another [GLIB][5]! One noticeable gap in GLIBC is the missing
|
||||
`_SAFE` macros in the BSD `sys/queue.h` API — highly recommended
|
||||
when traversing lists to delete/free nodes.
|
||||
Libite holds many of the missing pieces in GNU libc, although -lite does
|
||||
not aim to become another [GLIB][5]. One noticeable gap in GLIBC is the
|
||||
`_SAFE` macros available in the BSD `sys/queue.h` API — highly
|
||||
recommended when traversing lists to delete/free nodes.
|
||||
|
||||
The code is open sourced under a mix of the [MIT/X11 license][MIT], the
|
||||
[ISC license][ISC] used by OpenBSD, and [BSD licenses][BSD], all of them
|
||||
are extremely liberal and can be used freely in proprietary software if
|
||||
needed.
|
||||
|
||||
For an introduction to why Libite happened, and how you can use it, see
|
||||
[this blog post][6].
|
||||
The code is open sourced under a mix of permissive Open Source licenses:
|
||||
[MIT/X11 license][MIT], [ISC license][ISC], and [BSD licenses][BSD].
|
||||
|
||||
|
||||
Using -lite
|
||||
@@ -383,8 +378,6 @@ Build & Install
|
||||
|
||||
This library was initially built for and developed on GNU/Linux systems
|
||||
as a light weight utility library, these days NetBSD should also work.
|
||||
Libite (LITE) employs the de facto standard GNU configure and build
|
||||
system:
|
||||
|
||||
./configure
|
||||
make -j5
|
||||
@@ -396,27 +389,14 @@ generate a `configure` script. It is a generated file and otherwise only
|
||||
included in released tarballs.
|
||||
|
||||
|
||||
TODO
|
||||
----
|
||||
|
||||
- Improve documentation, possibly use kdoc or gdoc2 to generate docs from API.
|
||||
- Continuously, update OpenBSD functions/macros.
|
||||
|
||||
[1]: https://github.com/troglobit/finit
|
||||
[2]: http://www.openbsd.org/
|
||||
[3]: http://www.openbsd.org/cgi-bin/man.cgi?query=strlcpy
|
||||
[4]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/LIST_EMPTY.3
|
||||
[5]: https://developer.gnome.org/glib/
|
||||
[6]: http://troglobit.com/blog/2015/07/02/howto-using-lite-with-a-git-based-application/
|
||||
[7]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/SPLAY_FOREACH.3
|
||||
[MIT]: https://en.wikipedia.org/wiki/MIT_License
|
||||
[ISC]: https://en.wikipedia.org/wiki/ISC_license
|
||||
[BSD]: https://en.wikipedia.org/wiki/BSD_licenses
|
||||
[Travis]: https://travis-ci.org/troglobit/libite
|
||||
[Travis Status]: https://travis-ci.org/troglobit/libite.png?branch=master
|
||||
|
||||
<!--
|
||||
-- Local Variables:
|
||||
-- mode: markdown
|
||||
-- End:
|
||||
-->
|
||||
@@ -1,7 +1,8 @@
|
||||
TODO ... in no particular order
|
||||
===============================
|
||||
|
||||
* Improve documentation, possibly use kdoc or gdoc2 to generate docs from API
|
||||
* Continuously, update OpenBSD functions/macros
|
||||
* Investigate adding FreeBSD pidfile_open() et al
|
||||
* Investigate FreeBSD libutil library, could be useful for porting between unices
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
AC_INIT(libite, 2.0.0, https://github.com/troglobit/libite/issues)
|
||||
AC_INIT(libite, 2.0.1, https://github.com/troglobit/libite/issues)
|
||||
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz])
|
||||
AM_SILENT_RULES([yes])
|
||||
|
||||
|
||||
Vendored
+9
@@ -1,3 +1,12 @@
|
||||
libite (2.0.1-1) unstable; urgency=medium
|
||||
|
||||
* New upstream release, v2.0.1, fixes to:
|
||||
- touch(), cannot handle relative paths when updating mtime
|
||||
- unit test for which()
|
||||
- add missing initscr() declaration in conio.h
|
||||
- ifdef guards around min()/max() macros
|
||||
-- Joachim Nilsson <troglobit@gmail.com> Fri, 22 Dec 2017 12:11:41 +0100
|
||||
|
||||
libite (2.0.0-1) unstable; urgency=low
|
||||
|
||||
* New upstream release, v2.0.0, fixes to:
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ lib_LTLIBRARIES = libite.la
|
||||
|
||||
libite_la_CPPFLAGS = -D_GNU_SOURCE
|
||||
libite_la_CFLAGS = -W -Wall -Wextra
|
||||
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 5:0:0
|
||||
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 5:1:0
|
||||
libite_la_SOURCES = chomp.c copyfile.c \
|
||||
conio.c conio.h \
|
||||
dir.c \
|
||||
|
||||
@@ -75,6 +75,8 @@
|
||||
#define textcolor(color) __set_gm(RESETATTR, color, 30)
|
||||
#define textbackground(color) __set_gm(RESETATTR, color, 40)
|
||||
|
||||
void initscr(int *row, int *col);
|
||||
|
||||
/* Print table heading @line to @fp, with optional leading newline */
|
||||
static inline void printheader(FILE *fp, const char *line, int nl)
|
||||
{
|
||||
|
||||
+14
-13
@@ -27,7 +27,7 @@
|
||||
#include "lite.h"
|
||||
|
||||
/* Tests if dst is a directory, if so, reallocates dst and appends src filename returning 1 */
|
||||
static int adjust_target(char *src, char **dst)
|
||||
static int adjust_target(const char *src, char **dst)
|
||||
{
|
||||
int isdir = 0;
|
||||
|
||||
@@ -36,7 +36,7 @@ static int adjust_target(char *src, char **dst)
|
||||
char *tmp, *ptr = strrchr(src, '/');
|
||||
|
||||
if (!ptr)
|
||||
ptr = src;
|
||||
ptr = (char *)src;
|
||||
else
|
||||
ptr++;
|
||||
|
||||
@@ -115,9 +115,9 @@ static void set_mtime(int in, int out)
|
||||
* may also indicate that @src was empty. If @src is a directory @errno
|
||||
* will be set to %EISDIR since copyfile() is not recursive.
|
||||
*/
|
||||
ssize_t copyfile(char *src, char *dst, int len, int opt)
|
||||
ssize_t copyfile(const char *src, const char *dst, int len, int opt)
|
||||
{
|
||||
char *buffer;
|
||||
char *buffer, *dest = (char *)dst;
|
||||
int sym = (opt & LITE_FOPT_COPYFILE_SYM) != 0;
|
||||
int keep_mtim = (opt & LITE_FOPT_KEEP_MTIME) != 0;
|
||||
int in, out, isdir = 0, saved_errno = 0;
|
||||
@@ -137,7 +137,7 @@ ssize_t copyfile(char *src, char *dst, int len, int opt)
|
||||
}
|
||||
|
||||
/* Check if target is a directory, then append src filename. */
|
||||
isdir = adjust_target(src, &dst);
|
||||
isdir = adjust_target(src, &dest);
|
||||
|
||||
/* Check if the source file is a symlink ... */
|
||||
if (stat(src, &st)) {
|
||||
@@ -154,7 +154,7 @@ ssize_t copyfile(char *src, char *dst, int len, int opt)
|
||||
size = -1;
|
||||
} else {
|
||||
buffer[size] = 0;
|
||||
size = !symlink(buffer, dst);
|
||||
size = !symlink(buffer, dest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ ssize_t copyfile(char *src, char *dst, int len, int opt)
|
||||
goto exit;
|
||||
}
|
||||
|
||||
out = open(dst, O_WRONLY | O_CREAT | O_TRUNC, st.st_mode);
|
||||
out = open(dest, O_WRONLY | O_CREAT | O_TRUNC, st.st_mode);
|
||||
if (out < 0) {
|
||||
close(in);
|
||||
saved_errno = errno;
|
||||
@@ -194,7 +194,7 @@ ssize_t copyfile(char *src, char *dst, int len, int opt)
|
||||
exit:
|
||||
free(buffer);
|
||||
if (isdir)
|
||||
free(dst);
|
||||
free(dest);
|
||||
errno = saved_errno;
|
||||
|
||||
return size;
|
||||
@@ -216,17 +216,18 @@ exit:
|
||||
* Returns:
|
||||
* POSIX OK(0), or non-zero with errno set.
|
||||
*/
|
||||
int movefile(char *src, char *dst)
|
||||
int movefile(const char *src, const char *dst)
|
||||
{
|
||||
char *dest = (char *)dst;
|
||||
int isdir, result = 0;
|
||||
|
||||
/* Check if target is a directory, then append the src base filename. */
|
||||
isdir = adjust_target(src, &dst);
|
||||
isdir = adjust_target(src, &dest);
|
||||
|
||||
if (rename(src, dst)) {
|
||||
if (rename(src, dest)) {
|
||||
if (errno == EXDEV) {
|
||||
errno = 0;
|
||||
copyfile(src, dst, 0, 1);
|
||||
copyfile(src, dest, 0, 1);
|
||||
if (errno)
|
||||
result = 1;
|
||||
else
|
||||
@@ -237,7 +238,7 @@ int movefile(char *src, char *dst)
|
||||
}
|
||||
|
||||
if (isdir)
|
||||
free(dst);
|
||||
free(dest);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@
|
||||
* Returns:
|
||||
* %TRUE(1) if the file exists, otherwise %FALSE(0).
|
||||
*/
|
||||
int fexist(char *file)
|
||||
int fexist(const char *file)
|
||||
{
|
||||
if (!file) {
|
||||
errno = EINVAL;
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ extern size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
* Returns:
|
||||
* POSIX OK(0) on success, or non-zero on error.
|
||||
*/
|
||||
int ifconfig(char *ifname, char *addr, char *mask, int up)
|
||||
int ifconfig(const char *ifname, const char *addr, const char *mask, int up)
|
||||
{
|
||||
int sd, ret = -1;
|
||||
struct ifreq ifr;
|
||||
|
||||
+16
-18
@@ -24,7 +24,8 @@
|
||||
typedef struct lfile {
|
||||
FILE *fp;
|
||||
char buf[256];
|
||||
char *sep, *save;
|
||||
char *save;
|
||||
const char *sep;
|
||||
} lfile_t;
|
||||
|
||||
/**
|
||||
@@ -35,7 +36,7 @@ typedef struct lfile {
|
||||
* Returns:
|
||||
* Pointer to a &lftile_t parser context, or %NULL on error.
|
||||
*/
|
||||
lfile_t *lfopen(char *file, char *sep)
|
||||
lfile_t *lfopen(const char *file, const char *sep)
|
||||
{
|
||||
lfile_t *lf;
|
||||
|
||||
@@ -92,23 +93,20 @@ char *lftok(lfile_t *lf)
|
||||
}
|
||||
|
||||
token = strtok_r(NULL, lf->sep, &lf->save);
|
||||
if (!token) {
|
||||
while (fgets(lf->buf, sizeof(lf->buf), lf->fp)) {
|
||||
if (lf->buf[0] == '#')
|
||||
continue;
|
||||
if (token)
|
||||
return token;
|
||||
|
||||
token = strtok_r(lf->buf, lf->sep, &lf->save);
|
||||
if (!token)
|
||||
continue;
|
||||
|
||||
while (fgets(lf->buf, sizeof(lf->buf), lf->fp)) {
|
||||
if (lf->buf[0] == '#')
|
||||
continue;
|
||||
|
||||
token = strtok_r(lf->buf, lf->sep, &lf->save);
|
||||
if (token)
|
||||
return token;
|
||||
}
|
||||
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return token;
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +123,7 @@ char *lftok(lfile_t *lf)
|
||||
* Returns:
|
||||
* The value to @key, or %NULL if not found.
|
||||
*/
|
||||
char *lfgetkey(lfile_t *lf, char *key)
|
||||
char *lfgetkey(lfile_t *lf, const char *key)
|
||||
{
|
||||
char *token;
|
||||
|
||||
@@ -151,7 +149,7 @@ char *lfgetkey(lfile_t *lf, char *key)
|
||||
* Returns:
|
||||
* The positive integer value for @key, or -1 if not found.
|
||||
*/
|
||||
int lfgetint(lfile_t *lf, char *key)
|
||||
int lfgetint(lfile_t *lf, const char *key)
|
||||
{
|
||||
char *token = lfgetkey(lf, key);
|
||||
|
||||
@@ -173,7 +171,7 @@ int lfgetint(lfile_t *lf, char *key)
|
||||
* Returns:
|
||||
* The positive integer value for @key, or -1 if not found.
|
||||
*/
|
||||
int fgetint(char *file, char *sep, char *key)
|
||||
int fgetint(const char *file, const char *sep, const char *key)
|
||||
{
|
||||
int val = -1;
|
||||
lfile_t *lf;
|
||||
|
||||
+11
-10
@@ -26,6 +26,7 @@
|
||||
#define LITE_H_
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h> /* Definition of AT_* constants for utimensat() */
|
||||
#include <stdio.h>
|
||||
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, INT32_MAX, etc. */
|
||||
#include <sys/stat.h>
|
||||
@@ -55,23 +56,23 @@ typedef struct lfile lfile_t;
|
||||
char *chomp (char *str);
|
||||
char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
|
||||
|
||||
int fexist (char *file);
|
||||
int fexist (const char *file);
|
||||
int fisdir (const char *file);
|
||||
|
||||
FILE *tempfile (void);
|
||||
ssize_t copyfile (char *src, char *dst, int len, int opt);
|
||||
int movefile (char *src, char *dst);
|
||||
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 ifconfig (char *ifname, char *addr, char *mask, int up);
|
||||
int ifconfig (const char *ifname, const char *addr, const char *mask, int up);
|
||||
|
||||
lfile_t*lfopen (char *file, char *sep);
|
||||
lfile_t*lfopen (const char *file, const char *sep);
|
||||
void lfclose (lfile_t *lf);
|
||||
char *lftok (lfile_t *lf);
|
||||
char *lfgetkey (lfile_t *lf, char *key);
|
||||
int lfgetint (lfile_t *lf, char *key);
|
||||
int fgetint (char *file, char *sep, char *key);
|
||||
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 mkpath (const char *dir, mode_t mode);
|
||||
int makepath (const char *dir);
|
||||
@@ -99,7 +100,7 @@ static inline int touch(const char *path)
|
||||
{
|
||||
if (mknod((path), S_IFREG|0644, 0)) {
|
||||
if (errno == EEXIST)
|
||||
return utimensat(0, path, NULL, 0);
|
||||
return utimensat(AT_FDCWD, path, NULL, 0);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -164,7 +165,7 @@ static inline int erase(const char *path)
|
||||
#endif
|
||||
|
||||
/* Does directory end with a slash? */
|
||||
static inline int fisslashdir(char *dir)
|
||||
static inline int fisslashdir(const char *dir)
|
||||
{
|
||||
if (!dir)
|
||||
return 0;
|
||||
|
||||
+17
-15
@@ -29,6 +29,23 @@
|
||||
#include "strndupa.h"
|
||||
#include "strnlen.h"
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) \
|
||||
({ \
|
||||
__typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a < _b ? _a : _b; \
|
||||
})
|
||||
#endif
|
||||
#ifndef max
|
||||
#define max(a,b) \
|
||||
({ \
|
||||
__typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a > _b ? _a : _b; \
|
||||
})
|
||||
#endif
|
||||
|
||||
#ifndef strlcpy
|
||||
size_t strlcpy (char *dst, const char *src, size_t siz);
|
||||
#endif
|
||||
@@ -82,19 +99,4 @@ 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_ */
|
||||
+8
-7
@@ -11,16 +11,17 @@ int main(void)
|
||||
int result = 0;
|
||||
size_t i;
|
||||
struct tc test[] = {
|
||||
{ "ls", 1 },
|
||||
{ "free", 1 },
|
||||
{ "modinfo", 1 },
|
||||
{ "useradd", 1 },
|
||||
{ "/bin/which", 1 },
|
||||
{ "/bin/ps aux", 1 },
|
||||
{ "/etc/passwd", 0 },
|
||||
{ "ls", 1 },
|
||||
{ "free", 1 },
|
||||
{ "modinfo", 1 },
|
||||
{ "useradd", 1 },
|
||||
{ "/usr/bin/which", 1 },
|
||||
{ "/bin/ps aux", 1 },
|
||||
{ "/etc/passwd", 0 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
setenv("PATH", "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin", 1);
|
||||
for (i = 0; test[i].cmd; i++) {
|
||||
char *path;
|
||||
|
||||
|
||||
Reference in new issue
Block a user