mirror of
https://github.com/troglobit/libite.git
synced 2026-10-14 10:19:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67529f2283 | ||
|
|
8e69676943 | ||
|
|
76faae4292 | ||
|
|
e928c30fbd | ||
|
|
3512201a58 | ||
|
|
dc5c4ae36c | ||
|
|
748948b665 | ||
|
|
951050fdd2 | ||
|
|
d5c5996f03 | ||
|
|
f5808e557e | ||
|
|
d4b554ccdc | ||
|
|
098a020843 | ||
|
|
2040569f0a | ||
|
|
733a7062e9 | ||
|
|
7ad11a31df | ||
|
|
8ce46eb439 | ||
|
|
c15e883427 |
No files matched your search
+5
-5
@@ -25,15 +25,15 @@ addons:
|
|||||||
name: "troglobit/libite"
|
name: "troglobit/libite"
|
||||||
description: "That missing frog DNA you've been looking for"
|
description: "That missing frog DNA you've been looking for"
|
||||||
notification_email: troglobit@gmail.com
|
notification_email: troglobit@gmail.com
|
||||||
build_command_prepend: "./autogen.sh && ./configure --prefix=/tmp --disable-silent-rules"
|
build_command_prepend: "./autogen.sh && ./configure --prefix= --disable-silent-rules"
|
||||||
build_command: "make clean all"
|
build_command: "make clean all"
|
||||||
branch_pattern: dev
|
branch_pattern: dev
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- ./autogen.sh
|
- ./autogen.sh
|
||||||
- ./configure --prefix=/tmp --disable-silent-rules
|
- ./configure --prefix= --disable-silent-rules
|
||||||
- make clean
|
- make clean
|
||||||
- make -j5
|
- make -j5
|
||||||
- make install-strip
|
- make install-strip DESTDIR=/tmp/foo
|
||||||
- ls -lR /tmp
|
- ls -lR /tmp/foo
|
||||||
- make check
|
- make distcheck
|
||||||
+23
-1
@@ -3,6 +3,26 @@ Change Log
|
|||||||
|
|
||||||
All notable changes to the project are documented in this file.
|
All notable changes to the project are documented in this file.
|
||||||
|
|
||||||
|
|
||||||
|
[v2.4.0][] - 2021-03-27
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
- Add support for `touchf()`, formatted string support for `touch()`
|
||||||
|
- Add support for `erasef()`, formatted string support for `erase()`
|
||||||
|
- Add support for `strtrim()`, trims leading and trailing white-space
|
||||||
|
from a string
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
|
||||||
|
- Fix `systemf()` improper handling of `system()` return value. Now
|
||||||
|
checks if exited OK, then returning the exit status of the command, or
|
||||||
|
if not exited OK, then checks if the command was signaled, and returns
|
||||||
|
-1 with `errno` set. This also allows for returning 127, like
|
||||||
|
`system()`, if the shell, or the program itself, did not exist
|
||||||
|
|
||||||
|
|
||||||
[v2.3.1][] - 2021-02-12
|
[v2.3.1][] - 2021-02-12
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
@@ -393,7 +413,9 @@ 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/v2.3.0...HEAD
|
[UNRELEASED]: https://github.com/troglobit/libite/compare/v2.4.0...HEAD
|
||||||
|
[v2.4.0]: https://github.com/troglobit/libite/compare/v2.3.1...v2.4.0
|
||||||
|
[v2.3.1]: https://github.com/troglobit/libite/compare/v2.3.0...v2.3.1
|
||||||
[v2.3.0]: https://github.com/troglobit/libite/compare/v2.2.1...v2.3.0
|
[v2.3.0]: https://github.com/troglobit/libite/compare/v2.2.1...v2.3.0
|
||||||
[v2.2.1]: https://github.com/troglobit/libite/compare/v2.2.0...v2.2.1
|
[v2.2.1]: https://github.com/troglobit/libite/compare/v2.2.0...v2.2.1
|
||||||
[v2.2.0]: https://github.com/troglobit/libite/compare/v2.1.2...v2.2.0
|
[v2.2.0]: https://github.com/troglobit/libite/compare/v2.1.2...v2.2.0
|
||||||
|
|||||||
@@ -94,6 +94,10 @@ Helper Macros
|
|||||||
|
|
||||||
Erase file/directory with `remove()`. Errors on `stderr`
|
Erase file/directory with `remove()`. Errors on `stderr`
|
||||||
|
|
||||||
|
- `erasef(fmt, ...)`
|
||||||
|
|
||||||
|
Like `erase()` but takes a formatted printf-like string as argument.
|
||||||
|
|
||||||
- `makedir(path)`
|
- `makedir(path)`
|
||||||
|
|
||||||
Create directory, like `mkdir()`. Errors on `stderr`
|
Create directory, like `mkdir()`. Errors on `stderr`
|
||||||
@@ -110,6 +114,10 @@ Helper Macros
|
|||||||
|
|
||||||
Create a file, or update mtime. Errors on `stderr`
|
Create a file, or update mtime. Errors on `stderr`
|
||||||
|
|
||||||
|
- `touchf(fmt, ...)`
|
||||||
|
|
||||||
|
Like `touch()` but takes a formatted printf-like string as argument.
|
||||||
|
|
||||||
- `S_ISEXEC(mode_t m)`
|
- `S_ISEXEC(mode_t m)`
|
||||||
|
|
||||||
Mysteriously missing from GLIBC
|
Mysteriously missing from GLIBC
|
||||||
@@ -311,6 +319,11 @@ Generic Functions
|
|||||||
match, or `-1` on error or not found. `strnmatch()` takes an extra arg
|
match, or `-1` on error or not found. `strnmatch()` takes an extra arg
|
||||||
to compare only `len` number of characters from `str`.
|
to compare only `len` number of characters from `str`.
|
||||||
|
|
||||||
|
- `strtrim(str)`
|
||||||
|
|
||||||
|
Trims a string from any leading and trailing white-space, returns the
|
||||||
|
trimmed result in the same buffer.
|
||||||
|
|
||||||
- `systemf(fmt, ...)`
|
- `systemf(fmt, ...)`
|
||||||
|
|
||||||
Like `system()`, but takes a formatted string as argument. This
|
Like `system()`, but takes a formatted string as argument. This
|
||||||
@@ -442,6 +455,7 @@ as a light weight utility library, these days NetBSD should also work.
|
|||||||
to generate a `configure` script. It is a generated file and otherwise
|
to generate a `configure` script. It is a generated file and otherwise
|
||||||
only included in released tarballs.
|
only included in released tarballs.
|
||||||
|
|
||||||
|
|
||||||
Origin & References
|
Origin & References
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
@@ -461,7 +475,7 @@ respective file for license details.
|
|||||||
[ISC]: https://en.wikipedia.org/wiki/ISC_license
|
[ISC]: https://en.wikipedia.org/wiki/ISC_license
|
||||||
[BSD]: https://en.wikipedia.org/wiki/BSD_licenses
|
[BSD]: https://en.wikipedia.org/wiki/BSD_licenses
|
||||||
[Travis]: https://travis-ci.org/troglobit/libite
|
[Travis]: https://travis-ci.org/troglobit/libite
|
||||||
[Travis Status]: https://travis-ci.org/troglobit/libite.png?branch=master
|
[Travis Status]: https://travis-ci.org/troglobit/libite.svg?branch=master
|
||||||
[Coverity Scan]: https://scan.coverity.com/projects/20602
|
[Coverity Scan]: https://scan.coverity.com/projects/20602
|
||||||
[Coverity Status]: https://img.shields.io/coverity/scan/20602.svg
|
[Coverity Status]: https://img.shields.io/coverity/scan/20602.svg
|
||||||
[Claudio Matsuoka]: https://github.com/cmatsuoka
|
[Claudio Matsuoka]: https://github.com/cmatsuoka
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
AC_INIT(libite, 2.3.1, https://github.com/troglobit/libite/issues)
|
AC_INIT(libite, 2.4.0, https://github.com/troglobit/libite/issues)
|
||||||
AC_CONFIG_AUX_DIR(aux)
|
AC_CONFIG_AUX_DIR(aux)
|
||||||
AM_INIT_AUTOMAKE([1.11 foreign dist-xz])
|
AM_INIT_AUTOMAKE([1.11 foreign dist-xz])
|
||||||
AM_SILENT_RULES([yes])
|
AM_SILENT_RULES([yes])
|
||||||
|
|||||||
Vendored
+14
@@ -1,3 +1,17 @@
|
|||||||
|
libite (2.4.0) stable; urgency=medium
|
||||||
|
|
||||||
|
* New functions:
|
||||||
|
- touchf(), formatted string support for touch()
|
||||||
|
- erasef(), formatted string support for erase()
|
||||||
|
- strtrim(), trims leading and trailing white-space from a string
|
||||||
|
* Fix systemf() improper handling of system() return value. Now checks
|
||||||
|
if exited OK, then returning the exit status of the command, or if not
|
||||||
|
exited OK, then checks if the command was signaled, and returns -1 with
|
||||||
|
errno set. This also allows for returning 127, like system(), if the
|
||||||
|
shell, or the program itself, did not exist.
|
||||||
|
|
||||||
|
-- Joachim Wiberg <troglobit@gmail.com> Sat, 27 Mar 2021 09:12:32 +0100
|
||||||
|
|
||||||
libite (2.3.1) stable; urgency=medium
|
libite (2.3.1) stable; urgency=medium
|
||||||
|
|
||||||
* Minor packaging fixes.
|
* Minor packaging fixes.
|
||||||
|
|||||||
Vendored
+3
@@ -5,6 +5,7 @@ libite.so.5 libite5 #MINVER#
|
|||||||
chomp@Base 2.0.0
|
chomp@Base 2.0.0
|
||||||
copyfile@Base 2.0.0
|
copyfile@Base 2.0.0
|
||||||
dir@Base 2.0.0
|
dir@Base 2.0.0
|
||||||
|
erasef@Base 2.4.0
|
||||||
fcopyfile@Base 2.0.0
|
fcopyfile@Base 2.0.0
|
||||||
fexist@Base 2.0.0
|
fexist@Base 2.0.0
|
||||||
fgetint@Base 2.0.0
|
fgetint@Base 2.0.0
|
||||||
@@ -38,12 +39,14 @@ libite.so.5 libite5 #MINVER#
|
|||||||
strmatch@Base 2.1.0
|
strmatch@Base 2.1.0
|
||||||
strnmatch@Base 2.1.0
|
strnmatch@Base 2.1.0
|
||||||
strtonum@Base 2.1.0
|
strtonum@Base 2.1.0
|
||||||
|
strtrim@Base 2.4.0
|
||||||
systemf@Base 2.2.0
|
systemf@Base 2.2.0
|
||||||
telnet_close@Base 2.1.0
|
telnet_close@Base 2.1.0
|
||||||
telnet_expect@Base 2.1.0
|
telnet_expect@Base 2.1.0
|
||||||
telnet_open@Base 2.1.0
|
telnet_open@Base 2.1.0
|
||||||
telnet_session@Base 2.1.0
|
telnet_session@Base 2.1.0
|
||||||
tempfile@Base 2.0.0
|
tempfile@Base 2.0.0
|
||||||
|
touchf@Base 2.4.0
|
||||||
truncatef@Base 2.3.0
|
truncatef@Base 2.3.0
|
||||||
which@Base 2.0.0
|
which@Base 2.0.0
|
||||||
whichp@Base 2.0.0
|
whichp@Base 2.0.0
|
||||||
|
|||||||
+5
-5
@@ -2,19 +2,19 @@ lib_LTLIBRARIES = libite.la
|
|||||||
|
|
||||||
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 7:0:2
|
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 8:0:3
|
||||||
libite_la_SOURCES = chomp.c copyfile.c \
|
libite_la_SOURCES = chomp.c copyfile.c \
|
||||||
conio.c conio.h \
|
conio.c conio.h dir.c \
|
||||||
dir.c fopenf.c fremove.c \
|
erasef.c fopenf.c fremove.c \
|
||||||
fexist.c fisdir.c \
|
fexist.c fisdir.c \
|
||||||
fparseln.c fsendfile.c \
|
fparseln.c fsendfile.c \
|
||||||
ifconfig.c lfile.c \
|
ifconfig.c lfile.c \
|
||||||
makepath.c progress.c \
|
makepath.c progress.c \
|
||||||
pidfile.c pidfilefn.c \
|
pidfile.c pidfilefn.c \
|
||||||
reallocarray.c rsync.c \
|
reallocarray.c rsync.c strtrim.c \
|
||||||
strlcpy.c strlcat.c strtonum.c \
|
strlcpy.c strlcat.c strtonum.c \
|
||||||
strdupa.h strndupa.h strnlen.h \
|
strdupa.h strndupa.h strnlen.h \
|
||||||
strmatch.c systemf.c \
|
strmatch.c systemf.c touchf.c \
|
||||||
telnet.c tempfile.c truncatef.c \
|
telnet.c tempfile.c truncatef.c \
|
||||||
yorn.c which.c \
|
yorn.c which.c \
|
||||||
lite.h strlite.h \
|
lite.h strlite.h \
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/* Formatted erase()
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Joachim Wiberg <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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "lite.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* erasef - Like erase() but with formatted string support
|
||||||
|
* @fmt: Formatted string to be composed into a pathname
|
||||||
|
*
|
||||||
|
* This is a wrapper for the erase() function in lite.h, lessening the
|
||||||
|
* burden of having to compose the filename from parts in a seprate
|
||||||
|
* buffer.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* Upon successful completion erasef() returns POSIX OK(0), otherwise,
|
||||||
|
* -1 is returned and errno is set to indicate the error.
|
||||||
|
*/
|
||||||
|
int erasef(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *file;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
file = alloca(len + 1);
|
||||||
|
if (!file) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(file, len + 1, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return erase(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
+8
-3
@@ -60,6 +60,9 @@ typedef struct lfile lfile_t;
|
|||||||
typedef struct sdbuf sdbuf_t;
|
typedef struct sdbuf sdbuf_t;
|
||||||
|
|
||||||
char *chomp (char *str);
|
char *chomp (char *str);
|
||||||
|
|
||||||
|
int erasef (const char *fmt, ...);
|
||||||
|
|
||||||
char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
|
char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
|
||||||
|
|
||||||
int fexist (const char *file);
|
int fexist (const char *file);
|
||||||
@@ -107,6 +110,8 @@ int telnet_close (sdbuf_t *ctx);
|
|||||||
int telnet_expect (sdbuf_t *ctx, char *script[], FILE *output);
|
int telnet_expect (sdbuf_t *ctx, char *script[], FILE *output);
|
||||||
int telnet_session (int addr, short port, char *script[], FILE *output);
|
int telnet_session (int addr, short port, char *script[], FILE *output);
|
||||||
|
|
||||||
|
int touchf (const char *fmt, ...);
|
||||||
|
|
||||||
int yorn (const char *fmt, ...);
|
int yorn (const char *fmt, ...);
|
||||||
|
|
||||||
char *which (const char *cmd);
|
char *which (const char *cmd);
|
||||||
@@ -117,9 +122,9 @@ int whichp (const char *cmd);
|
|||||||
#include <sys/time.h> /* utimensat() on *BSD */
|
#include <sys/time.h> /* utimensat() on *BSD */
|
||||||
static inline int touch(const char *path)
|
static inline int touch(const char *path)
|
||||||
{
|
{
|
||||||
if (mknod((path), S_IFREG|0644, 0)) {
|
if (utimensat(AT_FDCWD, path, NULL, 0)) {
|
||||||
if (errno == EEXIST)
|
if (errno == ENOENT)
|
||||||
return utimensat(AT_FDCWD, path, NULL, 0);
|
return mknod((path), S_IFREG|0644, 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+3
-1
@@ -67,6 +67,8 @@ size_t strlcat (char *dst, const char *src, size_t siz);
|
|||||||
long long strtonum (const char *numstr, long long minval, long long maxval, const char **errstrp);
|
long long strtonum (const char *numstr, long long minval, long long maxval, const char **errstrp);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
char *strtrim (char *str);
|
||||||
|
|
||||||
/* Convert string to natural number (0-2147483647), returns -1 on error. */
|
/* Convert string to natural number (0-2147483647), returns -1 on error. */
|
||||||
static inline int atonum(const char *str)
|
static inline int atonum(const char *str)
|
||||||
{
|
{
|
||||||
@@ -107,7 +109,7 @@ static inline int string_compare(const char *a, const char *b)
|
|||||||
*/
|
*/
|
||||||
static inline int string_case_compare(const char *a, const char *b)
|
static inline int string_case_compare(const char *a, const char *b)
|
||||||
{
|
{
|
||||||
return strlen (a) == strlen (b) && !strcasecmp (a, b);
|
return strlen(a) == strlen(b) && !strcasecmp(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* LITE_STRING_H_ */
|
#endif /* LITE_STRING_H_ */
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/* Trim a string from whitespace
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Mattias Walström <lazzer@gmail.com>
|
||||||
|
* Copyright (c) 2021 Joachim Wiberg <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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "lite.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* strtrim - Strip leading and trailing whitespace from a string
|
||||||
|
* @str: The string to trim
|
||||||
|
*
|
||||||
|
* Trims a string from any leading and trailing white-space, returns the
|
||||||
|
* trimmed result in the same buffer.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* If @str is a valid, non-NULL, string this function returns the same
|
||||||
|
* string stripped from whitespace. This function only returns %NULL
|
||||||
|
* if @str itself is %NULL.
|
||||||
|
*/
|
||||||
|
char *strtrim(char *str)
|
||||||
|
{
|
||||||
|
char *start, *end;
|
||||||
|
|
||||||
|
if (!str) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
start = str;
|
||||||
|
while (isspace(*start))
|
||||||
|
start++;
|
||||||
|
|
||||||
|
if (*start == 0) {
|
||||||
|
str[0] = 0;
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
end = start + strlen(start) - 1;
|
||||||
|
while (end > start && isspace(*end))
|
||||||
|
end--;
|
||||||
|
*(++end) = 0;
|
||||||
|
|
||||||
|
memmove(str, start, end - start + 1);
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
+11
-18
@@ -25,8 +25,8 @@ int systemf(const char *fmt, ...)
|
|||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char *cmd;
|
char *cmd;
|
||||||
int len, status;
|
int len;
|
||||||
int rc = -1;
|
int rc;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
len = vsnprintf(NULL, 0, fmt, ap);
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
@@ -42,23 +42,16 @@ int systemf(const char *fmt, ...)
|
|||||||
vsnprintf(cmd, len, fmt, ap);
|
vsnprintf(cmd, len, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
status = system(cmd);
|
rc = system(cmd);
|
||||||
|
if (rc == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
rc = WEXITSTATUS(status);
|
if (WIFEXITED(rc)) {
|
||||||
if (!WIFEXITED(status)) {
|
errno = 0;
|
||||||
if (WIFSIGNALED(status) &&
|
rc = WEXITSTATUS(rc);
|
||||||
(WTERMSIG(status) == SIGINT ||
|
} else if (WIFSIGNALED(rc)) {
|
||||||
WTERMSIG(status) == SIGQUIT)) {
|
errno = EINTR;
|
||||||
errno = EINTR;
|
rc = -1;
|
||||||
rc = -1;
|
|
||||||
} else if (!rc) {
|
|
||||||
/*
|
|
||||||
* Alert callee that command didn't complete
|
|
||||||
* successfully. Some programs don't change
|
|
||||||
* their exit code when signaled.
|
|
||||||
*/
|
|
||||||
rc = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/* Formatted touch()
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Joachim Wiberg <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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "lite.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* touchf - Like touch() but with formatted string support
|
||||||
|
* @fmt: Formatted string to be composed into a pathname
|
||||||
|
*
|
||||||
|
* This is a wrapper for the touch() function in lite.h, lessening the
|
||||||
|
* burden of having to compose the filename from parts in a seprate
|
||||||
|
* buffer.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* Upon successful completion touchf() returns POSIX OK(0), otherwise,
|
||||||
|
* -1 is returned and errno is set to indicate the error.
|
||||||
|
*/
|
||||||
|
int touchf(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *file;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
file = alloca(len + 1);
|
||||||
|
if (!file) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(file, len + 1, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return touch(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -30,7 +30,6 @@
|
|||||||
* of having to compose the filename from parts in a seprate buffer.
|
* of having to compose the filename from parts in a seprate buffer.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
|
|
||||||
* Upon successful completion truncate() returns POSIX OK(0), otherwise,
|
* Upon successful completion truncate() returns POSIX OK(0), otherwise,
|
||||||
* -1 is returned and errno is set to indicate the error.
|
* -1 is returned and errno is set to indicate the error.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+8
-3
@@ -4,9 +4,10 @@
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
struct { char *cmd; int rc; } list[] = {
|
struct { char *cmd; int rc; } list[] = {
|
||||||
|
{ "/app/enoent", 127 },
|
||||||
{ "false", 1 },
|
{ "false", 1 },
|
||||||
{ "true", 0 },
|
{ "true", 0 },
|
||||||
{ "kill -9 $$", 1 },
|
{ "kill -9 $$", -1 },
|
||||||
{ "kill -QUIT $$", -1 },
|
{ "kill -QUIT $$", -1 },
|
||||||
{ "kill -INT $$", -1 }
|
{ "kill -INT $$", -1 }
|
||||||
};
|
};
|
||||||
@@ -15,8 +16,12 @@ int main(void)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = systemf("%s", list[i].cmd);
|
rc = systemf("%s", list[i].cmd);
|
||||||
if (rc != list[i].rc)
|
if (rc != list[i].rc) {
|
||||||
err(rc, "Failed command %s", list[i].cmd);
|
if (rc == -1)
|
||||||
|
err(rc, "Failed %s", list[i].cmd);
|
||||||
|
else
|
||||||
|
errx(rc, "Failed %s, rc %d vs %d", list[i].cmd, rc, list[i].rc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+33
-2
@@ -1,3 +1,4 @@
|
|||||||
|
/* test of touch(), touchf(), erase(), and erasef() */
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@@ -6,6 +7,8 @@
|
|||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
|
#define FMT "%s-bar"
|
||||||
|
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
|
|
||||||
|
|
||||||
@@ -32,10 +35,38 @@ static int mtime(char *file)
|
|||||||
ret = timespec_newer(&after.st_mtim, &before.st_mtim);
|
ret = timespec_newer(&after.st_mtim, &before.st_mtim);
|
||||||
PRINT("Before: %s\n", timespec2str(&before.st_mtim, buf, sizeof(buf)));
|
PRINT("Before: %s\n", timespec2str(&before.st_mtim, buf, sizeof(buf)));
|
||||||
PRINT("After : %s\n", timespec2str(&after.st_mtim, buf, sizeof(buf)));
|
PRINT("After : %s\n", timespec2str(&after.st_mtim, buf, sizeof(buf)));
|
||||||
|
erase(file);
|
||||||
|
|
||||||
return !ret;
|
return !ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int formatted(char *file)
|
||||||
|
{
|
||||||
|
char vrfy[80];
|
||||||
|
|
||||||
|
if (touchf(FMT, file))
|
||||||
|
err(1, "Failed creating " FMT, file);
|
||||||
|
|
||||||
|
PRINT("Created " FMT "\n", file);
|
||||||
|
|
||||||
|
snprintf(vrfy, sizeof(vrfy), FMT, file);
|
||||||
|
if (!fexist(vrfy))
|
||||||
|
errx(1, "touchf() does not detect failure to create file " FMT, file);
|
||||||
|
|
||||||
|
PRINT("File " FMT " really does exist!\n", file);
|
||||||
|
|
||||||
|
erasef(FMT, file);
|
||||||
|
if (fexist(vrfy)) {
|
||||||
|
int saved = errno;
|
||||||
|
|
||||||
|
erase(vrfy);
|
||||||
|
errno = saved;
|
||||||
|
errx(1, "erasef() failed removing the created file " FMT, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
@@ -49,13 +80,13 @@ int main(int argc, char *argv[])
|
|||||||
err(1, "Failed creating tempfile, %s", file);
|
err(1, "Failed creating tempfile, %s", file);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
return mtime(file);
|
return mtime(file) || formatted(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* indent-tabs-mode: t
|
* indent-tabs-mode: t
|
||||||
* c-file-style: "linux"
|
* c-file-style: "linux"
|
||||||
* compile-command: "make pidfile && ./pidfile -v"
|
* compile-command: "make touch && ./touch -v"
|
||||||
* End:
|
* End:
|
||||||
*/
|
*/
|
||||||
Reference in new issue
Block a user