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 | ||
|
|
20d8d40285 | ||
|
|
4dc24f37e3 | ||
|
|
11f8846f63 | ||
|
|
41778fb3ce | ||
|
|
59d1f0d60c | ||
|
|
afc4289326 | ||
|
|
67267659f7 | ||
|
|
188509d811 | ||
|
|
c10cd67266 | ||
|
|
82db75cac6 | ||
|
|
51970ff86e | ||
|
|
d6fa3cde96 | ||
|
|
9d50de3ec7 | ||
|
|
2aed5a6b3f | ||
|
|
f873635cfe | ||
|
|
c3d5588298 | ||
|
|
a65b2dfd71 | ||
|
|
6e8d8fc32c | ||
|
|
966aee09cd | ||
|
|
f93e298875 | ||
|
|
c8ec83f20c | ||
|
|
835e09a9fe | ||
|
|
13ffe87d10 | ||
|
|
72d1cb6501 | ||
|
|
83ace4f12d | ||
|
|
9bdc5e94b5 | ||
|
|
83047d4413 | ||
|
|
b2c2d032e8 | ||
|
|
7f053f7624 | ||
|
|
b15a14e920 | ||
|
|
7e8534e36b | ||
|
|
3989d91d36 | ||
|
|
fe3673a5e1 | ||
|
|
1bdcb1bfe4 | ||
|
|
75d3f1978e | ||
|
|
c07bfbda58 | ||
|
|
0ef509c393 | ||
|
|
5620faf7bf | ||
|
|
b6a9ed3c6d | ||
|
|
9d63302337 | ||
|
|
02d9d9f8c1 | ||
|
|
9f92a9d572 | ||
|
|
f0e3ed3342 | ||
|
|
34f23a77f8 |
No files matched your search
+2
-10
@@ -1,16 +1,8 @@
|
||||
*~
|
||||
*.d
|
||||
*.o
|
||||
*.so
|
||||
*.so.*
|
||||
*.a
|
||||
.deps
|
||||
.libs
|
||||
ID
|
||||
GPATH
|
||||
GRTAGS
|
||||
GTAGS
|
||||
tmp/
|
||||
compile
|
||||
config.*
|
||||
configure
|
||||
@@ -25,5 +17,5 @@ Makefile.in
|
||||
aclocal.m4
|
||||
ar-lib
|
||||
autom4te.cache
|
||||
libite*
|
||||
test-driver
|
||||
test-driver
|
||||
libite.pc
|
||||
+19
@@ -10,6 +10,25 @@ compiler:
|
||||
- gcc
|
||||
- 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:
|
||||
- ./autogen.sh
|
||||
- ./configure --prefix=/tmp --disable-silent-rules
|
||||
|
||||
+62
-1
@@ -4,6 +4,62 @@ Change Log
|
||||
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
|
||||
-----------------------
|
||||
|
||||
### Fixes
|
||||
- Fix Debian package upgrade from libite -> libite5
|
||||
|
||||
|
||||
[v2.1.1][] - 2020-02-22
|
||||
-----------------------
|
||||
|
||||
### Changes
|
||||
- Add test/example for `printhdr()`
|
||||
- Update copyright years
|
||||
|
||||
### Fixes
|
||||
- chomp: Check for beginning of string while removing \n's
|
||||
|
||||
|
||||
[v2.1.0][] - 2019-08-26
|
||||
-----------------------
|
||||
|
||||
### Changes
|
||||
- Add support for `strmatch()` and `strnmatch()`
|
||||
- Add support for `yorn()`, safe yes-or-no prompt
|
||||
- Add support for telnet expect/session APIs
|
||||
- Add modified `printhdr()` which takes ANSI attribute
|
||||
|
||||
### Fixes
|
||||
- Fix `pidfile_signal()`: always return result of `kill()`, or the
|
||||
result of `remove()` if we successfully sent `SIGKILL`
|
||||
- Fix `strtonum()`: POSIX `strtoll()` returns `EINVAL`, check that
|
||||
- Fix #13, support C++ `extern "C" {}` for header files
|
||||
|
||||
|
||||
[v2.0.2][] - 2018-05-10
|
||||
-----------------------
|
||||
|
||||
### Fixes
|
||||
- Fix issue #12, missing includes in `strlite.h` for standalone use
|
||||
- FTBFS `strtonum.c` on older systems w/o `LLONG_MAX` and `LLONG_MIN`
|
||||
|
||||
|
||||
[v2.0.1][] - 2017-12-22
|
||||
-----------------------
|
||||
|
||||
@@ -316,7 +372,12 @@ 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.1...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.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.0.2]: https://github.com/troglobit/libite/compare/v2.0.1...v2.0.2
|
||||
[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
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
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.
|
||||
|
||||
Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
|
||||
Copyright (c) 2008-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||
Copyright (c) 2008-2020 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
|
||||
|
||||
+32
-26
@@ -1,44 +1,50 @@
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
doc_DATA = README.md LICENSE
|
||||
doc_DATA = README.md LICENSE ChangeLog.md
|
||||
EXTRA_DIST = README.md LICENSE ChangeLog.md
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = libite.pc
|
||||
SUBDIRS = src tests
|
||||
|
||||
## Generate .deb package
|
||||
package:
|
||||
@dpkg-buildpackage -uc -us -B
|
||||
|
||||
## Generate MD5 checksum file
|
||||
MD5 = md5sum
|
||||
md5-dist:
|
||||
@for file in $(DIST_ARCHIVES); do \
|
||||
$(MD5) $$file > $$file.md5; \
|
||||
@for file in $(DIST_ARCHIVES); do \
|
||||
$(MD5) $$file > ../$$file.md5; \
|
||||
done
|
||||
|
||||
## Check if tagged in git
|
||||
release-hook:
|
||||
if [ ! `git tag | grep $(PACKAGE_VERSION)` ]; then \
|
||||
echo; \
|
||||
printf "\033[1m\033[41mCannot find release tag $(PACKAGE_VERSION)\033[0m\n"; \
|
||||
printf "\033[1m\033[5mDo release anyway?\033[0m "; read yorn; \
|
||||
if [ "$$yorn" != "y" -a "$$yorn" != "Y" ]; then \
|
||||
printf "OK, aborting release.\n"; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
echo; \
|
||||
else \
|
||||
echo; \
|
||||
printf "\033[1m\033[42mFound GIT release tag $(PACKAGE_VERSION)\033[0m\n"; \
|
||||
printf "\033[1m\033[44m>>Remember to push tags!\033[0m\n"; \
|
||||
echo; \
|
||||
@if [ ! `git tag | grep $(PACKAGE_VERSION)` ]; then \
|
||||
echo; \
|
||||
printf "\e[1m\e[41mCannot find release tag $(PACKAGE_VERSION)\e[0m\n"; \
|
||||
printf "\e[1m\e[5mDo release anyway?\e[0m "; read yorn; \
|
||||
if [ "$$yorn" != "y" -a "$$yorn" != "Y" ]; then \
|
||||
printf "OK, aborting release.\n"; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
echo; \
|
||||
else \
|
||||
echo; \
|
||||
printf "\e[1m\e[42mFound GIT release tag $(PACKAGE_VERSION)\e[0m\n"; \
|
||||
printf "\e[1m\e[44m>>Remember to push tags!\e[0m\n"; \
|
||||
echo; \
|
||||
fi
|
||||
|
||||
# lintian --profile debian -i -I --show-overrides ../$PKG.changes
|
||||
package build-deb:
|
||||
@dpkg-buildpackage -uc -us -B
|
||||
|
||||
## Target to run when building a release
|
||||
release: distcheck release-hook md5-dist
|
||||
@for file in $(DIST_ARCHIVES); do \
|
||||
printf "$$file \tDistribution tarball\n"; \
|
||||
printf "$$file.md5\t"; cat $$file.md5 | cut -f1 -d' '; \
|
||||
mv $$file* ../; \
|
||||
release: release-hook distcheck package md5-dist
|
||||
@mv $(DIST_ARCHIVES) ../
|
||||
@echo
|
||||
@echo "Resulting release files:"
|
||||
@echo "================================================================="
|
||||
@for file in $(DIST_ARCHIVES); do \
|
||||
printf "%-32s Distribution tarball\n" $$file; \
|
||||
printf "%-32s " $$file.md5; cat ../$$file.md5 | cut -f1 -d' '; \
|
||||
done
|
||||
@for file in `cd ..; ls $(PACKAGE)*_$(VERSION)*`; do \
|
||||
printf "%-32s Debian/Ubuntu package\n" $$file; \
|
||||
done
|
||||
@@ -1,7 +1,6 @@
|
||||
-lite | Frog DNA, basically
|
||||
===========================
|
||||
[![Travis Status][]][Travis]
|
||||
|
||||
[![Travis Status][]][Travis] [![Coverity Status]][Coverity Scan]
|
||||
|
||||
Table of Contents
|
||||
-----------------
|
||||
@@ -12,7 +11,7 @@ Table of Contents
|
||||
* [Generic Functions](#generic-functions)
|
||||
* [OpenBSD Functions](#openbsd-functions)
|
||||
* [Build & Install](#origin--references)
|
||||
* [TODO](#todo)
|
||||
* [Origin & References](#origin--references)
|
||||
|
||||
|
||||
> **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).
|
||||
|
||||
- `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)`
|
||||
|
||||
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.
|
||||
|
||||
- `fmkpath(mode, fmt, ...)`
|
||||
|
||||
Like `mkpath()`, but takes a formatted string as argument.
|
||||
|
||||
> **Notice:** the swapped order of `pathname` and `mode`!
|
||||
|
||||
- `movefile(src, dst)`
|
||||
|
||||
Like `copyfile()`, but renames `src` to `dst`, or recreates symlink
|
||||
@@ -284,6 +298,26 @@ Generic Functions
|
||||
`delete`, it is now called `opt`. The APIs are 100% compatible if the
|
||||
value `1` was used.
|
||||
|
||||
- `strmatch()`, `strnmatch()`
|
||||
|
||||
Find matching string in an array of strings. Returns index in array
|
||||
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()`
|
||||
|
||||
Poor mans telnet expect in C. Opens connection to a Telnet service;
|
||||
FTP, Telnet, similar, and run an expect-like script.
|
||||
|
||||
- `telnet_session()`
|
||||
|
||||
Wrapper for the above three in one API.
|
||||
|
||||
- `tempfile()`
|
||||
|
||||
Secure replacement for `tmpfile()`. Creates an invisible temporary
|
||||
@@ -303,6 +337,11 @@ Generic Functions
|
||||
**Note:** `which("/bin/ps aux")` will return `/bin/ps`, or `TRUE`,
|
||||
provided of course `/bin/ps` exists.
|
||||
|
||||
- `yorn(fmt, ...)`
|
||||
|
||||
Pose a question to user, appended with `(y/N)?`, returns `TRUE` for
|
||||
yes (both `y` and `Y` are handled) and `FALSE` for everything else.
|
||||
|
||||
|
||||
GNU Functions
|
||||
-------------
|
||||
@@ -384,10 +423,18 @@ as a light weight utility library, these days NetBSD should also work.
|
||||
sudo make install-strip
|
||||
sudo ldconfig
|
||||
|
||||
**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.
|
||||
**Note:** When checking out code from GIT, use <kbd>./autogen.sh</kbd>
|
||||
to generate a `configure` script. It is a generated file and otherwise
|
||||
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
|
||||
[2]: http://www.openbsd.org/
|
||||
@@ -400,3 +447,8 @@ included in released tarballs.
|
||||
[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
|
||||
[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
|
||||
+4
-2
@@ -1,4 +1,5 @@
|
||||
AC_INIT(libite, 2.0.1, https://github.com/troglobit/libite/issues)
|
||||
AC_INIT(libite, 2.2.0, https://github.com/troglobit/libite/issues)
|
||||
AC_CONFIG_AUX_DIR(aux)
|
||||
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz])
|
||||
AM_SILENT_RULES([yes])
|
||||
|
||||
@@ -8,7 +9,8 @@ AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile libite.pc])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
AC_PROG_CC
|
||||
AM_PROG_AR
|
||||
AC_PROG_INSTALL
|
||||
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
|
||||
LT_INIT
|
||||
|
||||
AC_OUTPUT
|
||||
+5
-2
@@ -1,6 +1,9 @@
|
||||
*.log
|
||||
*.substvars
|
||||
.debhelper/*
|
||||
tmp/*
|
||||
libuev/*
|
||||
libuev*
|
||||
libite5/*
|
||||
libite-dev/*
|
||||
autoreconf*
|
||||
debhelper*
|
||||
files
|
||||
|
||||
Vendored
+45
@@ -1,3 +1,47 @@
|
||||
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
|
||||
|
||||
* Fix upgrade of base package, new library name to match SONAME
|
||||
breaks upgrade from libite_2.0.x.deb to libite5_2.1.x.deb
|
||||
|
||||
-- Joachim Nilsson <troglobit@gmail.com> Sat, 22 Feb 2020 15:04:27 +0100
|
||||
|
||||
libite (2.1.1) stable; urgency=medium
|
||||
|
||||
* Fix to chomp(), ensure stopping before beginning of string
|
||||
* Added example of printhdr()
|
||||
* Update copyright years
|
||||
* Add missing libite5.symbols file, found by lintian
|
||||
* Fix package short description, found by linitian
|
||||
|
||||
-- Joachim Nilsson <troglobit@gmail.com> Sat, 22 Feb 2020 13:52:24 +0100
|
||||
|
||||
libite (2.1.0) unstable; urgency=medium
|
||||
|
||||
* New functions; strmatch(), strnmatch(), yorn(), telnet expect APIs
|
||||
* Fixes to pidfile_signal(), strtonum() and C++ linking
|
||||
|
||||
-- Joachim Nilsson <troglobit@gmail.com> Mon, 26 Aug 2019 20:21:46 +0200
|
||||
|
||||
libite (2.0.2) unstable; urgency=medium
|
||||
|
||||
* Fix issues with using `strlite.h` standalone
|
||||
* Fix build issue with `strtonum.c` older GLIBC
|
||||
|
||||
-- Joachim Nilsson <troglobit@gmail.com> Thu, 10 May 2018 19:12:57 +0200
|
||||
|
||||
libite (2.0.1-1) unstable; urgency=medium
|
||||
|
||||
* New upstream release, v2.0.1, fixes to:
|
||||
@@ -5,6 +49,7 @@ libite (2.0.1-1) unstable; urgency=medium
|
||||
- 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
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
9
|
||||
10
|
||||
Vendored
+25
-21
@@ -1,29 +1,29 @@
|
||||
Source: libite
|
||||
Priority: optional
|
||||
Maintainer: Joachim Nilsson <troglobit@gmail.com>
|
||||
Build-Depends: dpkg-dev (>= 1.14.9), debhelper (>= 9), dh-autoreconf
|
||||
Standards-Version: 3.9.6
|
||||
Build-Depends: debhelper (>= 10), libtool
|
||||
Standards-Version: 4.3.0
|
||||
Section: libs
|
||||
Homepage: https://github.com/troglobit/libite/
|
||||
Vcs-Git: https://github.com/troglobit/libite.git
|
||||
Vcs-Browser: https://github.com/troglobit/libite/
|
||||
|
||||
Package: libite-dev
|
||||
Priority: extra
|
||||
Priority: optional
|
||||
Section: libdevel
|
||||
Architecture: any
|
||||
Depends: ${misc:Depends}, libite (= ${binary:Version})
|
||||
Depends: ${misc:Depends}, libite5 (= ${binary:Version})
|
||||
Description: static library, header files, and docs for libite
|
||||
Static library, header files, and documentation for libite.
|
||||
.
|
||||
Libite is a lightweight library of frog DNA. It can be used to fill the
|
||||
gaps in any dinosaur project. It holds useful functions and macros
|
||||
developed by both Finit and the OpenBSD project. Most notably the
|
||||
Libite is a lightweight library of frog DNA. It can be used to fill
|
||||
the gaps in any dinosaur project. It holds useful functions and macros
|
||||
developed by both Finit and the OpenBSD project. Most notably the
|
||||
string functions: strlcpy(3), strlcat(3) and the highly useful *BSD
|
||||
sys/queue.h and sys/tree.h API's.
|
||||
.
|
||||
Libite is the frog DNA missing in GNU libc. However, -lite does not aim
|
||||
to become another GLIB! One noticeable gap in GLIBC is the missing
|
||||
Libite is the frog DNA missing in GNU libc. However, -lite does not
|
||||
aim to become another GLIB! 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.
|
||||
.
|
||||
@@ -31,21 +31,25 @@ Description: static library, header files, and docs for libite
|
||||
license used by OpenBSD, and BSD licenses, all of them are extremely
|
||||
liberal and can be used freely in proprietary software if needed.
|
||||
|
||||
Package: libite
|
||||
Package: libite5
|
||||
Replaces: libite
|
||||
Conflicts: libite
|
||||
Provides: libite
|
||||
Architecture: any
|
||||
Depends: ${misc:Depends}, ${shlibs:Depends}
|
||||
Description: That missing frog DNA you've been looking for. MIT/X11/ISC/BSD License.
|
||||
Libite is a lightweight library of frog DNA. It can be used to fill the
|
||||
gaps in any dinosaur project. It holds useful functions and macros
|
||||
developed by both Finit and the OpenBSD project. Most notably the
|
||||
string functions: strlcpy(3), strlcat(3) and the highly useful *BSD
|
||||
sys/queue.h and sys/tree.h API's.
|
||||
Description: That missing frog DNA you've been looking for
|
||||
Libite, or -lite, is a lightweight library of frog DNA. It can be used
|
||||
to fill the gaps in any dinosaur project. It holds useful functions
|
||||
and macros developed by both Finit and the OpenBSD project. Most
|
||||
notably the string functions: strlcpy(3), strlcat(3) and the highly
|
||||
useful *BSD sys/queue.h and sys/tree.h API's.
|
||||
.
|
||||
Libite is the frog DNA missing in GNU libc. However, -lite does not aim
|
||||
to become another GLIB! One noticeable gap in GLIBC is the missing
|
||||
Libite is the frog DNA missing in GNU libc. However, -lite does not
|
||||
aim to become another GLIB! 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.
|
||||
.
|
||||
The code is open sourced under a mix of the MIT/X11 license, the ISC
|
||||
license used by OpenBSD, and BSD licenses, all of them are extremely
|
||||
liberal and can be used freely in proprietary software if needed.
|
||||
The code is open source software under a mix of the MIT/X11 license,
|
||||
the ISC license used by OpenBSD, and BSD licenses, all of them are
|
||||
extremely liberal and can be used freely in proprietary software if
|
||||
needed.
|
||||
Vendored
+24
-12
@@ -4,7 +4,7 @@ Source: https.//github.com/troglobit/libite/
|
||||
Files: *
|
||||
Copyright:
|
||||
2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
|
||||
2008-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||
2008-2020 Joachim Nilsson <troglobit@gmail.com>
|
||||
License: MIT
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -25,19 +25,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
Files: chomp.c
|
||||
Copyright: 2014-2015 Joachim Nilsson <troglobit@gmail.com>
|
||||
Copyright: 2014-2020 Joachim Nilsson <troglobit@gmail.com>
|
||||
License: ISC
|
||||
|
||||
Files: conio.h
|
||||
Copyright: 2009-2013 Joachim Nilsson <troglobit@gmail.com>
|
||||
Copyright: 2009-2020 Joachim Nilsson <troglobit@gmail.com>
|
||||
License: ISC
|
||||
|
||||
Files: dir.c
|
||||
Copyright: 2008-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||
Copyright: 2008-2020 Joachim Nilsson <troglobit@gmail.com>
|
||||
License: ISC
|
||||
|
||||
Files: lfile.c
|
||||
Copyright: 2015-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||
Copyright: 2015-2020 Joachim Nilsson <troglobit@gmail.com>
|
||||
License: ISC
|
||||
|
||||
Files: pidfile.c
|
||||
@@ -53,7 +53,7 @@ Copyright: 2008 Otto Moerbeek <otto@drijf.net>
|
||||
License: ISC
|
||||
|
||||
Files: rsync.c
|
||||
Copyright: 2011, 2012 Joachim Nilsson <troglobit@gmail.com>
|
||||
Copyright: 2011-2020 Joachim Nilsson <troglobit@gmail.com>
|
||||
License: ISC
|
||||
|
||||
Files: strdupa.h strndupa.h
|
||||
@@ -61,23 +61,35 @@ Copyright: 2009 William Ahern
|
||||
License: MIT
|
||||
|
||||
Files: strlcat.c strlcpy.c
|
||||
Copyright: 998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
Copyright: 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
License: MIT
|
||||
|
||||
Files: strmatch.c
|
||||
Copyright: 2009-2020 Joachim Nilsson <troglobit@gmail.com>
|
||||
License: ISC
|
||||
|
||||
Files: strnlen.c
|
||||
Copyright: 2016 Joachim Nilsson <troglobit@gmail.com>
|
||||
Copyright: 2016-2020 Joachim Nilsson <troglobit@gmail.com>
|
||||
License: ISC
|
||||
|
||||
Files: strtonum.c
|
||||
Copyright: 2004 Ted Unangst and Todd Miller
|
||||
License: ISC
|
||||
|
||||
Files: tempfile.c
|
||||
Copyright: 2015-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||
Files: telnet.c
|
||||
Copyright: 2010-2020 Joachim Nilsson <troglobit@gmail.com>
|
||||
License: ISC
|
||||
|
||||
Files: tree.c
|
||||
Copyright: 2015 Joachim Nilsson <troglobit@gmail.com>
|
||||
Files: tempfile.c
|
||||
Copyright: 2015-2020 Joachim Nilsson <troglobit@gmail.com>
|
||||
License: ISC
|
||||
|
||||
Files: tree.h
|
||||
Copyright: 2002 Niels Provos <provos@citi.umich.edu>
|
||||
License: BSD-2-clause
|
||||
|
||||
Files: yorn.c
|
||||
Copyright: 2009-2020 Joachim Nilsson <troglobit@gmail.com>
|
||||
License: ISC
|
||||
|
||||
Files: tests/*.c
|
||||
|
||||
File renamed without changes.
File renamed without changes.
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
libite.so.5 libite5 #MINVER#
|
||||
* Build-Depends-Package: libite-dev
|
||||
__pidfile_name@Base 2.0.0
|
||||
__pidfile_path@Base 2.0.0
|
||||
chomp@Base 2.0.0
|
||||
copyfile@Base 2.0.0
|
||||
dir@Base 2.0.0
|
||||
fcopyfile@Base 2.0.0
|
||||
fexist@Base 2.0.0
|
||||
fgetint@Base 2.0.0
|
||||
fisdir@Base 2.0.0
|
||||
fmkpath@Base 2.2.0
|
||||
fopenf@Base 2.2.0
|
||||
fparseln@Base 2.0.0
|
||||
fsendfile@Base 2.0.0
|
||||
ifconfig@Base 2.0.0
|
||||
initscr@Base 2.0.0
|
||||
lfclose@Base 2.0.0
|
||||
lfgetint@Base 2.0.0
|
||||
lfgetkey@Base 2.0.0
|
||||
lfopen@Base 2.0.0
|
||||
lftok@Base 2.0.0
|
||||
makepath@Base 2.0.0
|
||||
mkpath@Base 2.0.0
|
||||
movefile@Base 2.0.0
|
||||
pidfile@Base 2.0.0
|
||||
pidfile_poll@Base 2.0.0
|
||||
pidfile_read@Base 2.0.0
|
||||
pidfile_signal@Base 2.1.0
|
||||
progress@Base 2.0.0
|
||||
progress_simple@Base 2.0.0
|
||||
reallocarray@Base 2.0.0
|
||||
rsync@Base 2.0.0
|
||||
sdbuf@Base 2.0.0
|
||||
strlcat@Base 2.0.0
|
||||
strlcpy@Base 2.0.0
|
||||
strmatch@Base 2.1.0
|
||||
strnmatch@Base 2.1.0
|
||||
strtonum@Base 2.1.0
|
||||
systemf@Base 2.2.0
|
||||
telnet_close@Base 2.1.0
|
||||
telnet_expect@Base 2.1.0
|
||||
telnet_open@Base 2.1.0
|
||||
telnet_session@Base 2.1.0
|
||||
tempfile@Base 2.0.0
|
||||
which@Base 2.0.0
|
||||
whichp@Base 2.0.0
|
||||
yorn@Base 2.1.0
|
||||
Vendored
+7
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/make -f
|
||||
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
|
||||
|
||||
# Uncomment this to turn on verbose mode.
|
||||
#export DH_VERBOSE=1
|
||||
@@ -6,3 +7,9 @@
|
||||
%:
|
||||
dh $@ --with autoreconf
|
||||
|
||||
override_dh_auto_install:
|
||||
dh_auto_install
|
||||
-rm -f debian/libite/usr/share/doc/libite/LICENSE
|
||||
|
||||
override_dh_installchangelogs:
|
||||
dh_installchangelogs ChangeLog.md
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
compression=xz
|
||||
@@ -0,0 +1,3 @@
|
||||
*.la
|
||||
.libs/*
|
||||
libite_la*
|
||||
+7
-4
@@ -2,10 +2,10 @@ lib_LTLIBRARIES = libite.la
|
||||
|
||||
libite_la_CPPFLAGS = -D_GNU_SOURCE
|
||||
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 \
|
||||
conio.c conio.h \
|
||||
dir.c \
|
||||
dir.c fopenf.c \
|
||||
fexist.c fisdir.c \
|
||||
fparseln.c fsendfile.c \
|
||||
ifconfig.c lfile.c \
|
||||
@@ -14,11 +14,14 @@ libite_la_SOURCES = chomp.c copyfile.c \
|
||||
reallocarray.c rsync.c \
|
||||
strlcpy.c strlcat.c strtonum.c \
|
||||
strdupa.h strndupa.h strnlen.h \
|
||||
tempfile.c which.c \
|
||||
strmatch.c systemf.c \
|
||||
telnet.c tempfile.c \
|
||||
yorn.c which.c \
|
||||
lite.h strlite.h \
|
||||
queue.h tree.h
|
||||
|
||||
|
||||
## Distribute these header files in the <lite/...> name space
|
||||
pkgincludedir = $(includedir)/lite
|
||||
pkginclude_HEADERS = lite.h queue.h conio.h tree.h strlite.h strdupa.h strndupa.h strnlen.h
|
||||
pkginclude_HEADERS = lite.h queue.h conio.h tree.h strlite.h strdupa.h \
|
||||
strndupa.h strnlen.h
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
/* Perl inspired chomp() implementation.
|
||||
*
|
||||
* Copyright (c) 2014-2015 Joachim Nilsson <troglobit@gmail.com>
|
||||
* Copyright (c) 2014-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
|
||||
@@ -23,7 +23,7 @@
|
||||
* @str: String to chomp
|
||||
*
|
||||
* This function is like Perl chomp, but it's set to chop of all
|
||||
* trailing newlines.
|
||||
* trailing newlines. Useful in combination with fgets().
|
||||
*
|
||||
* Returns:
|
||||
* If @str is a valid pointer this function returns @str, otherwise
|
||||
@@ -39,7 +39,7 @@ char *chomp(char *str)
|
||||
}
|
||||
|
||||
p = str + strlen(str) - 1;
|
||||
while (*p == '\n')
|
||||
while (p >= str && *p == '\n')
|
||||
*p-- = 0;
|
||||
|
||||
return str;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/* A conio.h like implementation for VTANSI displays.
|
||||
*
|
||||
* Copyright (c) 2009-2017 Joachim Nilsson <troglobit@gmail.com>
|
||||
* Copyright (c) 2009-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
|
||||
|
||||
+28
-6
@@ -1,6 +1,6 @@
|
||||
/* A conio.h like implementation for VTANSI displays.
|
||||
*
|
||||
* Copyright (c) 2009-2017 Joachim Nilsson <troglobit@gmail.com>
|
||||
* Copyright (c) 2009-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
|
||||
@@ -15,6 +15,11 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef CONIO_H_
|
||||
#define CONIO_H_
|
||||
|
||||
@@ -77,17 +82,34 @@
|
||||
|
||||
void initscr(int *row, int *col);
|
||||
|
||||
/* Print table heading @line to @fp, with optional leading newline */
|
||||
/* Print table heading @line to @fp, with optional leading newline
|
||||
* Example:
|
||||
* _________________ <-- Empty line with UNDERSCORE to frame first heading
|
||||
* First heading <-- In normal/RESETATTR
|
||||
* SUBHEADING <-- In REVERSE and with capital letters like 'top'
|
||||
*/
|
||||
static inline void printhdr(FILE *fp, const char *line, int nl, int attr)
|
||||
{
|
||||
if (attr < 0 || attr > 8)
|
||||
attr = REVERSE;
|
||||
|
||||
fprintf(fp ?: stdout,
|
||||
"%s\033[%dm%s%*s\033[0m\n",
|
||||
nl ? "\n" : "", attr, line,
|
||||
SCREEN_WIDTH - (int)strlen(line), "");
|
||||
}
|
||||
|
||||
static inline void printheader(FILE *fp, const char *line, int nl)
|
||||
{
|
||||
fprintf(fp ?: stdout,
|
||||
"%s\033[7m%s%*s\033[0m\n",
|
||||
nl ? "\n" : "",
|
||||
line, SCREEN_WIDTH - (int)strlen(line), "");
|
||||
printhdr(fp, line, nl, REVERSE);
|
||||
}
|
||||
|
||||
#endif /* CONIO_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
|
||||
+3
-1
@@ -85,7 +85,9 @@ static void set_mtime(int in, int out)
|
||||
struct stat st;
|
||||
struct timespec tv[2];
|
||||
|
||||
fstat(in, &st);
|
||||
if (fstat(in, &st))
|
||||
return;
|
||||
|
||||
tv[0] = st.st_atim;
|
||||
tv[1] = st.st_mtim;
|
||||
futimens(out, tv);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* Functions for operating on files in directories.
|
||||
*
|
||||
* Copyright (c) 2008-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||
* Copyright (c) 2008-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
|
||||
|
||||
+5
-5
@@ -25,17 +25,17 @@
|
||||
#include <unistd.h>
|
||||
|
||||
/**
|
||||
* fexist - Check if a file exists and is a directory.
|
||||
* @file: File to look for, with full path.
|
||||
* fisdir - Check if a path exists and is a directory.
|
||||
* @path: Path to file or directory
|
||||
*
|
||||
* Returns:
|
||||
* %TRUE(1) if the file exists and is a directory, otherwise %FALSE(0).
|
||||
* %TRUE(1) if @path exists and is a directory, otherwise %FALSE(0).
|
||||
*/
|
||||
int fisdir(const char *file)
|
||||
int fisdir(const char *path)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (!stat(file, &sb) && S_ISDIR(sb.st_mode))
|
||||
if (!stat(path, &sb) && S_ISDIR(sb.st_mode))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -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:
|
||||
*/
|
||||
+2
-2
@@ -51,8 +51,8 @@ ssize_t fsendfile(FILE *src, FILE *dst, size_t len)
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf = (char *)malloc(BUFSIZ);
|
||||
|
||||
buf = malloc(BUFSIZ);
|
||||
if (!buf)
|
||||
return -1;
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
/* Fastinit (finit) ifconfig() implementation.
|
||||
*
|
||||
* Copyright (c) 2008 Claudio Matsuoka <http://helllabs.org/finit/>
|
||||
* Copyright (C) 2009-2014 Joachim Nilsson <joachim.nilsson@westermo.se>
|
||||
* Copyright (c) 2008-2010 Claudio Matsuoka <http://helllabs.org/finit/>
|
||||
* Copyright (C) 2009-2020 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
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/* Parse UNIX /etc configuration files like /etc/protocols and /etc/services
|
||||
*
|
||||
* Copyright (c) 2015-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||
* Copyright (c) 2015-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
|
||||
|
||||
+23
-2
@@ -1,7 +1,7 @@
|
||||
/* Collection of frog DNA
|
||||
*
|
||||
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
|
||||
* Copyright (c) 2008-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||
* Copyright (c) 2008-2020 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
|
||||
@@ -22,6 +22,11 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef LITE_H_
|
||||
#define LITE_H_
|
||||
|
||||
@@ -52,13 +57,15 @@
|
||||
#define LITE_FOPT_KEEP_MTIME 0x02
|
||||
|
||||
typedef struct lfile lfile_t;
|
||||
typedef struct sdbuf sdbuf_t;
|
||||
|
||||
char *chomp (char *str);
|
||||
char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
|
||||
|
||||
int fexist (const char *file);
|
||||
int fisdir (const char *file);
|
||||
int fisdir (const char *path);
|
||||
|
||||
FILE *fopenf (const char *mode, const char *fmt, ...);
|
||||
FILE *tempfile (void);
|
||||
ssize_t copyfile (const char *src, const char *dst, int len, int opt);
|
||||
int movefile (const char *src, const char *dst);
|
||||
@@ -74,6 +81,7 @@ 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 fmkpath (mode_t mode, const char *fmt, ...);
|
||||
int mkpath (const char *dir, mode_t mode);
|
||||
int makepath (const char *dir);
|
||||
|
||||
@@ -90,6 +98,15 @@ void *reallocarray(void *optr, size_t nmemb, size_t size);
|
||||
void progress (int percent, int max_width);
|
||||
void progress_simple(int percent);
|
||||
|
||||
int systemf (const char *fmt, ...);
|
||||
|
||||
sdbuf_t*telnet_open (int addr, short port);
|
||||
int telnet_close (sdbuf_t *ctx);
|
||||
int telnet_expect (sdbuf_t *ctx, char *script[], FILE *output);
|
||||
int telnet_session (int addr, short port, char *script[], FILE *output);
|
||||
|
||||
int yorn (const char *fmt, ...);
|
||||
|
||||
char *which (const char *cmd);
|
||||
int whichp (const char *cmd);
|
||||
|
||||
@@ -183,6 +200,10 @@ static inline int fisslashdir(const char *dir)
|
||||
|
||||
#endif /* LITE_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <libgen.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include "lite.h"
|
||||
@@ -46,6 +48,38 @@ int mkpath(const char *dir, mode_t 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.
|
||||
* @dir: Directory to create.
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
/* Functions for dealing with PID files (client side)
|
||||
*
|
||||
* Copyright (c) 2009-2015 Joachim Nilsson <troglobit@gmail.com>
|
||||
* Copyright (c) 2009-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
|
||||
@@ -111,10 +111,10 @@ int pidfile_signal(const char *pidfile, int signal)
|
||||
return 1;
|
||||
|
||||
ret = kill(pid, signal);
|
||||
if ((ret == -1) || (signal == SIGTERM) || (signal == SIGKILL))
|
||||
(void)remove(pidfile);
|
||||
if (!ret && signal == SIGKILL)
|
||||
ret = remove(pidfile);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/* Simple termios based progress bar
|
||||
*
|
||||
* Copyright (c) 2012-2015 Joachim Nilsson <troglobit@gmail.com>
|
||||
* Copyright (c) 2012-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
|
||||
|
||||
@@ -32,6 +32,11 @@
|
||||
* @(#)queue.h 8.5 (Berkeley) 8/20/94
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef _SYS_QUEUE_H_
|
||||
#define _SYS_QUEUE_H_
|
||||
|
||||
@@ -531,3 +536,7 @@ struct { \
|
||||
} while (0)
|
||||
|
||||
#endif /* !_SYS_QUEUE_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+8
-6
@@ -1,6 +1,6 @@
|
||||
/* Micro "rsync" implementation.
|
||||
*
|
||||
* Copyright (c) 2011, 2012 Joachim Nilsson <troglobit@gmail.com>
|
||||
* Copyright (c) 2011-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
|
||||
@@ -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]);
|
||||
if (fisdir(source)) {
|
||||
char dst2[256];
|
||||
struct stat st;
|
||||
struct stat sb;
|
||||
|
||||
strcat(source, "/");
|
||||
if (stat(source, &st))
|
||||
return 1;
|
||||
if (stat(source, &sb)) {
|
||||
result++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mdir(dst2, sizeof(dst2), dst, files[i], &st)) {
|
||||
if (mdir(dst2, sizeof(dst2), dst, files[i], &sb)) {
|
||||
result++;
|
||||
continue;
|
||||
}
|
||||
|
||||
rsync(source, dst2, opt, filter);
|
||||
if (keep_mtim)
|
||||
set_mtime(dst2, &st);
|
||||
set_mtime(dst2, &sb);
|
||||
|
||||
continue; /* Next file/dir in @src to copy... */
|
||||
}
|
||||
|
||||
@@ -23,6 +23,12 @@
|
||||
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
* ==========================================================================
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef LITE_STRDUPA_H
|
||||
#define LITE_STRDUPA_H
|
||||
|
||||
@@ -50,3 +56,7 @@
|
||||
#endif /* !HAVE_STRDUPA */
|
||||
|
||||
#endif /* LITE_STRDUPA_H */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+16
-1
@@ -1,6 +1,6 @@
|
||||
/* Collection of frog DNA
|
||||
*
|
||||
* Copyright (c) 2008-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||
* Copyright (c) 2008-2020 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
|
||||
@@ -21,10 +21,18 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef LITE_STRING_H_
|
||||
#define LITE_STRING_H_
|
||||
|
||||
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, INT32_MAX, etc. */
|
||||
#include <string.h>
|
||||
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
|
||||
|
||||
#include "strdupa.h"
|
||||
#include "strndupa.h"
|
||||
#include "strnlen.h"
|
||||
@@ -46,6 +54,9 @@
|
||||
})
|
||||
#endif
|
||||
|
||||
int strnmatch (const char *str, const char **list, size_t num);
|
||||
int strmatch (const char *str, const char **list);
|
||||
|
||||
#ifndef strlcpy
|
||||
size_t strlcpy (char *dst, const char *src, size_t siz);
|
||||
#endif
|
||||
@@ -100,3 +111,7 @@ static inline int string_case_compare(const char *a, const char *b)
|
||||
}
|
||||
|
||||
#endif /* LITE_STRING_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,89 @@
|
||||
/* Simple string matcher function, finds partial matches.
|
||||
*
|
||||
* Copyright (c) 2009-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 <string.h>
|
||||
|
||||
|
||||
/**
|
||||
* strnmatch - Finds matching strings from a finite list
|
||||
* @str: String to look for
|
||||
* @list: List of strings to search.
|
||||
* @num: Number of entries in @list.
|
||||
*
|
||||
* This function searches the @list of strings for @str. If a (partial) match
|
||||
* is found it returns the index in the @list.
|
||||
*
|
||||
* Very similar in function to strmatch(), but works for sets of strings that
|
||||
* are not %NULL terminated.
|
||||
*
|
||||
* Returns:
|
||||
* -1 on error, otherwise the index to the matching string.
|
||||
*/
|
||||
int strnmatch(const char *str, const char **list, size_t num)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!str || !list) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
if (!strncasecmp (str, list[i], strlen (str)))
|
||||
return i;
|
||||
}
|
||||
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* strmatch - Finds matching strings from a list
|
||||
* @str: String to look for
|
||||
* @list: %NULL terminated list of strings to search.
|
||||
*
|
||||
* This function searches the @list of strings for @str. If a (partial) match
|
||||
* is found it returns the index in the @list.
|
||||
*
|
||||
* Please note, the @list MUST be terminated by a %NULL element. If that is
|
||||
* not possible for you, we recommend using strnmatch() instead.
|
||||
*
|
||||
* Returns:
|
||||
* -1 on error, otherwise the index to the matching string.
|
||||
*/
|
||||
int strmatch(const char *str, const char **list)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!list) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; list[i]; i++)
|
||||
;
|
||||
|
||||
return strnmatch(str, list, i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
@@ -23,6 +23,12 @@
|
||||
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
* ==========================================================================
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef LITE_STRNDUPA_H_
|
||||
#define LITE_STRNDUPA_H_
|
||||
|
||||
@@ -51,3 +57,7 @@
|
||||
#endif /* !HAVE_STRNDUPA */
|
||||
|
||||
#endif /* GNU_STRING_STRNDUPA_H */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+10
-1
@@ -1,6 +1,6 @@
|
||||
/* strnlen.h - Re-implementation of GLIBC strnlen()
|
||||
*
|
||||
* Copyright (c) 2016 Joachim Nilsson <troglobit@gmail.com>
|
||||
* Copyright (c) 2016-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
|
||||
@@ -15,6 +15,11 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef LITE_STRNLEN_H_
|
||||
#define LITE_STRNLEN_H_
|
||||
|
||||
@@ -41,3 +46,7 @@ static inline size_t xstrnlen(const char *str, size_t lim)
|
||||
#endif
|
||||
|
||||
#endif /* LITE_STRNLEN_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+10
-1
@@ -26,6 +26,15 @@
|
||||
#define TOOSMALL 2
|
||||
#define TOOLARGE 3
|
||||
|
||||
#ifndef LLONG_MAX
|
||||
# define LLONG_MAX 0x7fffffffffffffffLL
|
||||
#endif
|
||||
|
||||
#ifndef LLONG_MIN
|
||||
# define LLONG_MIN (-0x7fffffffffffffffLL - 1)
|
||||
#endif
|
||||
|
||||
|
||||
long long
|
||||
strtonum(const char *numstr, long long minval, long long maxval,
|
||||
const char **errstrp)
|
||||
@@ -49,7 +58,7 @@ strtonum(const char *numstr, long long minval, long long maxval,
|
||||
error = INVALID;
|
||||
} else {
|
||||
ll = strtoll(numstr, &ep, 10);
|
||||
if (numstr == ep || *ep != '\0')
|
||||
if (errno == EINVAL || numstr == ep || *ep != '\0')
|
||||
error = INVALID;
|
||||
else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
|
||||
error = TOOSMALL;
|
||||
|
||||
@@ -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:
|
||||
*/
|
||||
+291
@@ -0,0 +1,291 @@
|
||||
/* Poor mans telnet expect in C.
|
||||
*
|
||||
* Copyright (c) 2010-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 <poll.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "lite.h"
|
||||
|
||||
#define EXPECT_DEBUG 0
|
||||
#define EXPECT_POLL_TIMEOUT 3000 /* 3 sec timeout waiting for server. */
|
||||
|
||||
#if EXPECT_DEBUG
|
||||
# define TELL(fmt, args...) fprintf (stderr, fmt "\n", ##args)
|
||||
#else
|
||||
# define TELL(fmt, args...)
|
||||
#endif
|
||||
|
||||
struct sdbuf {
|
||||
int sd;
|
||||
char *buf;
|
||||
} sdbuf;
|
||||
|
||||
/* Open telnet connection to @addr:@port and connect. */
|
||||
sdbuf_t *telnet_open(int addr, short port)
|
||||
{
|
||||
struct sockaddr_in *sin;
|
||||
struct sockaddr s;
|
||||
sdbuf_t *ctx;
|
||||
int saved_errno;
|
||||
|
||||
ctx = (sdbuf_t *)malloc(sizeof(sdbuf_t));
|
||||
if (!ctx) {
|
||||
// perror("Failed allocating expect ctxect");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->buf = (char *)malloc(BUFSIZ);
|
||||
if (!ctx->buf) {
|
||||
// perror("Failed allocating expect buffer");
|
||||
free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->sd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if (-1 == ctx->sd) {
|
||||
saved_errno = errno;
|
||||
// perror ("Failed creating socket");
|
||||
free(ctx->buf);
|
||||
free(ctx);
|
||||
|
||||
errno = saved_errno;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sin = (struct sockaddr_in *)&s;
|
||||
sin->sin_family = AF_INET;
|
||||
sin->sin_port = port;
|
||||
sin->sin_addr.s_addr = addr;
|
||||
if (-1 == connect(ctx->sd, &s, sizeof(s))) {
|
||||
saved_errno = errno;
|
||||
// perror ("Cannot connect to telnet daemon");
|
||||
telnet_close(ctx);
|
||||
errno = saved_errno;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
int telnet_close(sdbuf_t *ctx)
|
||||
{
|
||||
free(ctx->buf);
|
||||
close(ctx->sd);
|
||||
free(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wait_substr(sdbuf_t *ctx, char *str)
|
||||
{
|
||||
struct pollfd pfd = { ctx->sd, POLLIN, 0 };
|
||||
ssize_t len, tot = 0;
|
||||
int err;
|
||||
|
||||
while (1) {
|
||||
err = poll(&pfd, 1, EXPECT_POLL_TIMEOUT);
|
||||
if (err <= 0) {
|
||||
if (0 == err)
|
||||
errno = ETIMEDOUT;
|
||||
|
||||
if (EINTR == errno)
|
||||
continue;
|
||||
|
||||
// perror("No prompt");
|
||||
return 1;
|
||||
}
|
||||
|
||||
len = read(ctx->sd, &ctx->buf[tot], BUFSIZ);
|
||||
if (len <= 0) {
|
||||
errno = ENOMSG;
|
||||
return 1;
|
||||
}
|
||||
|
||||
tot += len;
|
||||
ctx->buf[tot] = 0;
|
||||
TELL("Got line: '%s' is it '%s'?", ctx->buf, str);
|
||||
|
||||
if (strstr(ctx->buf, str))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* telnet_expect - Poor man's telnet expect
|
||||
* @ctx: Telnet session context from telnet_open()
|
||||
* @script: %NULL terminated list of expect and response strings
|
||||
* @output: Optional output from session
|
||||
*
|
||||
* Issues @script sequence on telnet session specified in @ctx, with
|
||||
* optional @output from session.
|
||||
*
|
||||
* The @script consists of strings of expect and response pairs. For
|
||||
* example, expect "ogin: " followed by response "root\n", expect
|
||||
* "assword: "with response "secret\n", concluded by %NULL.
|
||||
*
|
||||
* Returns:
|
||||
* POSIX OK(0) or non-zero on error.
|
||||
*/
|
||||
int telnet_expect(sdbuf_t *ctx, char *script[], FILE *output)
|
||||
{
|
||||
struct pollfd fd = { ctx->sd, POLLIN, 0 };
|
||||
ssize_t len;
|
||||
int i, first = 1, cont = 1, result = 0;
|
||||
|
||||
for (i = 0; script[i]; i++) {
|
||||
/* when expecting the empty string, just wipe any available input */
|
||||
if (!strlen(script[i])) {
|
||||
result = poll(&fd, 1, 0);
|
||||
if (result > 0)
|
||||
lseek(ctx->sd, 0, SEEK_END);
|
||||
} else {
|
||||
if (wait_substr(ctx, script[i])) {
|
||||
result = ENOMSG;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
if (strlen(script[i])) {
|
||||
TELL("Sending line: '%s'", script[i]);
|
||||
if (-1 == write(ctx->sd, script[i], strlen(script[i]))) {
|
||||
errno = ENOSPC;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (cont) {
|
||||
char *ptr = ctx->buf;
|
||||
char *tmp;
|
||||
|
||||
result = poll(&fd, 1, EXPECT_POLL_TIMEOUT);
|
||||
if (result <= 0) {
|
||||
if (0 == result)
|
||||
errno = ETIMEDOUT;
|
||||
|
||||
if (EINTR == errno)
|
||||
continue;
|
||||
|
||||
// perror ("No result");
|
||||
result = errno;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* On VERY long outputs we need to send some love back to the
|
||||
* server, otherwise it terminates the connection. --Jocke
|
||||
*/
|
||||
if (-1 == write(ctx->sd, "\n", 1))
|
||||
goto retry;
|
||||
|
||||
len = read(ctx->sd, ctx->buf, BUFSIZ);
|
||||
if (len == -1) {
|
||||
retry:
|
||||
if (EINTR == errno)
|
||||
continue;
|
||||
|
||||
result = errno;
|
||||
break;
|
||||
}
|
||||
ctx->buf[len] = 0;
|
||||
|
||||
TELL("Read line: '%s'", ctx->buf);
|
||||
|
||||
/* Skip first line -- only an echo of the last command */
|
||||
if (first) {
|
||||
first = 0;
|
||||
ptr = strchr(ctx->buf, '\n');
|
||||
if (ptr)
|
||||
ptr++;
|
||||
else
|
||||
ptr = ctx->buf;
|
||||
}
|
||||
|
||||
TELL("Comparing '%s' with '%s'", ptr, script[i - 2]);
|
||||
|
||||
/* Skip last line -- only the returning prompt. */
|
||||
tmp = strstr(ptr, script[i - 2]);
|
||||
if (tmp) {
|
||||
TELL("OK, last line. Good bye!");
|
||||
result = 0;
|
||||
cont = 0;
|
||||
*tmp = 0;
|
||||
|
||||
tmp = strrchr(ptr, '\n');
|
||||
if (tmp)
|
||||
*++tmp = 0;
|
||||
}
|
||||
|
||||
if (output && *ptr) {
|
||||
if (EOF == fputs(ptr, output)) {
|
||||
/* Only happens when /tmp is full :( */
|
||||
result = ENOSPC;
|
||||
/* We must complete read-out of descriptor */
|
||||
output = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* telnet_session - Very simple expect-like implementation for telnet.
|
||||
* @addr: Must be in network byte order, use htonl().
|
||||
* @port: IP port to connect to, use htons().
|
||||
* @script: Expect like script of paired 'expect', 'response' strings.
|
||||
* @output: A &FILE pointer to a tmpfile() for output from the last command.
|
||||
*
|
||||
* This is a very simple expect-like implementation for querying and
|
||||
* operating daemons remotely over telnet.
|
||||
*
|
||||
* The @script is a query-response type of list of strings leading up to
|
||||
* a final command, which output is then written to the given @output file.
|
||||
*
|
||||
* Returns:
|
||||
* POSIX OK(0), or non-zero with errno set on error.
|
||||
*/
|
||||
int telnet_session(int addr, short port, char *script[], FILE *output)
|
||||
{
|
||||
sdbuf_t *sdbuf;
|
||||
int result = 0;
|
||||
|
||||
sdbuf = telnet_open(addr, port);
|
||||
if (!sdbuf)
|
||||
return errno;
|
||||
|
||||
if (telnet_expect(sdbuf, script, output))
|
||||
result = errno;
|
||||
|
||||
telnet_close(sdbuf);
|
||||
|
||||
return errno = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/* A secure tmpfile() replacement.
|
||||
*
|
||||
* Copyright (c) 2015-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||
* Copyright (c) 2015-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
|
||||
|
||||
@@ -24,6 +24,11 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifndef _SYS_TREE_H_
|
||||
#define _SYS_TREE_H_
|
||||
|
||||
@@ -746,3 +751,7 @@ name##_RB_MINMAX(struct name *head, int val) \
|
||||
(x) = (y))
|
||||
|
||||
#endif /* _SYS_TREE_H_ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/* C implementation of UNIX which(1)
|
||||
*
|
||||
* Copyright (c) 2017 Joachim Nilsson <troglobit@gmail.com>
|
||||
* Copyright (c) 2017-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
|
||||
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
/* Safe yes-or-no with prompt
|
||||
*
|
||||
* Copyright (c) 2009-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 <stdio_ext.h> /* __fpurge() */
|
||||
#include <stdarg.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static char rawgetch(void)
|
||||
{
|
||||
struct termios savemodes, modmodes;
|
||||
char val;
|
||||
|
||||
if (!isatty(STDIN_FILENO))
|
||||
return getchar();
|
||||
|
||||
/* Backup terminal settings. */
|
||||
if (tcgetattr(STDIN_FILENO, &savemodes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* "stty cbreak -echo" */
|
||||
modmodes = savemodes;
|
||||
modmodes.c_lflag &= ~ICANON;
|
||||
modmodes.c_lflag &= ~ECHO;
|
||||
modmodes.c_cc[VMIN] = 1;
|
||||
modmodes.c_cc[VTIME] = 0;
|
||||
|
||||
/* Set terminal in raw mode. */
|
||||
if (tcsetattr(STDIN_FILENO, TCSANOW, &modmodes) < 0) {
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &savemodes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
val = getchar();
|
||||
|
||||
/* Restore terminal to previous state. */
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &savemodes);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* yorn - Pose a a Yes or No question and return answer
|
||||
* @fmt: Standard printf() style argument(s).
|
||||
*
|
||||
* This function prints the given question on screen, waits for user
|
||||
* input in the form of yes or no.
|
||||
*
|
||||
* Returns:
|
||||
* True(1) or False(0). True if the answer is yes.
|
||||
*/
|
||||
int yorn(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char yorn;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
__fpurge(stdin);
|
||||
yorn = rawgetch();
|
||||
printf("%c\n", yorn);
|
||||
fflush(stdout);
|
||||
if (yorn != 'y' && yorn != 'Y')
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
@@ -1,17 +1,25 @@
|
||||
*.o
|
||||
*.log
|
||||
*.trs
|
||||
.deps/
|
||||
chomp
|
||||
copyfile
|
||||
dir
|
||||
fexist
|
||||
fisdir
|
||||
fopenf
|
||||
fsendfile
|
||||
lfile
|
||||
makepath
|
||||
pidfile
|
||||
printhdr
|
||||
progress
|
||||
rsync
|
||||
str
|
||||
strmatch
|
||||
systemf
|
||||
tempfile
|
||||
touch
|
||||
tree
|
||||
which
|
||||
yorn
|
||||
+7
-1
@@ -7,15 +7,21 @@ TESTS += copyfile
|
||||
TESTS += dir
|
||||
TESTS += fexist
|
||||
TESTS += fisdir
|
||||
TESTS += fopenf
|
||||
TESTS += fsendfile
|
||||
TESTS += lfile
|
||||
TESTS += makepath
|
||||
TESTS += pidfile
|
||||
TESTS += touch
|
||||
TESTS += printhdr
|
||||
TESTS += progress
|
||||
TESTS += rsync
|
||||
TESTS += str
|
||||
TESTS += strmatch
|
||||
TESTS += systemf
|
||||
TESTS += touch
|
||||
TESTS += tempfile
|
||||
TESTS += which
|
||||
TESTS += yorn
|
||||
|
||||
check_PROGRAMS = $(TESTS)
|
||||
|
||||
|
||||
@@ -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 "check.h"
|
||||
|
||||
#define BASEDIR "/tmp/libite-test"
|
||||
|
||||
int checkpath(const char *dir)
|
||||
{
|
||||
char tmp[256];
|
||||
@@ -32,28 +34,48 @@ int test_makepath(const char *dir)
|
||||
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 i, ret = 0;
|
||||
char *list[] = {
|
||||
"/tmp/libite-test/tok/",
|
||||
"/tmp/libite-test/tok2",
|
||||
"/tmp/libite-test/ab",
|
||||
"/tmp/libite-test/b",
|
||||
"/tmp/libite-test/a/",
|
||||
"/tmp/libite-test/a/b",
|
||||
"/tmp/libite-test/a/c/",
|
||||
BASEDIR "/tok/",
|
||||
BASEDIR "/tok2",
|
||||
BASEDIR "/ab",
|
||||
BASEDIR "/b",
|
||||
BASEDIR "/a/",
|
||||
BASEDIR "/a/b",
|
||||
BASEDIR "/a/c/",
|
||||
NULL
|
||||
};
|
||||
|
||||
printf("Testing makepath() ...\n");
|
||||
mkdir("/tmp/libite-test", 0755);
|
||||
mkdir(BASEDIR, 0755);
|
||||
|
||||
printf("PASS 1/2: makepath() ======================================\n");
|
||||
for (i = 0; list[i] && !ret; i++)
|
||||
ret |= test_makepath(list[i]);
|
||||
|
||||
printf("\nCleaning up ...\n");
|
||||
system("rm -rf /tmp/libite-test");
|
||||
printf("PASS 2/2: fmkpath() =======================================\n");
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <stdlib.h> /* atexit() */
|
||||
#include <unistd.h> /* usleep() */
|
||||
|
||||
#include "check.h"
|
||||
|
||||
#define SCREEN_WIDTH 80
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FILE *fp = stderr;
|
||||
char buf[SCREEN_WIDTH];
|
||||
|
||||
printhdr(fp, "", 0, UNDERSCORE);
|
||||
printhdr(fp, "Neighbor Table", 0, 0);
|
||||
snprintf(buf, sizeof(buf), "%-15s %-15s %7s %-5s%10s %6s",
|
||||
"Neighbor", "Interface", "Version", "Flags", "Uptime", "Expire");
|
||||
printhdr(fp, buf, 0, REVERSE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#include "../src/strlite.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char buf[10];
|
||||
int val;
|
||||
|
||||
val = atonum("42");
|
||||
if (val != 42)
|
||||
return 1;
|
||||
|
||||
if (!string_match("eth1", "eth1234"))
|
||||
return 1;
|
||||
|
||||
if (string_compare("eth1", "eth1234"))
|
||||
return 1;
|
||||
|
||||
if (!string_case_compare("somestring", "SoMeSTRING"))
|
||||
return 1;
|
||||
|
||||
strlcpy(buf, "tooloongstring", sizeof(buf));
|
||||
if (buf[9] == 'r')
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "check.h"
|
||||
#define SYSLOG_NAMES
|
||||
#include <syslog.h>
|
||||
|
||||
#define SEVERITY_LEVEL { \
|
||||
CHOOSE(SEVERITY_NONE, "none"), \
|
||||
CHOOSE(SEVERITY_DEBUG, "debug"), \
|
||||
CHOOSE(SEVERITY_INFO, "info"), \
|
||||
CHOOSE(SEVERITY_NOTICE, "notice"), \
|
||||
CHOOSE(SEVERITY_WARNING, "warning"), \
|
||||
CHOOSE(SEVERITY_ERR, "err"), \
|
||||
CHOOSE(SEVERITY_CRIT, "crit"), \
|
||||
CHOOSE(SEVERITY_ALERT, "alert"), \
|
||||
CHOOSE(SEVERITY_EMERG, "emerg") \
|
||||
}
|
||||
|
||||
#define CHOOSE(a, b) b
|
||||
const char *levels[] = SEVERITY_LEVEL;
|
||||
|
||||
#undef CHOOSE
|
||||
#define CHOOSE(a, b) a
|
||||
typedef enum SEVERITY_LEVEL severity_level_t;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
size_t i;
|
||||
int num;
|
||||
struct {
|
||||
char *str;
|
||||
int val;
|
||||
} t[] = {
|
||||
{ "warn", SEVERITY_WARNING },
|
||||
{ "alert", SEVERITY_ALERT },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
for (i = 0; t[i].str; i++) {
|
||||
num = strmatch(t[i].str, levels);
|
||||
fail_unless(num >= 0);
|
||||
fail_unless(num == t[i].val);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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:
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "check.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int chan[2];
|
||||
int status;
|
||||
|
||||
pipe(chan);
|
||||
|
||||
if (fork() > 0) {
|
||||
dup2(chan[0], STDIN_FILENO);
|
||||
if (yorn("Do you really wanna do this (y/N)? ")) {
|
||||
printf("Affirmative!\n");
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
printf("OK, aborting!\n");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
if (write(chan[1], "Y", 1) != 1)
|
||||
return 1;
|
||||
|
||||
wait(&status);
|
||||
|
||||
return WEXITSTATUS(status);
|
||||
}
|
||||
Reference in new issue
Block a user