mirror of
https://github.com/troglobit/libite.git
synced 2026-10-14 10:19:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef04307b4a | ||
|
|
5d035d955e | ||
|
|
b65175782d | ||
|
|
c27a8e7ec6 | ||
|
|
d231c1e1eb | ||
|
|
247fb67274 | ||
|
|
c716cc5835 | ||
|
|
e81ce85867 | ||
|
|
549f325c21 | ||
|
|
2a6adeebcd | ||
|
|
cb2beacf2c | ||
|
|
256b6ba038 | ||
|
|
61d9b5fac7 | ||
|
|
38ad841389 | ||
|
|
f1a1a21569 | ||
|
|
7f3f4df9e9 | ||
|
|
02a42a1cad | ||
|
|
28c11f010a |
No files matched your search
+19
@@ -10,6 +10,25 @@ compiler:
|
|||||||
- gcc
|
- gcc
|
||||||
- clang
|
- clang
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
|
||||||
|
# via the "travis encrypt" command using the project repo's public key
|
||||||
|
- secure: "EcWeDUONZnl7IHBWD2rc92LwTWGIlqBZ7wQrLfe3mFXOnB+IZjJIBnDsJDnHDWwA8fGF9NaJbRz4BThroafueUwkDXNyvph1Mdaxm6mdMPyjNJ4H1AFkd9Fz0LYdLNXCPl43tm6s1BR6OWts17lWF6sMnMmIu8gUgXJVg2qsDBl3O9eCoRvQ/h4elLfXZ03fHi4XzzzQvZVyDCg8MCzXIgHJzdkv4llpiCLWQExFbIAVy39euDnx+UuWYB7WDdUbOc7HkkUwf0/vX9PhKVQFKOkXn1ddN0iCsWRH3ti5KXWrBeRO3RPu6Z5YtR8l1WK7iqCYOLuMBW23tXsBQsIW09f1+fFgJ8Ig5hHRRbDinbTUb+mHUJZmNv9ZTc3hPYH4Fyev/ljk42VVDdIBy9AqO42jj8VGmDmiIq47aqNJZUGYZgQlGXGqk9MtavJrqEVcFSgyfEtI+c4n4fzvMRpcEwjnbp482s1xNzHQZ1GQI77Td5UUXXWyNSCoQoE/VpkAesYJAw8KwXOXveDr3Qu0HhuQu1oyLmWHlZHYDu+TInjY81gpGw9Cm7/SdFoA0Ag49PlAXdPRymbP01B50MqrCTxtXEHtdXxhrkDvaoUp7heSuvO0fS+mI5F7eQ4Ji2JdyRSt1KpXVNAyL1FrO/yznM3EwcXPmWmrc+QjFtC9vY4="
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
|
||||||
|
|
||||||
|
addons:
|
||||||
|
coverity_scan:
|
||||||
|
project:
|
||||||
|
name: "troglobit/libite"
|
||||||
|
description: "That missing frog DNA you've been looking for"
|
||||||
|
notification_email: troglobit@gmail.com
|
||||||
|
build_command_prepend: "./autogen.sh && ./configure --prefix=/tmp --disable-silent-rules"
|
||||||
|
build_command: "make clean all"
|
||||||
|
branch_pattern: dev
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- ./autogen.sh
|
- ./autogen.sh
|
||||||
- ./configure --prefix=/tmp --disable-silent-rules
|
- ./configure --prefix=/tmp --disable-silent-rules
|
||||||
|
|||||||
+17
-1
@@ -3,6 +3,21 @@ 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.2.0][] - 2020-03-16
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- Add support for `systemf()`, formatted string `system()` replacement
|
||||||
|
- Add support for `fmkpath()`, formatted string `mkpath()`
|
||||||
|
- Add support for `fopenf()`, formatted string `fopen()` replacement
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Fix possible memory leak in `rsync()`, found by Coverity Scan
|
||||||
|
- Check return value of `fstat()` to prevent bogus destination file
|
||||||
|
times when using `copyfile()`, found by Coverity Scan
|
||||||
|
|
||||||
|
|
||||||
[v2.1.2][] - 2020-02-22
|
[v2.1.2][] - 2020-02-22
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
@@ -357,7 +372,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/v2.1.2...HEAD
|
[UNRELEASED]: https://github.com/troglobit/libite/compare/v2.2.0...HEAD
|
||||||
|
[v2.2.0]: https://github.com/troglobit/libite/compare/v2.1.2...v2.2.0
|
||||||
[v2.1.2]: https://github.com/troglobit/libite/compare/v2.1.1...v2.1.2
|
[v2.1.2]: https://github.com/troglobit/libite/compare/v2.1.1...v2.1.2
|
||||||
[v2.1.1]: https://github.com/troglobit/libite/compare/v2.1.0...v2.1.1
|
[v2.1.1]: https://github.com/troglobit/libite/compare/v2.1.0...v2.1.1
|
||||||
[v2.1.0]: https://github.com/troglobit/libite/compare/v2.0.2...v2.1.0
|
[v2.1.0]: https://github.com/troglobit/libite/compare/v2.0.2...v2.1.0
|
||||||
|
|||||||
@@ -18,9 +18,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
|
|
||||||
Note: Much of the code in libite (-lite) is written by Claudio Matsuoka
|
|
||||||
for Finit and released under the MIT/X11 license. Joachim Nilsson
|
|
||||||
later improved on the Finit code base and included pieces of
|
|
||||||
software released under the ISC and BSD licenses. See each
|
|
||||||
respective file for license details.
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
-lite | Frog DNA, basically
|
-lite | Frog DNA, basically
|
||||||
===========================
|
===========================
|
||||||
[![Travis Status][]][Travis]
|
[![Travis Status][]][Travis] [![Coverity Status]][Coverity Scan]
|
||||||
|
|
||||||
|
|
||||||
Table of Contents
|
Table of Contents
|
||||||
-----------------
|
-----------------
|
||||||
@@ -12,7 +11,7 @@ Table of Contents
|
|||||||
* [Generic Functions](#generic-functions)
|
* [Generic Functions](#generic-functions)
|
||||||
* [OpenBSD Functions](#openbsd-functions)
|
* [OpenBSD Functions](#openbsd-functions)
|
||||||
* [Build & Install](#origin--references)
|
* [Build & Install](#origin--references)
|
||||||
* [TODO](#todo)
|
* [Origin & References](#origin--references)
|
||||||
|
|
||||||
|
|
||||||
> **NOTE:** Incompatible changes in v2.0 compared to v1.x!
|
> **NOTE:** Incompatible changes in v2.0 compared to v1.x!
|
||||||
@@ -181,6 +180,15 @@ Generic Functions
|
|||||||
|
|
||||||
Check for the existence of a directory, returns True(1) or False(0).
|
Check for the existence of a directory, returns True(1) or False(0).
|
||||||
|
|
||||||
|
- `fopenf(mode, fmt, ...)`
|
||||||
|
|
||||||
|
Like `fopen()`, but takes a formatted string as argument. This
|
||||||
|
greatly simplifies operations that usually consist of composing a
|
||||||
|
filename from parts into a dynamic buffer before actually opening
|
||||||
|
the file.
|
||||||
|
|
||||||
|
> **Notice:** the swapped order of `pathname` and `mode`!
|
||||||
|
|
||||||
- `fsendfile(src, dst, len)`
|
- `fsendfile(src, dst, len)`
|
||||||
|
|
||||||
Copy data between file streams, very similar to `fcopyfile()`, but
|
Copy data between file streams, very similar to `fcopyfile()`, but
|
||||||
@@ -223,6 +231,12 @@ Generic Functions
|
|||||||
|
|
||||||
Like `makepath()`, but also takes a `mode_t` permission mode argument.
|
Like `makepath()`, but also takes a `mode_t` permission mode argument.
|
||||||
|
|
||||||
|
- `fmkpath(mode, fmt, ...)`
|
||||||
|
|
||||||
|
Like `mkpath()`, but takes a formatted string as argument.
|
||||||
|
|
||||||
|
> **Notice:** the swapped order of `pathname` and `mode`!
|
||||||
|
|
||||||
- `movefile(src, dst)`
|
- `movefile(src, dst)`
|
||||||
|
|
||||||
Like `copyfile()`, but renames `src` to `dst`, or recreates symlink
|
Like `copyfile()`, but renames `src` to `dst`, or recreates symlink
|
||||||
@@ -289,6 +303,12 @@ Generic Functions
|
|||||||
Find matching string in an array of strings. Returns index in array
|
Find matching string in an array of strings. Returns index in array
|
||||||
on match, or `-1` on error or not found.
|
on match, or `-1` on error or not found.
|
||||||
|
|
||||||
|
`systemf(fmt, ...)`
|
||||||
|
|
||||||
|
Like `system()`, but takes a formatted string as argument. This
|
||||||
|
greatly simplifies operations that usually consist of composing a
|
||||||
|
command from parts into a dynamic buffer before calling it.
|
||||||
|
|
||||||
- `telnet_open(), telnet_close(), telnet_expect()`
|
- `telnet_open(), telnet_close(), telnet_expect()`
|
||||||
|
|
||||||
Poor mans telnet expect in C. Opens connection to a Telnet service;
|
Poor mans telnet expect in C. Opens connection to a Telnet service;
|
||||||
@@ -407,6 +427,14 @@ 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
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Much of the code in libite (-lite) is written by [Claudio Matsuoka][]
|
||||||
|
for [Finit][original finit] and released under the MIT/X11 license.
|
||||||
|
Joachim Nilsson later improved on the [Finit][] code base and included
|
||||||
|
pieces of software released under the ISC and BSD licenses. See each
|
||||||
|
respective file for license details.
|
||||||
|
|
||||||
[1]: https://github.com/troglobit/finit
|
[1]: https://github.com/troglobit/finit
|
||||||
[2]: http://www.openbsd.org/
|
[2]: http://www.openbsd.org/
|
||||||
@@ -419,3 +447,8 @@ only included in released tarballs.
|
|||||||
[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.png?branch=master
|
||||||
|
[Coverity Scan]: https://scan.coverity.com/projects/20602
|
||||||
|
[Coverity Status]: https://img.shields.io/coverity/scan/20602.svg
|
||||||
|
[Claudio Matsuoka]: https://github.com/cmatsuoka
|
||||||
|
[original finit]: http://helllabs.org/finit/
|
||||||
|
[Finit]: https://github.com/troglobit/finit
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
AC_INIT(libite, 2.1.2, https://github.com/troglobit/libite/issues)
|
AC_INIT(libite, 2.2.0, https://github.com/troglobit/libite/issues)
|
||||||
AC_CONFIG_AUX_DIR(aux)
|
AC_CONFIG_AUX_DIR(aux)
|
||||||
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])
|
||||||
@@ -10,7 +10,7 @@ AC_CONFIG_MACRO_DIR([m4])
|
|||||||
|
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
AC_PROG_INSTALL
|
AC_PROG_INSTALL
|
||||||
AM_PROG_AR
|
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
|
||||||
LT_INIT
|
LT_INIT
|
||||||
|
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
Vendored
+13
@@ -1,3 +1,16 @@
|
|||||||
|
libite (2.2.0) unstable; urgency=medium
|
||||||
|
|
||||||
|
* New functions:
|
||||||
|
- systemf(), formatted string system() replacement
|
||||||
|
- fmkpath(), formatted string mkpath() replacement
|
||||||
|
- fopenf(), formatted string fopen() replacement
|
||||||
|
* Fixes
|
||||||
|
- possible memory leak in rsync()
|
||||||
|
- Check return value of fstat() to prevent bogus destination file
|
||||||
|
times when using copyfile()
|
||||||
|
|
||||||
|
-- Joachim Nilsson <troglobit@gmail.com> Mon, 16 Mar 2020 15:42:02 +0100
|
||||||
|
|
||||||
libite (2.1.2) stable; urgency=high
|
libite (2.1.2) stable; urgency=high
|
||||||
|
|
||||||
* Fix upgrade of base package, new library name to match SONAME
|
* Fix upgrade of base package, new library name to match SONAME
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
Source: libite
|
Source: libite
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Maintainer: Joachim Nilsson <troglobit@gmail.com>
|
Maintainer: Joachim Nilsson <troglobit@gmail.com>
|
||||||
Build-Depends: debhelper (>= 10)
|
Build-Depends: debhelper (>= 10), libtool
|
||||||
Standards-Version: 4.3.0
|
Standards-Version: 4.3.0
|
||||||
Section: libs
|
Section: libs
|
||||||
Homepage: https://github.com/troglobit/libite/
|
Homepage: https://github.com/troglobit/libite/
|
||||||
|
|||||||
Vendored
+3
@@ -9,6 +9,8 @@ libite.so.5 libite5 #MINVER#
|
|||||||
fexist@Base 2.0.0
|
fexist@Base 2.0.0
|
||||||
fgetint@Base 2.0.0
|
fgetint@Base 2.0.0
|
||||||
fisdir@Base 2.0.0
|
fisdir@Base 2.0.0
|
||||||
|
fmkpath@Base 2.2.0
|
||||||
|
fopenf@Base 2.2.0
|
||||||
fparseln@Base 2.0.0
|
fparseln@Base 2.0.0
|
||||||
fsendfile@Base 2.0.0
|
fsendfile@Base 2.0.0
|
||||||
ifconfig@Base 2.0.0
|
ifconfig@Base 2.0.0
|
||||||
@@ -35,6 +37,7 @@ 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
|
||||||
|
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
|
||||||
|
|||||||
+4
-3
@@ -2,10 +2,10 @@ 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 5:1:0
|
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 6:0:1
|
||||||
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 \
|
||||||
fexist.c fisdir.c \
|
fexist.c fisdir.c \
|
||||||
fparseln.c fsendfile.c \
|
fparseln.c fsendfile.c \
|
||||||
ifconfig.c lfile.c \
|
ifconfig.c lfile.c \
|
||||||
@@ -14,7 +14,8 @@ libite_la_SOURCES = chomp.c copyfile.c \
|
|||||||
reallocarray.c rsync.c \
|
reallocarray.c rsync.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 telnet.c tempfile.c \
|
strmatch.c systemf.c \
|
||||||
|
telnet.c tempfile.c \
|
||||||
yorn.c which.c \
|
yorn.c which.c \
|
||||||
lite.h strlite.h \
|
lite.h strlite.h \
|
||||||
queue.h tree.h
|
queue.h tree.h
|
||||||
|
|||||||
+3
-1
@@ -85,7 +85,9 @@ static void set_mtime(int in, int out)
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
struct timespec tv[2];
|
struct timespec tv[2];
|
||||||
|
|
||||||
fstat(in, &st);
|
if (fstat(in, &st))
|
||||||
|
return;
|
||||||
|
|
||||||
tv[0] = st.st_atim;
|
tv[0] = st.st_atim;
|
||||||
tv[1] = st.st_mtim;
|
tv[1] = st.st_mtim;
|
||||||
futimens(out, tv);
|
futimens(out, tv);
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/* Formatted fopen()
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fopenf - Open a file based on the formatted string and optional arguments
|
||||||
|
* @mode: Last argument in optional list, if omitted EINVAL
|
||||||
|
* @fmt: Formatted string to be composed into a pathname
|
||||||
|
*
|
||||||
|
* This function is an extension to the fopen() family, lessening the burden
|
||||||
|
* of first having to compose the filename from parts in a seprate buffer.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* Upon successful completion fopenf() a FILE pointer. Otherwise, NULL
|
||||||
|
* is returned and errno is set to indicate the error.
|
||||||
|
*/
|
||||||
|
FILE *fopenf(const char *mode, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
FILE *fp = NULL;
|
||||||
|
char *file;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
file = alloca(len + 1);
|
||||||
|
if (file) {
|
||||||
|
vsnprintf(file, len + 1, fmt, ap);
|
||||||
|
fp = fopen(file, mode);
|
||||||
|
}
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -65,6 +65,7 @@ char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
|
|||||||
int fexist (const char *file);
|
int fexist (const char *file);
|
||||||
int fisdir (const char *path);
|
int fisdir (const char *path);
|
||||||
|
|
||||||
|
FILE *fopenf (const char *mode, const char *fmt, ...);
|
||||||
FILE *tempfile (void);
|
FILE *tempfile (void);
|
||||||
ssize_t copyfile (const char *src, const char *dst, int len, int opt);
|
ssize_t copyfile (const char *src, const char *dst, int len, int opt);
|
||||||
int movefile (const char *src, const char *dst);
|
int movefile (const char *src, const char *dst);
|
||||||
@@ -80,6 +81,7 @@ char *lfgetkey (lfile_t *lf, const char *key);
|
|||||||
int lfgetint (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 fgetint (const char *file, const char *sep, const char *key);
|
||||||
|
|
||||||
|
int fmkpath (mode_t mode, const char *fmt, ...);
|
||||||
int mkpath (const char *dir, mode_t mode);
|
int mkpath (const char *dir, mode_t mode);
|
||||||
int makepath (const char *dir);
|
int makepath (const char *dir);
|
||||||
|
|
||||||
@@ -96,6 +98,8 @@ void *reallocarray(void *optr, size_t nmemb, size_t size);
|
|||||||
void progress (int percent, int max_width);
|
void progress (int percent, int max_width);
|
||||||
void progress_simple(int percent);
|
void progress_simple(int percent);
|
||||||
|
|
||||||
|
int systemf (const char *fmt, ...);
|
||||||
|
|
||||||
sdbuf_t*telnet_open (int addr, short port);
|
sdbuf_t*telnet_open (int addr, short port);
|
||||||
int telnet_close (sdbuf_t *ctx);
|
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);
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "lite.h"
|
#include "lite.h"
|
||||||
@@ -46,6 +48,38 @@ int mkpath(const char *dir, mode_t mode)
|
|||||||
return mkdir(dir, mode);
|
return mkdir(dir, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fmkpath - Formatted version of mkpath()
|
||||||
|
* @mode: A &mode_t mode to create directories with
|
||||||
|
* @fmt: Formatted string to be composed into a pathname
|
||||||
|
*
|
||||||
|
* Note:
|
||||||
|
* Notice the swapped arguments, compared to mkpath()!
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* POSIX OK(0) on success, otherwise -1 with @errno set.
|
||||||
|
*/
|
||||||
|
int fmkpath(mode_t mode, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *path;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
path = alloca(len + 1);
|
||||||
|
if (!path)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(path, len + 1, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return mkpath(path, mode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* makepath - Create all components of the specified directory.
|
* makepath - Create all components of the specified directory.
|
||||||
* @dir: Directory to create.
|
* @dir: Directory to create.
|
||||||
|
|||||||
+7
-5
@@ -107,20 +107,22 @@ int rsync(char *src, char *dst, int opt, int (*filter)(const char *file))
|
|||||||
snprintf(source, sizeof(source), "%s%s%s", src, fisslashdir(src) ? "" : "/", files[i]);
|
snprintf(source, sizeof(source), "%s%s%s", src, fisslashdir(src) ? "" : "/", files[i]);
|
||||||
if (fisdir(source)) {
|
if (fisdir(source)) {
|
||||||
char dst2[256];
|
char dst2[256];
|
||||||
struct stat st;
|
struct stat sb;
|
||||||
|
|
||||||
strcat(source, "/");
|
strcat(source, "/");
|
||||||
if (stat(source, &st))
|
if (stat(source, &sb)) {
|
||||||
return 1;
|
result++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (mdir(dst2, sizeof(dst2), dst, files[i], &st)) {
|
if (mdir(dst2, sizeof(dst2), dst, files[i], &sb)) {
|
||||||
result++;
|
result++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
rsync(source, dst2, opt, filter);
|
rsync(source, dst2, opt, filter);
|
||||||
if (keep_mtim)
|
if (keep_mtim)
|
||||||
set_mtime(dst2, &st);
|
set_mtime(dst2, &sb);
|
||||||
|
|
||||||
continue; /* Next file/dir in @src to copy... */
|
continue; /* Next file/dir in @src to copy... */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/* Formatted system() which returns actual return status of command
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
int systemf(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *cmd;
|
||||||
|
int len, status;
|
||||||
|
int rc = -1;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
cmd = alloca(++len);
|
||||||
|
if (!cmd) {
|
||||||
|
va_end(ap);
|
||||||
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
vsnprintf(cmd, len, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
status = system(cmd);
|
||||||
|
|
||||||
|
rc = WEXITSTATUS(status);
|
||||||
|
if (!WIFEXITED(status)) {
|
||||||
|
if (WIFSIGNALED(status) &&
|
||||||
|
(WTERMSIG(status) == SIGINT ||
|
||||||
|
WTERMSIG(status) == SIGQUIT)) {
|
||||||
|
errno = EINTR;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
*.o
|
*.o
|
||||||
*.log
|
*.log
|
||||||
*.trs
|
*.trs
|
||||||
|
.deps/
|
||||||
chomp
|
chomp
|
||||||
copyfile
|
copyfile
|
||||||
dir
|
dir
|
||||||
fexist
|
fexist
|
||||||
fisdir
|
fisdir
|
||||||
|
fopenf
|
||||||
fsendfile
|
fsendfile
|
||||||
lfile
|
lfile
|
||||||
makepath
|
makepath
|
||||||
@@ -15,6 +17,7 @@ progress
|
|||||||
rsync
|
rsync
|
||||||
str
|
str
|
||||||
strmatch
|
strmatch
|
||||||
|
systemf
|
||||||
tempfile
|
tempfile
|
||||||
touch
|
touch
|
||||||
tree
|
tree
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ TESTS += copyfile
|
|||||||
TESTS += dir
|
TESTS += dir
|
||||||
TESTS += fexist
|
TESTS += fexist
|
||||||
TESTS += fisdir
|
TESTS += fisdir
|
||||||
|
TESTS += fopenf
|
||||||
TESTS += fsendfile
|
TESTS += fsendfile
|
||||||
TESTS += lfile
|
TESTS += lfile
|
||||||
TESTS += makepath
|
TESTS += makepath
|
||||||
@@ -16,6 +17,7 @@ TESTS += progress
|
|||||||
TESTS += rsync
|
TESTS += rsync
|
||||||
TESTS += str
|
TESTS += str
|
||||||
TESTS += strmatch
|
TESTS += strmatch
|
||||||
|
TESTS += systemf
|
||||||
TESTS += touch
|
TESTS += touch
|
||||||
TESTS += tempfile
|
TESTS += tempfile
|
||||||
TESTS += which
|
TESTS += which
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include "check.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
char *dir = "/tmp";
|
||||||
|
char *file = "__foo__";
|
||||||
|
|
||||||
|
fp = fopenf("w", "%s/%s", dir, file);
|
||||||
|
if (fp) {
|
||||||
|
fputs("foo", fp);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
fail_unless(fexist("/tmp/__foo__"));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+33
-11
@@ -4,6 +4,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
|
#define BASEDIR "/tmp/libite-test"
|
||||||
|
|
||||||
int checkpath(const char *dir)
|
int checkpath(const char *dir)
|
||||||
{
|
{
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
@@ -32,28 +34,48 @@ int test_makepath(const char *dir)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int test_fmkpath(const char *subdir)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = fmkpath(0755, "%s/%s", BASEDIR, subdir);
|
||||||
|
if (!ret) {
|
||||||
|
char tmp[256];
|
||||||
|
|
||||||
|
snprintf(tmp, sizeof(tmp), "%s/%s", BASEDIR, subdir);
|
||||||
|
ret = checkpath(tmp);
|
||||||
|
} else
|
||||||
|
perror("Failed");
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int i, ret = 0;
|
int i, ret = 0;
|
||||||
char *list[] = {
|
char *list[] = {
|
||||||
"/tmp/libite-test/tok/",
|
BASEDIR "/tok/",
|
||||||
"/tmp/libite-test/tok2",
|
BASEDIR "/tok2",
|
||||||
"/tmp/libite-test/ab",
|
BASEDIR "/ab",
|
||||||
"/tmp/libite-test/b",
|
BASEDIR "/b",
|
||||||
"/tmp/libite-test/a/",
|
BASEDIR "/a/",
|
||||||
"/tmp/libite-test/a/b",
|
BASEDIR "/a/b",
|
||||||
"/tmp/libite-test/a/c/",
|
BASEDIR "/a/c/",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
printf("Testing makepath() ...\n");
|
mkdir(BASEDIR, 0755);
|
||||||
mkdir("/tmp/libite-test", 0755);
|
|
||||||
|
|
||||||
|
printf("PASS 1/2: makepath() ======================================\n");
|
||||||
for (i = 0; list[i] && !ret; i++)
|
for (i = 0; list[i] && !ret; i++)
|
||||||
ret |= test_makepath(list[i]);
|
ret |= test_makepath(list[i]);
|
||||||
|
|
||||||
printf("\nCleaning up ...\n");
|
printf("PASS 2/2: fmkpath() =======================================\n");
|
||||||
system("rm -rf /tmp/libite-test");
|
for (i = 0; list[i] && !ret; i++)
|
||||||
|
ret |= test_fmkpath(list[i] + strlen(BASEDIR) + 1);
|
||||||
|
|
||||||
|
printf("DONE: Cleaning up =========================================\n");
|
||||||
|
system("rm -rf " BASEDIR);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#include <err.h>
|
||||||
|
#include "check.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
struct { char *cmd; int rc; } list[] = {
|
||||||
|
{ "false", 1 },
|
||||||
|
{ "true", 0 },
|
||||||
|
{ "kill -9 $$", 1 },
|
||||||
|
{ "kill -QUIT $$", -1 },
|
||||||
|
{ "kill -INT $$", -1 }
|
||||||
|
};
|
||||||
|
|
||||||
|
for (size_t i = 0; i < NELEMS(list); i++) {
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = systemf("%s", list[i].cmd);
|
||||||
|
if (rc != list[i].rc)
|
||||||
|
err(rc, "Failed command %s", list[i].cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
|
|
||||||
Reference in new issue
Block a user