Compare commits

...
133 Commits
Author SHA1 Message Date
Joachim Nilsson 20d8d40285 Update changelogs and bump version for v2.1.2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 15:06:28 +01:00
Joachim Nilsson 4dc24f37e3 debian: Fix breakage when upgrading libite -> libite5
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 15:05:56 +01:00
Joachim Nilsson 11f8846f63 Update changelogs and bump version for v2.1.1 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 13:57:39 +01:00
Joachim Nilsson 41778fb3ce debian: Add missing symbols file, pointed out by lintian
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 13:57:39 +01:00
Joachim Nilsson 59d1f0d60c Update .gitignore files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 13:57:39 +01:00
Joachim Nilsson afc4289326 debian: Fix lintian warning for package short description
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 13:57:39 +01:00
Joachim Nilsson 67267659f7 configure: Put auxilliary files in aux and check for install
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 13:57:39 +01:00
Joachim Nilsson 188509d811 debian: Update changelog for 2.1.1 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 13:57:39 +01:00
Joachim Nilsson c10cd67266 Update release hook and fix formatting in release target
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 13:57:39 +01:00
Joachim Nilsson 82db75cac6 debian: Update to Standards-Version 4.3.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 12:46:14 +01:00
Joachim Nilsson 51970ff86e Update copyright years
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 11:32:43 +01:00
Joachim Nilsson d6fa3cde96 Update ChangeLog for v2.1.1 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 11:17:14 +01:00
Joachim Nilsson 9d50de3ec7 tests: Add example of how to use printhdr()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 11:14:27 +01:00
Joachim Nilsson 2aed5a6b3f chomp: Check for beginning of string while removing \n's
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-09-25 08:51:56 +02:00
Joachim Nilsson f873635cfe Bump version for v2.1.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-08-26 21:59:57 +02:00
Joachim Nilsson c3d5588298 Prepare ChangeLogs for next release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-08-26 21:59:11 +02:00
Joachim Nilsson a65b2dfd71 debian: Update copyright, new files, and fix year
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-08-26 21:59:11 +02:00
Joachim Nilsson 6e8d8fc32c debian: Drop LICENSE file and install ChangeLog.md
The LICENSE file is replaced with copyright in Debian

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-08-26 21:59:11 +02:00
Joachim Nilsson 966aee09cd Install ChangeLog.md in doc/, debian supports this now
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-08-26 21:59:11 +02:00
Joachim Nilsson f93e298875 debian: Update package descriptions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-08-26 21:59:11 +02:00
Joachim Nilsson c8ec83f20c debian: Update to standards version 4.1.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-08-26 21:59:11 +02:00
Joachim Nilsson 835e09a9fe debian: Step library name to match SONAME, fixes lintian warning
This patch fixes the lintian warning package-name-doesnt-match-sonames,
which is a reminder to step the library version to match the soname.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-08-26 21:59:05 +02:00
Joachim Nilsson 13ffe87d10 tests: Update unit test for string functions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-08-22 22:26:07 +02:00
Joachim Nilsson 72d1cb6501 Add printhdr(), replacement for printheader() with ANSI attribute
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-08-21 23:57:29 +02:00
Joachim Nilsson 83ace4f12d ChangeLog: Add missing telnet APIs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-08-21 16:07:44 +02:00
Joachim Nilsson 9bdc5e94b5 Update ChangeLog with latest fixes & feature
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-08-19 23:51:50 +02:00
Joachim Nilsson 83047d4413 Add support for a simple telnet expect set of APIs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-06-09 18:06:47 +02:00
Joachim Nilsson b2c2d032e8 Add support for yorn(), safe yes-or-no prompt
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-05-29 15:57:11 +02:00
Joachim Nilsson 7f053f7624 Fix #13: Support C-linkage for C++ compilation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-05-24 21:57:57 +02:00
Joachim Nilsson b15a14e920 strtonum(): POSIX strtoll() returns EINVAL, check for that too
From FreeBSD.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-12-10 09:43:20 +01:00
Joachim Nilsson 7e8534e36b pidfile_signal(): Return result of kill() and only remove on SIGKILL
If kill() is successful, and the signal was SIGKILL, we remove() the PID
file and return the rc of remove(), otherwise we always return the rc of
kill().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-22 13:08:19 +02:00
Joachim Nilsson 3989d91d36 Minor, refactor and fix function doc comment
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-07-22 14:46:08 +02:00
Joachim Nilsson fe3673a5e1 Mention new strnmatch() API family
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-07-05 22:47:28 +02:00
Joachim Nilsson 1bdcb1bfe4 Document new functions: strmatch(), strnmatch()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-07-03 17:09:42 +02:00
Joachim Nilsson 75d3f1978e Minor, grammar
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-07-02 17:48:43 +02:00
Joachim Nilsson c07bfbda58 Bump version for v2.1.0 release cycle
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-07-02 16:39:50 +02:00
Joachim Nilsson 0ef509c393 Minor, reorder tests alphabetically
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-07-02 16:38:47 +02:00
Joachim Nilsson 5620faf7bf Add unit test for strmatch()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-07-02 16:38:39 +02:00
Joachim Nilsson b6a9ed3c6d New function(s): strnmatch() and strmatch()
These two functions look for a string in a (terminate) list of strings
and returns the index to that string, or -1 if not found or error.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-06-29 18:38:56 +02:00
Joachim Nilsson 9d63302337 Minor, whitespace + simplify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-06-29 18:35:52 +02:00
Joachim Nilsson 02d9d9f8c1 Update ChangeLog and bump version for v2.0.2 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-05-10 19:13:56 +02:00
Joachim Nilsson 9f92a9d572 Fix #12: Add missing includes for INT32_MAX and MIN()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-05-10 19:06:07 +02:00
Joachim Nilsson f0e3ed3342 Add basic unit test for strlite.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-05-10 19:05:48 +02:00
Joachim Nilsson 34f23a77f8 Missing defines for LLONG_MAX and LLONG_MIN
Some systems may not yet have defined LLONG_MAX and LLONG_MIN in
limits.h, in particular older GLIBC installs are affected.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-02-28 10:43:08 +01:00
Joachim Nilsson 261cf3a01b debian/changelog; Update for new upstream release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 12:12:34 +01:00
Joachim Nilsson 2c9c13bd07 Update ChangeLog for v2.0.1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 12:08:05 +01:00
Joachim Nilsson 59ce0c0dc4 Minor ABI bump, changes to lite.h, const + fixed up touch()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 12:08:05 +01:00
Joachim Nilsson a603208da9 Redo 60406c3, this is a bug-fix release only: 2.1.0-pre --> 2.0.1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 12:08:05 +01:00
Joachim Nilsson eaac01871b Simplify introduction, and tone it down a bit ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 12:08:05 +01:00
Joachim Nilsson 8cefa12675 Remove Emacs hinting
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 12:08:05 +01:00
Joachim Nilsson 5893010074 Move TODO items to TODO.md
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 12:08:05 +01:00
Joachim Nilsson d84bcb3847 copyfile(),movefile(): constify
A `const` string is a declaration to the user of an API that the
implementation does not touch the contents.

We do some `(char *)` casting in this patch, but the resulting
code still does not touch the contents of the original pointer.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 11:34:46 +01:00
Joachim Nilsson a9a3a2dda1 constify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 11:34:24 +01:00
Joachim Nilsson 20af39300c ifconfig(): constify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 11:33:55 +01:00
Joachim Nilsson 7b612cda83 lfile: constify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 11:33:37 +01:00
Joachim Nilsson 60406c33f6 Bump version, -pre, for v2.1.0 release cycle
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 10:57:37 +01:00
Joachim Nilsson 1d21b11802 lftok(): Refactor, collapse and simplify a bit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 10:56:54 +01:00
Joachim Nilsson a3badc85f8 Fix FTBFS, add missing fcntl.h header for AT_FDCWD
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-21 17:15:39 +01:00
Joachim Nilsson ac936448f5 Only define min() and max() macros if not already defined
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-21 14:19:45 +01:00
Joachim Nilsson 3a26ab28b2 Fix #11: Allow relative paths to touch()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-21 14:17:43 +01:00
Joachim Nilsson 123108fbf9 Fix #10: Supply a default PATH for test
Set a default PATH matching the root user's defaults.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-07 23:09:19 +01:00
Joachim Nilsson 3545d63d2e Fix #9: Use /usr/bin/which, not /bin/which, for unit test.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-07 22:15:40 +01:00
Joachim Nilsson 3e921d72e5 conio.h: Add initscr() declaration after relocation to conio.c
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 15:39:16 +01:00
Joachim Nilsson 1c9c038c06 Update copyfile() and rsync() API descriptions, new option flags
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 14:18:27 +01:00
Joachim Nilsson e5b79443b8 Bump version for v2.0.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 14:01:44 +01:00
Joachim Nilsson 589465f48b Update ChangeLog for v2.0.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 14:01:44 +01:00
Joachim Nilsson 1f745ff9a0 Add head-up to users about changes in v2.0 early in text
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 13:58:01 +01:00
Joachim Nilsson 71a0c53029 Bump ABI version, major changes in this release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 13:57:44 +01:00
Joachim Nilsson 6608d2e8c9 Remove tree() from libite, moved to troglobit/toolbox.git instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 13:49:05 +01:00
Joachim Nilsson 62334c80fd Remove fmode() from libite, it's safer to use stat() instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 12:51:49 +01:00
Joachim Nilsson 626d5456f7 copyfile(): Reduce dependency and simplify, already called stat()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 12:49:49 +01:00
Joachim Nilsson e3dff8e5be Reorder source files, sort of alphabetically
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 12:46:39 +01:00
Joachim Nilsson bbb951dc23 conio.h: Move initscr() function to conio.c
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 10:28:07 +01:00
Joachim Nilsson 94800e7d5c Use distcheck in release target, verifies generated tarball is buildable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 09:04:28 +01:00
Joachim Nilsson 3442d8e12b Update unit test suite with new path to library and header files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 09:03:54 +01:00
Joachim Nilsson 75f57283bd Don't guess where conio.h is, rely on check.h instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 09:02:51 +01:00
Joachim Nilsson daf41d326b Relocate source files to an src/ sub directory
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 09:02:21 +01:00
Joachim Nilsson 3179be4348 Update ChangeLog, hint at future v2.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-21 23:57:31 +01:00
Joachim Nilsson 56530a8c78 Ignore global indexing files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-20 18:37:59 +01:00
Joachim Nilsson abd6e3abd6 Update rsync() unit test slightly, does not verify MTIME yet ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-20 17:32:31 +01:00
Joachim Nilsson b078a8676f rsync(): Refactor @delete argument into an @opt to keep mtime
This patch changes the @delete rsync() argument to @opt.  The first bit
is reserved for %LITE_FOPT_RSYNC_DELETE, for backwards compatibility.

A new %LITE_FOPT_KEEP_MTIME option is also added.  If set the mtime of
the @src file is set on @dst, both directories and regular files are
fully supported.  However, if the base @dst directory does not exist,
and rsync() has to create it, its mtime will be the time of the last
file copied into it.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-20 17:29:39 +01:00
Joachim Nilsson c2b92a38ef copyfile(): Refactor @sym argument into an @opt to keep mtime
This patch changes the @sym copyfile() argument to @opt.  The first bit
is reserved for %LITE_FOPT_COPYFILE_SYM, for backwards compatibility.

A new %LITE_FOPT_KEEP_MTIME option is also added.  If set the mtime of
the @src file is set on @dst.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-20 17:24:08 +01:00
Joachim Nilsson 98b2e9d426 debian/changelog: New upstream release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 22:43:03 +01:00
Joachim Nilsson 96d3e5dd8b Bump version for v1.9.4 release cycle (-pre)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-16 21:31:33 +01:00
Joachim Nilsson ff626acb73 Update ChangeLog for upcoming v1.9.4
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-16 21:31:20 +01:00
Joachim Nilsson ba3f7c89fb Update makepath() unit test
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-31 21:08:21 +01:00
Joachim Nilsson 714ea88cc9 makepath(): Update doc, recommend mkpath() over this function
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-31 21:08:21 +01:00
Joachim Nilsson add4d5d325 Fix #8: constify mkpath() and makepath()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-31 21:08:21 +01:00
Joachim Nilsson be6f276557 Fix #7: inconsistent return value in mkpath()
When the required `dir` argument is missing `mkpath()` inconsistently
returns 1 instead of -1.  Found by @jesponde

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-31 00:33:19 +01:00
Joachim Nilsson 6daebf4ea4 Bump version for v1.9.3 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 15:56:30 +02:00
Joachim Nilsson 4d6e3e060e Update ChangeLog(s) for v1.9.3
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 15:56:17 +02:00
Joachim Nilsson 86eef8e38d tree(): Increase internal buffer size, result may be truncated
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 08:42:55 +02:00
Joachim Nilsson d5d3dafc78 Slight ABI bump due to changes in initscr()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 08:38:10 +02:00
Joachim Nilsson 2534c398ea initscr(): Use stdout, not stderr, just like other conio.h macros
A program's stderr may have been redirected by the operator.  We want to
query the size of stdout, even though it is buffered, so add fflush() to
handle that.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 08:33:02 +02:00
Joachim Nilsson 3691044007 conio.h: initscr() requires termios.h as well
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 08:32:30 +02:00
Joachim Nilsson 6770dad0cc conio.h: Minor, whitespace only
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 08:32:18 +02:00
Joachim Nilsson ef0db5e766 initscr(): Check if stdin and stdout are TTYs first
Programs that may be called in the background or with the stdin/stdout
redirected are not proper TTYs and we should not try to perform any
tricks on them.  This patch checks isatty() and returns standard term
sizes as a fallback.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 08:31:43 +02:00
Joachim Nilsson 485463c70e Update tree() test, use /usr/sbin instead of /sbin
Seems Debian finally went through with their move to symlink /bin and
/sbin to /usr/bin and /usr/sbin, respectively.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-30 11:13:23 +02:00
Joachim Nilsson 4b77eb1423 Update ChangeLog diff URLs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-22 16:27:08 +02:00
Joachim Nilsson 0b54dc6015 Update Debian packaging, v1.9.2-1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-15 08:15:30 +02:00
Joachim Nilsson 9d6df87d0d Update ChangeLog and bump version for v1.9.2 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:52:29 +02:00
Joachim Nilsson 5b2eee6aff conio.h: Minor refactor, cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:46:49 +02:00
Joachim Nilsson 6904f6e0fe conio.h: Add initscr(), probes terminal rows + cols
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-07 13:19:53 +02:00
Joachim Nilsson 877ba02d13 conio.h: Revert 018e607, fails unit tests
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-07 13:19:23 +02:00
Joachim Nilsson 25dfded835 conio.h: Update copyright years
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-07 12:51:43 +02:00
Joachim Nilsson 1323a88e94 conio.h: Convert printheader() to static inline function
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-07 12:51:25 +02:00
Joachim Nilsson 018e607290 conio.h: Use stderr instead of stdout because it's non-buffered
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-07 11:58:48 +02:00
Joachim Nilsson e48c9c5589 Bump version and update ChangeLog for v1.9.1, minor fix release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-03 12:57:52 +02:00
Joachim Nilsson 2c875afe06 which: Allow which("ps aux"), which skips any arguments to command
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-03 12:48:02 +02:00
Joachim Nilsson 10e4a1d057 Update which() unit test, check for /bin/which and /bin/ps aux
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-03 12:45:33 +02:00
Joachim Nilsson 3dde2922c3 Add whichp() predicate function to which()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-03 12:34:05 +02:00
Joachim Nilsson 4dd9459f65 Update debian/changelog for v1.9.0-1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 19:23:49 +02:00
Joachim Nilsson 7172f487d5 Bump version for v1.9.0 GA release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 19:18:55 +02:00
Joachim Nilsson 4c0967405d Bump ABI version, removed UNUSED() added which(), fixed touch()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 19:18:55 +02:00
Joachim Nilsson fd65af31db Update HACKING document, mostly wrt library versioning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 19:18:55 +02:00
Joachim Nilsson e55976d137 Update ChangeLog for v1.9 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 19:18:55 +02:00
Joachim Nilsson 1b1ffb33f1 Bump version to v1.9 due to new functionality, which()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 16:51:21 +02:00
Joachim Nilsson d018a5215f which.c: C implementation of UNIX which(1)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 16:50:58 +02:00
Joachim Nilsson 0d70c116d7 Update .gitignore files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 16:33:00 +02:00
Joachim Nilsson 32c774deef tree(): Refactor, flatten tree
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 16:32:04 +02:00
Joachim Nilsson 441d5f58d7 Add simple ocular unit test for printheader()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-30 20:28:31 +02:00
Joachim Nilsson 2a59289d53 conio.h: Add top-like heading macro, printheader()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-30 20:27:59 +02:00
Joachim Nilsson f89c3c88de Clear build warnings for unit tests
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-30 17:43:11 +02:00
Joachim Nilsson 705b402344 Remove UNUSED() macro, just use -Wno-unused instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-30 17:36:10 +02:00
Joachim Nilsson fe82ab953c Fix non-writable tempfile(), "rw" --> "w+", found by Westermo
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-18 18:18:08 +02:00
Joachim Nilsson 6ec2a31042 Update tempfile() unit test to detect failed write + read
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-18 18:14:39 +02:00
Joachim Nilsson 9f5e852084 Bump version in preparation for 1.8.4 bug-fix release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-05-20 09:29:26 +02:00
Joachim Nilsson 628c5597b9 Fix issue #6: touch does not update mtime if file exists
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-05-19 17:50:44 +02:00
Joachim Nilsson b7b635a3f4 Add unit test for touch to replicate issue #6
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-05-19 17:50:22 +02:00
Joachim Nilsson dd53c3ae9e Minor refactor of unit tests
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-05-19 17:50:07 +02:00
Joachim Nilsson 16a30a293c Add support for make package to build .deb files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-12 17:43:53 +01:00
Joachim Nilsson 325fcbe149 lite.h: Add whitespace to compat macros, for readability
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-12 17:43:31 +01:00
Joachim Nilsson cbb1604ea0 New release for .deb package, 1.8.3-1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-08 15:22:42 +01:00
70 changed files with 1799 additions and 512 deletions

No files matched your search

+6 -9
View File
@@ -1,12 +1,8 @@
*~ *~
*.d ID
*.o GPATH
*.so GRTAGS
*.so.* GTAGS
*.a
.deps
.libs
tmp/
compile compile
config.* config.*
configure configure
@@ -21,4 +17,5 @@ Makefile.in
aclocal.m4 aclocal.m4
ar-lib ar-lib
autom4te.cache autom4te.cache
libite* test-driver
libite.pc
+137 -7
View File
@@ -3,6 +3,132 @@ 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.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
-----------------------
### Changes
- Add missing `initscr()` declaration, regression in [v2.0.0][]
- Add `#ifdef` guards around `min()` and `max()` macros
- Add `const` to `char *` args in multiple API:s:
- `fexist()`
- `fgetint()`
- `fisslashdir()`
- `copyfile()`
- `movefile()`
- `ifconfig()`
- `lfopen()`
- `lfgetkey()`
- `lfgetint()`
### Fixes
- Fix #9, uncommon location of `which` command in unit test
- Fix #10, supply unit test with a default `$PATH`
- Fix #11, `touch()` command cannot handle relative paths when updating
the mtime of an existing file
[v2.0.0][] - 2017-11-22
-----------------------
### Changes
- Remove `tree()`, moved to toolbox.git instead
- Remove `fmode()`, please use `stat()` instead, it's safer
- Add support for keeping mtime in `copy()` and `rsync()`
- Move source files to an `src/` sub-directory
- Move `initscr()` from `conio.h` to `conio.c`
- Update docs, recommend `mkpath()` over `makepath()`
- Bump ABI version, major changes to library
### Fixes
- Fix #7, inconsistent return value in `mkpath()` and `makepath()`
- Fix #8, constify `mkpath()` and `makepath()`
[v1.9.3][] - 2017-10-24
-----------------------
### Changes
- `initscr()`, use stdout, not stderr, like the rest of the
`conio.h` macros. Also, stderr may be redirected by user
- `tree()`, update unit test, use standard directries
### Fixes
- `initscr()`, verify that both stdin and stdout are real TTYs
before messing up output or blocking on input for the user
- `tree()`, increase internal buffer slightly, output may be
truncated otherwise. Found by GCC 7.2
[v1.9.2][] - 2017-07-09
-----------------------
### Changes
- Add `initscr()` function to query screen size
- Convert `printheader()` to a static inline function
[v1.9.1][] - 2017-07-03
-----------------------
### Changes
- Add missing `whichp()` predicate function to accompany `which()`
- Allow `which("ps aux")`, which skips any arguments to command
[v1.9.0][] - 2017-07-02
-----------------------
### Changes
- Add `which()`, a C implementation of UNIX which(1)
- Add `printheader()`, prints a top-like table heading for client tools
- Remove `UNUSED()` macro, recommended to disable GCC warning instead
### Fixes
- Fix issue #6: `touch()` does not update mtime if file exists
- Fix non-writable `tempfile()`, now with proper unit test
[v1.8.3][] - 2017-01-08 [v1.8.3][] - 2017-01-08
----------------------- -----------------------
@@ -231,7 +357,17 @@ problems this may cause!
Initial extraction of frog DNA from [Finit][]. See [README][] for API details. Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
[UNRELEASED]: https://github.com/troglobit/libite/compare/v1.8.3...HEAD [UNRELEASED]: https://github.com/troglobit/libite/compare/v2.1.2...HEAD
[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
[v1.9.2]: https://github.com/troglobit/libite/compare/v1.9.1...v1.9.2
[v1.9.1]: https://github.com/troglobit/libite/compare/v1.9.0...v1.9.1
[v1.9.0]: https://github.com/troglobit/libite/compare/v1.8.3...v1.9.0
[v1.8.3]: https://github.com/troglobit/libite/compare/v1.8.2...v1.8.3 [v1.8.3]: https://github.com/troglobit/libite/compare/v1.8.2...v1.8.3
[v1.8.2]: https://github.com/troglobit/libite/compare/v1.8.1...v1.8.2 [v1.8.2]: https://github.com/troglobit/libite/compare/v1.8.1...v1.8.2
[v1.8.1]: https://github.com/troglobit/libite/compare/v1.8.0...v1.8.1 [v1.8.1]: https://github.com/troglobit/libite/compare/v1.8.0...v1.8.1
@@ -254,9 +390,3 @@ Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
[Inadyn]: https://github.com/troglobit/inadyn/ [Inadyn]: https://github.com/troglobit/inadyn/
[Mg]: https://github.com/troglobit/mg [Mg]: https://github.com/troglobit/mg
[README]: https://github.com/troglobit/libite/blob/v1.0.0/README.md [README]: https://github.com/troglobit/libite/blob/v1.0.0/README.md
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
+24 -5
View File
@@ -4,9 +4,10 @@ Maintenance and Release Checklist
Maintenance Maintenance
----------- -----------
* Encourage contributors to write tests, in particular for new features
* Run tests regularly, use Travis-CI to do this automatically
* Leverage GitHub issues for milestone planning * Leverage GitHub issues for milestone planning
* Reference issues from GitHub pull requests to alert issue subscribers * Reference issues from GitHub pull requests to alert issue subscribers
* Encourage contributors to write unit tests
* Bump library ABI version just before release! * Bump library ABI version just before release!
@@ -17,6 +18,7 @@ Release Checklist
- Inform users in a plain language of changes and bug fixes - Inform users in a plain language of changes and bug fixes
- Do *not* copy-paste GIT commit logs! - Do *not* copy-paste GIT commit logs!
- Order entrys according to importance, most relevant first - Order entrys according to importance, most relevant first
* Run unit tests: `make check`
* Do we need to bump the ABI version? (Probably, see below) * Do we need to bump the ABI version? (Probably, see below)
* Tag * Tag
* Push last commit(s) *and* tags to GitHub * Push last commit(s) *and* tags to GitHub
@@ -25,7 +27,7 @@ Release Checklist
make distclean make distclean
./autogen.sh ./autogen.sh
./configure ./configure
make release make release
* Create new release in GitHub releases page * Create new release in GitHub releases page
* Copy and paste ChangeLog entry, check any stale links! * Copy and paste ChangeLog entry, check any stale links!
@@ -54,14 +56,31 @@ It must be updated according to the [GNU Libtool recommendations][1]:
release of your software. More frequent updates are unnecessary, and release of your software. More frequent updates are unnecessary, and
only guarantee that the current interface number gets larger faster. only guarantee that the current interface number gets larger faster.
3. If the library *source code has changed at all* since the last update, 3. If the library *source code has changed at all* since the last update,
then increment revision (`c:r:a` --> `c:r+1:a`) then increment revision (`c:r:a` becomes `c:r+1:a`).
4. If any *interfaces have been added, removed, or changed* since last 4. If any *interfaces have been added, removed, or changed* since the
update, increment current, and zero revision (`c:r:a` --> `c+1:0:0`) last update, increment current, and set revision to 0.
5. If any *interfaces have been added* since the last public release, 5. If any *interfaces have been added* since the last public release,
then increment age. then increment age.
6. If any *interfaces have been removed or changed* since the last 6. If any *interfaces have been removed or changed* since the last
public release, then set age to 0. public release, then set age to 0.
The libtool ABI versioning logic is very confusing but works if you just
disable your brain and follow the rules, one by one.
**Example #1:** a new function has been added, none of the existing ones
have changed. The initial version is 1:0:0, we follow the rules above to
the letter: increase revision, increase current and set revision to zero,
and finally increase age. This, rather confusingly, gives us 2:0:1 which
libtool then translates to `libconfuse.so.1.1.0`.
**Example #2:** some existing functions are changed, they now return an
`int` instead of `void`. The initial version is 0:0:0, and we follow the
rules again: increment revision, increment current and set revision to
zero, set age to zero. This gives us 1:0:0, which is then translated to
`libconfuse.so.1.0.0`.
### Note
Usually, non-developers have no interest in running development versions Usually, non-developers have no interest in running development versions
(releases are frequent enough), and developers are expected to know how (releases are frequent enough), and developers are expected to know how
to juggle versions. In such an ideal world, it is good enough to bump to juggle versions. In such an ideal world, it is good enough to bump
+7 -6
View File
@@ -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-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 Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@@ -23,3 +18,9 @@ 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.
+34 -36
View File
@@ -1,52 +1,50 @@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
lib_LTLIBRARIES = libite.la doc_DATA = README.md LICENSE ChangeLog.md
pkgincludedir = $(includedir)/lite EXTRA_DIST = README.md LICENSE ChangeLog.md
pkginclude_HEADERS = lite.h queue.h conio.h tree.h strlite.h strdupa.h strndupa.h strnlen.h
libite_la_SOURCES = chomp.c copyfile.c dir.c fexist.c fisdir.c fmode.c fparseln.c \
fsendfile.c ifconfig.c lfile.c makepath.c pidfile.c pidfilefn.c \
progress.c reallocarray.c rsync.c strlcpy.c strlcat.c strtonum.c \
tempfile.c tree.c
libite_la_CPPFLAGS = -D_GNU_SOURCE
libite_la_CFLAGS = -W -Wall -Wextra
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 3:1:0
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libite.pc pkgconfig_DATA = libite.pc
doc_DATA = README.md LICENSE SUBDIRS = src tests
EXTRA_DIST = README.md LICENSE ChangeLog.md
SUBDIRS = tests
## Generate MD5 checksum file ## Generate MD5 checksum file
MD5 = md5sum MD5 = md5sum
md5-dist: md5-dist:
@for file in $(DIST_ARCHIVES); do \ @for file in $(DIST_ARCHIVES); do \
$(MD5) $$file > $$file.md5; \ $(MD5) $$file > ../$$file.md5; \
done done
## Check if tagged in git ## Check if tagged in git
release-hook: release-hook:
if [ ! `git tag | grep $(PACKAGE_VERSION)` ]; then \ @if [ ! `git tag | grep $(PACKAGE_VERSION)` ]; then \
echo; \ echo; \
printf "\033[1m\033[41mCannot find release tag $(PACKAGE_VERSION)\033[0m\n"; \ printf "\e[1m\e[41mCannot find release tag $(PACKAGE_VERSION)\e[0m\n"; \
printf "\033[1m\033[5mDo release anyway?\033[0m "; read yorn; \ printf "\e[1m\e[5mDo release anyway?\e[0m "; read yorn; \
if [ "$$yorn" != "y" -a "$$yorn" != "Y" ]; then \ if [ "$$yorn" != "y" -a "$$yorn" != "Y" ]; then \
printf "OK, aborting release.\n"; \ printf "OK, aborting release.\n"; \
exit 1; \ exit 1; \
fi; \ fi; \
echo; \ echo; \
else \ else \
echo; \ echo; \
printf "\033[1m\033[42mFound GIT release tag $(PACKAGE_VERSION)\033[0m\n"; \ printf "\e[1m\e[42mFound GIT release tag $(PACKAGE_VERSION)\e[0m\n"; \
printf "\033[1m\033[44m>>Remember to push tags!\033[0m\n"; \ printf "\e[1m\e[44m>>Remember to push tags!\e[0m\n"; \
echo; \ echo; \
fi 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 ## Target to run when building a release
release: dist release-hook md5-dist release: release-hook distcheck package md5-dist
@for file in $(DIST_ARCHIVES); do \ @mv $(DIST_ARCHIVES) ../
printf "$$file \tDistribution tarball\n"; \ @echo
printf "$$file.md5\t"; cat $$file.md5 | cut -f1 -d' '; \ @echo "Resulting release files:"
mv $$file* ../; \ @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 done
+62 -47
View File
@@ -15,27 +15,24 @@ Table of Contents
* [TODO](#todo) * [TODO](#todo)
> **NOTE:** Incompatible changes in v2.0 compared to v1.x!
Introduction Introduction
------------ ------------
Libite is a lightweight library of *frog DNA*. It can be used to fill Libite is a lightweight library of *frog DNA* that can be used to fill
the gaps in any dinosaur project. It holds useful functions and macros the gaps in any dinosaur project. It holds useful functions and macros
developed by both [Finit][1] and the [OpenBSD][2] project. Most notably developed by both [Finit][1] and the [OpenBSD][2] project. Most notably
the string functions: [strlcpy(3)][3], [strlcat(3)][3] and the highly the string functions: [strlcpy(3)][3], [strlcat(3)][3] and the highly
useful *BSD [sys/queue.h][4] and [sys/tree.h][7] API's. useful *BSD [sys/queue.h][4] and [sys/tree.h][7] API's.
Libite is the frog DNA missing in GNU libc. However, -lite does not aim Libite holds many of the missing pieces in GNU libc, although -lite does
to become another [GLIB][5]! One noticeable gap in GLIBC is the missing not aim to become another [GLIB][5]. One noticeable gap in GLIBC is the
`_SAFE` macros in the BSD `sys/queue.h` API &mdash; highly recommended `_SAFE` macros available in the BSD `sys/queue.h` API &mdash; highly
when traversing lists to delete/free nodes. recommended when traversing lists to delete/free nodes.
The code is open sourced under a mix of the [MIT/X11 license][MIT], the The code is open sourced under a mix of permissive Open Source licenses:
[ISC license][ISC] used by OpenBSD, and [BSD licenses][BSD], all of them [MIT/X11 license][MIT], [ISC license][ISC], and [BSD licenses][BSD].
are extremely liberal and can be used freely in proprietary software if
needed.
For an introduction to why Libite happened, and how you can use it, see
[this blog post][6].
Using -lite Using -lite
@@ -143,10 +140,6 @@ Helper Macros
Returns the number of elements in an array. From the great book, The Returns the number of elements in an array. From the great book, The
Practice of Programming, by Kernighan and Pike. Practice of Programming, by Kernighan and Pike.
- `UNUSED(var)`
Shorter and more readable version of `var __attribute__ ((unused))`
Generic Functions Generic Functions
----------------- -----------------
@@ -155,9 +148,18 @@ Generic Functions
Perl like chomp function, chop off last char if newline. Perl like chomp function, chop off last char if newline.
- `copyfile(src, dst, len, symlink)` - `copyfile(src, dst, len, opt)`
Like the shell `cp(1)` and `dd(1),` can also create symlinks. Like the shell `cp(1)` and `dd(1),`, can also copy symlinks and
preserve the mtime of the source file. The opt argument can be
a mask of:
- `LITE_FOPT_COPYFILE_SYM (0x01)`
- `LITE_FOPT_KEEP_MTIME (0x02)`
In releases prior to v2.0 the opt argument was called `symlink`.
The APIs are 100% compatible if the value `1` was used to enable
the symlink option.
- `dir(dir, ext, filter, list, strip)` - `dir(dir, ext, filter, list, strip)`
@@ -179,10 +181,6 @@ 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).
- `fmode(file)`
Returns the `mode_t` bits of a file or directory.
- `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
@@ -272,10 +270,33 @@ Generic Functions
Called multiple times with the same percentage value cause spinner to Called multiple times with the same percentage value cause spinner to
spin. spin.
- `rsync(src, dst, delete, *filter())` - `rsync(src, dst, opt, *filter())`
Very simple `rsync()` to copy files files and directories Very simple `rsync()` to copy files and directories recursively. It
recursively. supports pruning files from the destination tree that do not exist in
the source tree and preserving the mtime of the source files. The opt
argument can be a mask of:
- `LITE_FOPT_RSYNC_DELETE (0x01)`
- `LITE_FOPT_KEEP_MTIME (0x02)`
In releases prior to v2.0 the argument controlling pruning was called
`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.
- `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()` - `tempfile()`
@@ -286,11 +307,20 @@ Generic Functions
**Note:** Requires Linux v3.11, or later, will fall back to the old **Note:** Requires Linux v3.11, or later, will fall back to the old
and unsafe `tmpfile()` on older systems. and unsafe `tmpfile()` on older systems.
- `tree(path, show_perms)` - `which(cmd)`, `whichp(cmd)`
Very simple `/bin/tree` replacement. Draw ASCII tree of `path`, with C implementation of UNIX which(1). Returns a malloc'ed string with the
optional listing of file and directory permissions if `show_perms` is full path to `cmd` on success, otherwise `NULL`.
set. The `path` argument should be a directory.
`whichp()` is a predicate function, returns `TRUE` or `FALSE`.
**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 GNU Functions
@@ -367,40 +397,25 @@ Build & Install
This library was initially built for and developed on GNU/Linux systems This library was initially built for and developed on GNU/Linux systems
as a light weight utility library, these days NetBSD should also work. as a light weight utility library, these days NetBSD should also work.
Libite (LITE) employs the de facto standard GNU configure and build
system:
./configure ./configure
make -j5 make -j5
sudo make install-strip sudo make install-strip
sudo ldconfig sudo ldconfig
**Note:** When checking code from GitHub, use <kbd>./autogen.sh</kbd> to **Note:** When checking out code from GIT, use <kbd>./autogen.sh</kbd>
generate a `configure` script. It is a generated file and otherwise only to generate a `configure` script. It is a generated file and otherwise
included in released tarballs. only included in released tarballs.
TODO
----
- Improve documentation, possibly use kdoc or gdoc2 to generate docs from API.
- Continuously, update OpenBSD functions/macros.
[1]: https://github.com/troglobit/finit [1]: https://github.com/troglobit/finit
[2]: http://www.openbsd.org/ [2]: http://www.openbsd.org/
[3]: http://www.openbsd.org/cgi-bin/man.cgi?query=strlcpy [3]: http://www.openbsd.org/cgi-bin/man.cgi?query=strlcpy
[4]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/LIST_EMPTY.3 [4]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/LIST_EMPTY.3
[5]: https://developer.gnome.org/glib/ [5]: https://developer.gnome.org/glib/
[6]: http://troglobit.com/blog/2015/07/02/howto-using-lite-with-a-git-based-application/
[7]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/SPLAY_FOREACH.3 [7]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/SPLAY_FOREACH.3
[MIT]: https://en.wikipedia.org/wiki/MIT_License [MIT]: https://en.wikipedia.org/wiki/MIT_License
[ISC]: https://en.wikipedia.org/wiki/ISC_license [ISC]: https://en.wikipedia.org/wiki/ISC_license
[BSD]: https://en.wikipedia.org/wiki/BSD_licenses [BSD]: https://en.wikipedia.org/wiki/BSD_licenses
[Travis]: https://travis-ci.org/troglobit/libite [Travis]: https://travis-ci.org/troglobit/libite
[Travis Status]: https://travis-ci.org/troglobit/libite.png?branch=master [Travis Status]: https://travis-ci.org/troglobit/libite.png?branch=master
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
+2 -1
View File
@@ -1,7 +1,8 @@
TODO ... in no particular order TODO ... in no particular order
=============================== ===============================
* Improve documentation, possibly use kdoc or gdoc2 to generate docs from API
* Continuously, update OpenBSD functions/macros
* Investigate adding FreeBSD pidfile_open() et al * Investigate adding FreeBSD pidfile_open() et al
* Investigate FreeBSD libutil library, could be useful for porting between unices * Investigate FreeBSD libutil library, could be useful for porting between unices
+5 -3
View File
@@ -1,13 +1,15 @@
AC_INIT(libite, 1.8.3, https://github.com/troglobit/libite/issues) AC_INIT(libite, 2.1.2, https://github.com/troglobit/libite/issues)
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])
AC_CONFIG_SRCDIR(lite.h) AC_CONFIG_SRCDIR(src/lite.h)
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)
AC_CONFIG_FILES([Makefile tests/Makefile libite.pc]) AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile libite.pc])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
AC_PROG_CC AC_PROG_CC
AC_PROG_INSTALL
AM_PROG_AR AM_PROG_AR
LT_INIT LT_INIT
+5 -2
View File
@@ -1,6 +1,9 @@
*.log
*.substvars
.debhelper/*
tmp/* tmp/*
libuev/* libite5/*
libuev* libite-dev/*
autoreconf* autoreconf*
debhelper* debhelper*
files files
+83
View File
@@ -1,3 +1,86 @@
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:
- touch(), cannot handle relative paths when updating mtime
- unit test for which()
- add missing initscr() declaration in conio.h
- ifdef guards around min()/max() macros
-- Joachim Nilsson <troglobit@gmail.com> Fri, 22 Dec 2017 12:11:41 +0100
libite (2.0.0-1) unstable; urgency=low
* New upstream release, v2.0.0, fixes to:
- makepath(), mkpath()
* Changes to
- rsync(), API changes
- copyfile(), API changes
- tree(), removed from library
- fmode(), removed from library
-- Joachim Nilsson <troglobit@gmail.com> Sun, 19 Nov 2017 22:42:51 +0100
libite (1.9.3-1) unstable; urgency=low
* New upstream release, v1.9.3, fixes to conio.h, initscr() and tree().
-- Joachim Nilsson <troglobit@gmail.com> Tue, 24 Oct 2017 08:49:54 +0200
libite (1.9.2-1) unstable; urgency=low
* New upstream reelase, v1.9.2, see upstream ChangeLog for details.
-- Joachim Nilsson <troglobit@gmail.com> Tue, 15 Aug 2017 08:15:14 +0200
libite (1.9.1-1) unstable; urgency=low
* New upstream reelase, v1.9.1.
-- Joachim Nilsson <troglobit@gmail.com> Sun, 02 Jul 2017 19:23:00 +0100
libite (1.9.0-1) unstable; urgency=low
* New upstream reelase.
-- Joachim Nilsson <troglobit@gmail.com> Sun, 02 Jul 2017 19:23:00 +0100
libite (1.8.3-1) unstable; urgency=low
* New upstream reelase.
-- Joachim Nilsson <troglobit@gmail.com> Sun, 08 Jan 2017 15:22:26 +0100
libite (1.8.2-1) unstable; urgency=low libite (1.8.2-1) unstable; urgency=low
* Initial release. * Initial release.
+1 -1
View File
@@ -1 +1 @@
9 10
+25 -21
View File
@@ -1,29 +1,29 @@
Source: libite Source: libite
Priority: optional Priority: optional
Maintainer: Joachim Nilsson <troglobit@gmail.com> Maintainer: Joachim Nilsson <troglobit@gmail.com>
Build-Depends: dpkg-dev (>= 1.14.9), debhelper (>= 9), dh-autoreconf Build-Depends: debhelper (>= 10)
Standards-Version: 3.9.6 Standards-Version: 4.3.0
Section: libs Section: libs
Homepage: https://github.com/troglobit/libite/ Homepage: https://github.com/troglobit/libite/
Vcs-Git: https://github.com/troglobit/libite.git Vcs-Git: https://github.com/troglobit/libite.git
Vcs-Browser: https://github.com/troglobit/libite/ Vcs-Browser: https://github.com/troglobit/libite/
Package: libite-dev Package: libite-dev
Priority: extra Priority: optional
Section: libdevel Section: libdevel
Architecture: any Architecture: any
Depends: ${misc:Depends}, libite (= ${binary:Version}) Depends: ${misc:Depends}, libite5 (= ${binary:Version})
Description: static library, header files, and docs for libite Description: static library, header files, and docs for libite
Static library, header files, and documentation 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 Libite is a lightweight library of frog DNA. It can be used to fill
gaps in any dinosaur project. It holds useful functions and macros the gaps in any dinosaur project. It holds useful functions and macros
developed by both Finit and the OpenBSD project. Most notably the developed by both Finit and the OpenBSD project. Most notably the
string functions: strlcpy(3), strlcat(3) and the highly useful *BSD string functions: strlcpy(3), strlcat(3) and the highly useful *BSD
sys/queue.h and sys/tree.h API's. sys/queue.h and sys/tree.h API's.
. .
Libite is the frog DNA missing in GNU libc. However, -lite does not aim Libite is the frog DNA missing in GNU libc. However, -lite does not
to become another GLIB! One noticeable gap in GLIBC is the missing 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 _SAFE macros in the BSD sys/queue.h API — highly recommended when
traversing lists to delete/free nodes. 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 license used by OpenBSD, and BSD licenses, all of them are extremely
liberal and can be used freely in proprietary software if needed. liberal and can be used freely in proprietary software if needed.
Package: libite Package: libite5
Replaces: libite
Conflicts: libite
Provides: libite
Architecture: any Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends} Depends: ${misc:Depends}, ${shlibs:Depends}
Description: That missing frog DNA you've been looking for. MIT/X11/ISC/BSD License. Description: That missing frog DNA you've been looking for
Libite is a lightweight library of frog DNA. It can be used to fill the Libite, or -lite, is a lightweight library of frog DNA. It can be used
gaps in any dinosaur project. It holds useful functions and macros to fill the gaps in any dinosaur project. It holds useful functions
developed by both Finit and the OpenBSD project. Most notably the and macros developed by both Finit and the OpenBSD project. Most
string functions: strlcpy(3), strlcat(3) and the highly useful *BSD notably the string functions: strlcpy(3), strlcat(3) and the highly
sys/queue.h and sys/tree.h API's. 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 Libite is the frog DNA missing in GNU libc. However, -lite does not
to become another GLIB! One noticeable gap in GLIBC is the missing 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 _SAFE macros in the BSD sys/queue.h API — highly recommended when
traversing lists to delete/free nodes. traversing lists to delete/free nodes.
. .
The code is open sourced under a mix of the MIT/X11 license, the ISC The code is open source software under a mix of the MIT/X11 license,
license used by OpenBSD, and BSD licenses, all of them are extremely the ISC license used by OpenBSD, and BSD licenses, all of them are
liberal and can be used freely in proprietary software if needed. extremely liberal and can be used freely in proprietary software if
needed.
+24 -12
View File
@@ -4,7 +4,7 @@ Source: https.//github.com/troglobit/libite/
Files: * Files: *
Copyright: Copyright:
2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
2008-2016 Joachim Nilsson <troglobit@gmail.com> 2008-2020 Joachim Nilsson <troglobit@gmail.com>
License: MIT License: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal 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. THE SOFTWARE.
Files: chomp.c Files: chomp.c
Copyright: 2014-2015 Joachim Nilsson <troglobit@gmail.com> Copyright: 2014-2020 Joachim Nilsson <troglobit@gmail.com>
License: ISC License: ISC
Files: conio.h Files: conio.h
Copyright: 2009-2013 Joachim Nilsson <troglobit@gmail.com> Copyright: 2009-2020 Joachim Nilsson <troglobit@gmail.com>
License: ISC License: ISC
Files: dir.c Files: dir.c
Copyright: 2008-2016 Joachim Nilsson <troglobit@gmail.com> Copyright: 2008-2020 Joachim Nilsson <troglobit@gmail.com>
License: ISC License: ISC
Files: lfile.c Files: lfile.c
Copyright: 2015-2016 Joachim Nilsson <troglobit@gmail.com> Copyright: 2015-2020 Joachim Nilsson <troglobit@gmail.com>
License: ISC License: ISC
Files: pidfile.c Files: pidfile.c
@@ -53,7 +53,7 @@ Copyright: 2008 Otto Moerbeek <otto@drijf.net>
License: ISC License: ISC
Files: rsync.c Files: rsync.c
Copyright: 2011, 2012 Joachim Nilsson <troglobit@gmail.com> Copyright: 2011-2020 Joachim Nilsson <troglobit@gmail.com>
License: ISC License: ISC
Files: strdupa.h strndupa.h Files: strdupa.h strndupa.h
@@ -61,23 +61,35 @@ Copyright: 2009 William Ahern
License: MIT License: MIT
Files: strlcat.c strlcpy.c 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 License: MIT
Files: strmatch.c
Copyright: 2009-2020 Joachim Nilsson <troglobit@gmail.com>
License: ISC
Files: strnlen.c Files: strnlen.c
Copyright: 2016 Joachim Nilsson <troglobit@gmail.com> Copyright: 2016-2020 Joachim Nilsson <troglobit@gmail.com>
License: ISC License: ISC
Files: strtonum.c Files: strtonum.c
Copyright: 2004 Ted Unangst and Todd Miller Copyright: 2004 Ted Unangst and Todd Miller
License: ISC License: ISC
Files: tempfile.c Files: telnet.c
Copyright: 2015-2016 Joachim Nilsson <troglobit@gmail.com> Copyright: 2010-2020 Joachim Nilsson <troglobit@gmail.com>
License: ISC License: ISC
Files: tree.c Files: tempfile.c
Copyright: 2015 Joachim Nilsson <troglobit@gmail.com> 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 License: ISC
Files: tests/*.c Files: tests/*.c
View File
File renamed without changes.
View File
File renamed without changes.
+45
View File
@@ -0,0 +1,45 @@
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
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
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
+7
View File
@@ -1,4 +1,5 @@
#!/usr/bin/make -f #!/usr/bin/make -f
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# Uncomment this to turn on verbose mode. # Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1 #export DH_VERBOSE=1
@@ -6,3 +7,9 @@
%: %:
dh $@ --with autoreconf 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
+1
View File
@@ -0,0 +1 @@
compression=xz
-56
View File
@@ -1,56 +0,0 @@
/* File mode bit operations
*
* Copyright (c) 2008 Claudio Matsuoka <http://helllabs.org/finit/>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
/**
* fmode - Return a file's mode bits.
* @file: File to look for, with full path.
*
* Returns:
* The mode bits or zero when @file does not exist and errno set to %ENOENT.
*/
mode_t fmode(char *file)
{
struct stat sb;
if (!file) {
errno = EINVAL;
return 0;
}
if (!stat(file, &sb))
return sb.st_mode;
return 0;
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+3
View File
@@ -0,0 +1,3 @@
*.la
.libs/*
libite_la*
+26
View File
@@ -0,0 +1,26 @@
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_SOURCES = chomp.c copyfile.c \
conio.c conio.h \
dir.c \
fexist.c fisdir.c \
fparseln.c fsendfile.c \
ifconfig.c lfile.c \
makepath.c progress.c \
pidfile.c pidfilefn.c \
reallocarray.c rsync.c \
strlcpy.c strlcat.c strtonum.c \
strdupa.h strndupa.h strnlen.h \
strmatch.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
+3 -3
View File
@@ -1,6 +1,6 @@
/* Perl inspired chomp() implementation. /* 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 * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@@ -23,7 +23,7 @@
* @str: String to chomp * @str: String to chomp
* *
* This function is like Perl chomp, but it's set to chop of all * This function is like Perl chomp, but it's set to chop of all
* trailing newlines. * trailing newlines. Useful in combination with fgets().
* *
* Returns: * Returns:
* If @str is a valid pointer this function returns @str, otherwise * If @str is a valid pointer this function returns @str, otherwise
@@ -39,7 +39,7 @@ char *chomp(char *str)
} }
p = str + strlen(str) - 1; p = str + strlen(str) - 1;
while (*p == '\n') while (p >= str && *p == '\n')
*p-- = 0; *p-- = 0;
return str; return str;
+83
View File
@@ -0,0 +1,83 @@
/* A conio.h like implementation for VTANSI displays.
*
* 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 <poll.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
void initscr(int *row, int *col)
{
if (!row || !col)
return;
#if defined(TCSANOW) && defined(POLLIN)
struct termios tc, saved;
struct pollfd fd = { STDIN_FILENO, POLLIN, 0 };
if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) {
*row = 24;
*col = 80;
return;
}
/* Disable echo to terminal while probing */
tcgetattr(STDOUT_FILENO, &tc);
saved = tc;
tc.c_cflag |= (CLOCAL | CREAD);
tc.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
tcsetattr(STDOUT_FILENO, TCSANOW, &tc);
/*
* Save cursor pos+attr
* Diable top+bottom margins
* Set cursor at the far bottom,right pos
* Query term for resulting pos
*/
fprintf(stdout, "\e7" "\e[r" "\e[999;999H" "\e[6n");
fflush(stdout);
/*
* Wait here for terminal to echo back \e[row,lineR ...
*/
if (poll(&fd, 1, 300) <= 0 || scanf("\e[%d;%dR", row, col) != 2) {
*row = 24;
*col = 80;
}
/*
* Restore above saved cursor pos+attr
*/
fprintf(stdout, "\e8");
fflush(stdout);
/* Restore terminal */
tcsetattr(STDOUT_FILENO, TCSANOW, &saved);
return;
#else
*row = 24;
*col = 80;
#endif
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+55 -18
View File
@@ -1,6 +1,6 @@
/* A conio.h like implementation for VTANSI displays. /* A conio.h like implementation for VTANSI displays.
* *
* Copyright (c) 2009-2013 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 * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * 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. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef CONIO_H_ #ifndef CONIO_H_
#define CONIO_H_ #define CONIO_H_
@@ -48,31 +53,63 @@
#define LIGHTCYAN 0x16 #define LIGHTCYAN 0x16
#define WHITE 0x17 #define WHITE 0x17
/* Esc[2JEsc[1;1H - Clear screen and move cursor to 1,1 (upper left) pos. */ #ifndef SCREEN_WIDTH
#define clrscr() fputs ("\033[2J\033[1;1H", stdout) #define SCREEN_WIDTH 80 /* Override using, e.g. #define SCREEN_WIDTH tty_width() */
/* Esc[K - Erases from the current cursor position to the end of the current line. */ #endif
#define clreol() fputs ("\033[K", stdout)
/* Esc[2K - Erases the entire current line. */
#define delline() fputs ("\033[2K", stdout)
/* Esc[Line;ColumnH - Moves the cursor to the specified position (coordinates) */
#define gotoxy(x,y) printf("\033[%d;%dH", y, x)
/* Esc[?25l (lower case L) - Hide Cursor */
#define hidecursor() fputs ("\033[?25l", stdout)
/* Esc[?25h (lower case H) - Show Cursor */
#define showcursor() fputs ("\033[?25h", stdout)
/* Esc[Value;...;Valuem - Set Graphics Mode */ /* Esc[2JEsc[1;1H - Clear screen and move cursor to 1,1 (upper left) pos. */
#define __set_gm(attr,color,val) \ #define clrscr() fputs("\033[2J\033[1;1H", stdout)
if (!color) \ /* Esc[K - Erases from the current cursor position to the end of the current line. */
printf("\033[%dm", attr); \ #define clreol() fputs("\033[K", stdout)
/* Esc[2K - Erases the entire current line. */
#define delline() fputs("\033[2K", stdout)
/* Esc[Line;ColumnH - Moves the cursor to the specified position (coordinates) */
#define gotoxy(x,y) fprintf(stdout, "\033[%d;%dH", y, x)
/* Esc[?25l (lower case L) - Hide Cursor */
#define hidecursor() fputs("\033[?25l", stdout)
/* Esc[?25h (lower case H) - Show Cursor */
#define showcursor() fputs("\033[?25h", stdout)
/* Esc[Value;...;Valuem - Set Graphics Mode (attr, color, val) */
#define __set_gm(a,c,v) \
if (!c) \
fprintf(stdout, "\033[%dm", a); \
else \ else \
printf("\033[%d;%dm", color & 0x10 ? 1 : 0, (color & 0xF) + val) fprintf(stdout, "\033[%d;%dm", c & 0x10 ? 1 : 0, (c & 0xF) + v)
#define textattr(attr) __set_gm(attr, 0, 0) #define textattr(attr) __set_gm(attr, 0, 0)
#define textcolor(color) __set_gm(RESETATTR, color, 30) #define textcolor(color) __set_gm(RESETATTR, color, 30)
#define textbackground(color) __set_gm(RESETATTR, color, 40) #define textbackground(color) __set_gm(RESETATTR, color, 40)
void initscr(int *row, int *col);
/* 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)
{
printhdr(fp, line, nl, REVERSE);
}
#endif /* CONIO_H_ */ #endif /* CONIO_H_ */
#ifdef __cplusplus
}
#endif
/** /**
* Local Variables: * Local Variables:
* indent-tabs-mode: t * indent-tabs-mode: t
+37 -14
View File
@@ -27,7 +27,7 @@
#include "lite.h" #include "lite.h"
/* Tests if dst is a directory, if so, reallocates dst and appends src filename returning 1 */ /* Tests if dst is a directory, if so, reallocates dst and appends src filename returning 1 */
static int adjust_target(char *src, char **dst) static int adjust_target(const char *src, char **dst)
{ {
int isdir = 0; int isdir = 0;
@@ -36,7 +36,7 @@ static int adjust_target(char *src, char **dst)
char *tmp, *ptr = strrchr(src, '/'); char *tmp, *ptr = strrchr(src, '/');
if (!ptr) if (!ptr)
ptr = src; ptr = (char *)src;
else else
ptr++; ptr++;
@@ -80,26 +80,46 @@ static ssize_t do_copy(int in, int out, size_t num, char *buffer, size_t len)
return size; return size;
} }
static void set_mtime(int in, int out)
{
struct stat st;
struct timespec tv[2];
fstat(in, &st);
tv[0] = st.st_atim;
tv[1] = st.st_mtim;
futimens(out, tv);
}
/** /**
* copyfile - Copy a file to another. * copyfile - Copy a file to another.
* @src: Full path name to source file. * @src: Full path name to source file.
* @dst: Full path name to target file. * @dst: Full path name to target file.
* @len: Number of bytes to copy, zero (0) for entire file. * @len: Number of bytes to copy, zero (0) for entire file.
* @sym: Should symlinks be recreated (1) or followed (0) * @opt: An option mask of %LITE_FOPT_COPYFILE_SYM, %LITE_FOPT_KEEP_MTIME
* *
* This is a C implementation of the command line cp(1) utility. It is one * This is a C implementation of the command line cp(1) utility. It is one
* of the classic missing links in the UNIX C library. This version is from * of the classic missing links in the UNIX C library. This version is from
* the finit project, http://helllabs.org/finit/, which is a reimplementation * the finit project, http://helllabs.org/finit/, which is a reimplementation
* of fastinit for the Asus EeePC. * of fastinit for the Asus EeePC.
* *
* The @opt field replaces the @sym argument in previous releases and
* works as follows. To maintain backwards compatibility with @sym
* the %LITE_FOPT_COPYFILE_SYM maintains a value of 1:
*
* %LITE_FOPT_COPYFILE_SYM: Recreate symlink or follow to copy target
* %LITE_FOPT_KEEP_MTIME: Preserve modification time
*
* Returns: * Returns:
* The number of bytes copied, zero may be error (check errno!), but it * The number of bytes copied, zero may be error (check errno!), but it
* may also indicate that @src was empty. If @src is a directory @errno * may also indicate that @src was empty. If @src is a directory @errno
* will be set to %EISDIR since copyfile() is not recursive. * will be set to %EISDIR since copyfile() is not recursive.
*/ */
ssize_t copyfile(char *src, char *dst, int len, int sym) ssize_t copyfile(const char *src, const char *dst, int len, int opt)
{ {
char *buffer; char *buffer, *dest = (char *)dst;
int sym = (opt & LITE_FOPT_COPYFILE_SYM) != 0;
int keep_mtim = (opt & LITE_FOPT_KEEP_MTIME) != 0;
int in, out, isdir = 0, saved_errno = 0; int in, out, isdir = 0, saved_errno = 0;
size_t num; size_t num;
ssize_t size = 0; ssize_t size = 0;
@@ -117,7 +137,7 @@ ssize_t copyfile(char *src, char *dst, int len, int sym)
} }
/* Check if target is a directory, then append src filename. */ /* Check if target is a directory, then append src filename. */
isdir = adjust_target(src, &dst); isdir = adjust_target(src, &dest);
/* Check if the source file is a symlink ... */ /* Check if the source file is a symlink ... */
if (stat(src, &st)) { if (stat(src, &st)) {
@@ -134,7 +154,7 @@ ssize_t copyfile(char *src, char *dst, int len, int sym)
size = -1; size = -1;
} else { } else {
buffer[size] = 0; buffer[size] = 0;
size = !symlink(buffer, dst); size = !symlink(buffer, dest);
} }
} }
@@ -155,7 +175,7 @@ ssize_t copyfile(char *src, char *dst, int len, int sym)
goto exit; goto exit;
} }
out = open(dst, O_WRONLY | O_CREAT | O_TRUNC, fmode(src)); out = open(dest, O_WRONLY | O_CREAT | O_TRUNC, st.st_mode);
if (out < 0) { if (out < 0) {
close(in); close(in);
saved_errno = errno; saved_errno = errno;
@@ -165,6 +185,8 @@ ssize_t copyfile(char *src, char *dst, int len, int sym)
size = do_copy(in, out, num, buffer, BUFSIZ); size = do_copy(in, out, num, buffer, BUFSIZ);
if (!size && errno) if (!size && errno)
saved_errno = errno; saved_errno = errno;
else if (keep_mtim)
set_mtime(in, out);
close(out); close(out);
close(in); close(in);
@@ -172,7 +194,7 @@ ssize_t copyfile(char *src, char *dst, int len, int sym)
exit: exit:
free(buffer); free(buffer);
if (isdir) if (isdir)
free(dst); free(dest);
errno = saved_errno; errno = saved_errno;
return size; return size;
@@ -194,17 +216,18 @@ exit:
* Returns: * Returns:
* POSIX OK(0), or non-zero with errno set. * POSIX OK(0), or non-zero with errno set.
*/ */
int movefile(char *src, char *dst) int movefile(const char *src, const char *dst)
{ {
char *dest = (char *)dst;
int isdir, result = 0; int isdir, result = 0;
/* Check if target is a directory, then append the src base filename. */ /* Check if target is a directory, then append the src base filename. */
isdir = adjust_target(src, &dst); isdir = adjust_target(src, &dest);
if (rename(src, dst)) { if (rename(src, dest)) {
if (errno == EXDEV) { if (errno == EXDEV) {
errno = 0; errno = 0;
copyfile(src, dst, 0, 1); copyfile(src, dest, 0, 1);
if (errno) if (errno)
result = 1; result = 1;
else else
@@ -215,7 +238,7 @@ int movefile(char *src, char *dst)
} }
if (isdir) if (isdir)
free(dst); free(dest);
return result; return result;
} }
+1 -1
View File
@@ -1,6 +1,6 @@
/* Functions for operating on files in directories. /* 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 * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+1 -1
View File
@@ -31,7 +31,7 @@
* Returns: * Returns:
* %TRUE(1) if the file exists, otherwise %FALSE(0). * %TRUE(1) if the file exists, otherwise %FALSE(0).
*/ */
int fexist(char *file) int fexist(const char *file)
{ {
if (!file) { if (!file) {
errno = EINVAL; errno = EINVAL;
+5 -5
View File
@@ -25,17 +25,17 @@
#include <unistd.h> #include <unistd.h>
/** /**
* fexist - Check if a file exists and is a directory. * fisdir - Check if a path exists and is a directory.
* @file: File to look for, with full path. * @path: Path to file or directory
* *
* Returns: * 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; struct stat sb;
if (!stat(file, &sb) && S_ISDIR(sb.st_mode)) if (!stat(path, &sb) && S_ISDIR(sb.st_mode))
return 1; return 1;
return 0; return 0;
View File
File renamed without changes.
+1 -1
View File
@@ -52,7 +52,7 @@ ssize_t fsendfile(FILE *src, FILE *dst, size_t len)
return -1; return -1;
} }
buf = (char *)malloc(BUFSIZ); buf = malloc(BUFSIZ);
if (!buf) if (!buf)
return -1; return -1;
+3 -3
View File
@@ -1,7 +1,7 @@
/* Fastinit (finit) ifconfig() implementation. /* Fastinit (finit) ifconfig() implementation.
* *
* Copyright (c) 2008 Claudio Matsuoka <http://helllabs.org/finit/> * Copyright (c) 2008-2010 Claudio Matsuoka <http://helllabs.org/finit/>
* Copyright (C) 2009-2014 Joachim Nilsson <joachim.nilsson@westermo.se> * Copyright (C) 2009-2020 Joachim Nilsson <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -43,7 +43,7 @@ extern size_t strlcpy(char *dst, const char *src, size_t siz);
* Returns: * Returns:
* POSIX OK(0) on success, or non-zero on error. * POSIX OK(0) on success, or non-zero on error.
*/ */
int ifconfig(char *ifname, char *addr, char *mask, int up) int ifconfig(const char *ifname, const char *addr, const char *mask, int up)
{ {
int sd, ret = -1; int sd, ret = -1;
struct ifreq ifr; struct ifreq ifr;
+16 -18
View File
@@ -1,6 +1,6 @@
/* Parse UNIX /etc configuration files like /etc/protocols and /etc/services /* 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 * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@@ -24,7 +24,8 @@
typedef struct lfile { typedef struct lfile {
FILE *fp; FILE *fp;
char buf[256]; char buf[256];
char *sep, *save; char *save;
const char *sep;
} lfile_t; } lfile_t;
/** /**
@@ -35,7 +36,7 @@ typedef struct lfile {
* Returns: * Returns:
* Pointer to a &lftile_t parser context, or %NULL on error. * Pointer to a &lftile_t parser context, or %NULL on error.
*/ */
lfile_t *lfopen(char *file, char *sep) lfile_t *lfopen(const char *file, const char *sep)
{ {
lfile_t *lf; lfile_t *lf;
@@ -92,23 +93,20 @@ char *lftok(lfile_t *lf)
} }
token = strtok_r(NULL, lf->sep, &lf->save); token = strtok_r(NULL, lf->sep, &lf->save);
if (!token) { if (token)
while (fgets(lf->buf, sizeof(lf->buf), lf->fp)) { return token;
if (lf->buf[0] == '#')
continue;
token = strtok_r(lf->buf, lf->sep, &lf->save); while (fgets(lf->buf, sizeof(lf->buf), lf->fp)) {
if (!token) if (lf->buf[0] == '#')
continue; continue;
token = strtok_r(lf->buf, lf->sep, &lf->save);
if (token)
return token; return token;
}
errno = ENOENT;
return NULL;
} }
return token; errno = ENOENT;
return NULL;
} }
/** /**
@@ -125,7 +123,7 @@ char *lftok(lfile_t *lf)
* Returns: * Returns:
* The value to @key, or %NULL if not found. * The value to @key, or %NULL if not found.
*/ */
char *lfgetkey(lfile_t *lf, char *key) char *lfgetkey(lfile_t *lf, const char *key)
{ {
char *token; char *token;
@@ -151,7 +149,7 @@ char *lfgetkey(lfile_t *lf, char *key)
* Returns: * Returns:
* The positive integer value for @key, or -1 if not found. * The positive integer value for @key, or -1 if not found.
*/ */
int lfgetint(lfile_t *lf, char *key) int lfgetint(lfile_t *lf, const char *key)
{ {
char *token = lfgetkey(lf, key); char *token = lfgetkey(lf, key);
@@ -173,7 +171,7 @@ int lfgetint(lfile_t *lf, char *key)
* Returns: * Returns:
* The positive integer value for @key, or -1 if not found. * The positive integer value for @key, or -1 if not found.
*/ */
int fgetint(char *file, char *sep, char *key) int fgetint(const char *file, const char *sep, const char *key)
{ {
int val = -1; int val = -1;
lfile_t *lf; lfile_t *lf;
+51 -26
View File
@@ -1,7 +1,7 @@
/* Collection of frog DNA /* Collection of frog DNA
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -22,10 +22,16 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef LITE_H_ #ifndef LITE_H_
#define LITE_H_ #define LITE_H_
#include <errno.h> #include <errno.h>
#include <fcntl.h> /* Definition of AT_* constants for utimensat() */
#include <stdio.h> #include <stdio.h>
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, INT32_MAX, etc. */ #include <stdint.h> /* uint8_t, uint16_t, uint32_t, INT32_MAX, etc. */
#include <sys/stat.h> #include <sys/stat.h>
@@ -43,35 +49,42 @@
#define FPARSELN_UNESCREST 0x08 #define FPARSELN_UNESCREST 0x08
#define FPARSELN_UNESCALL 0x0f #define FPARSELN_UNESCALL 0x0f
/*
* copyfile() and rsync() option flags
*/
#define LITE_FOPT_RSYNC_DELETE 0x01
#define LITE_FOPT_COPYFILE_SYM 0x01
#define LITE_FOPT_KEEP_MTIME 0x02
typedef struct lfile lfile_t; typedef struct lfile lfile_t;
typedef struct sdbuf sdbuf_t;
char *chomp (char *str); char *chomp (char *str);
char *fparseln (FILE *, size_t *, size_t *, const char[3], int); char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
int fexist (char *file); int fexist (const char *file);
int fisdir (const char *file); int fisdir (const char *path);
mode_t fmode (char *file);
FILE *tempfile (void); FILE *tempfile (void);
ssize_t copyfile (char *src, char *dst, int len, int sym); ssize_t copyfile (const char *src, const char *dst, int len, int opt);
int movefile (char *src, char *dst); int movefile (const char *src, const char *dst);
int fcopyfile (FILE *src, FILE *dst); int fcopyfile (FILE *src, FILE *dst);
ssize_t fsendfile (FILE *src, FILE *dst, size_t len); ssize_t fsendfile (FILE *src, FILE *dst, size_t len);
int ifconfig (char *ifname, char *addr, char *mask, int up); int ifconfig (const char *ifname, const char *addr, const char *mask, int up);
lfile_t*lfopen (char *file, char *sep); lfile_t*lfopen (const char *file, const char *sep);
void lfclose (lfile_t *lf); void lfclose (lfile_t *lf);
char *lftok (lfile_t *lf); char *lftok (lfile_t *lf);
char *lfgetkey (lfile_t *lf, char *key); char *lfgetkey (lfile_t *lf, const char *key);
int lfgetint (lfile_t *lf, char *key); int lfgetint (lfile_t *lf, const char *key);
int fgetint (char *file, char *sep, char *key); int fgetint (const char *file, const char *sep, const char *key);
int mkpath (char *dir, mode_t mode); int mkpath (const char *dir, mode_t mode);
int makepath (char *dir); int makepath (const char *dir);
int dir (const char *dir, const char *type, int (*filter) (const char *file), char ***list, int strip); int dir (const char *dir, const char *type, int (*filter) (const char *file), char ***list, int strip);
int rsync (char *src, char *dst, int delete, int (*filter) (const char *file)); int rsync (char *src, char *dst, int opt, int (*filter) (const char *file));
int pidfile (const char *basename); int pidfile (const char *basename);
int pidfile_signal(const char *pidfile, int signal); int pidfile_signal(const char *pidfile, int signal);
@@ -80,16 +93,29 @@ pid_t pidfile_poll (const char *pidfile);
void *reallocarray(void *optr, size_t nmemb, size_t size); void *reallocarray(void *optr, size_t nmemb, size_t size);
int tree(char *path, int show_perms);
void progress (int percent, int max_width); void progress (int percent, int max_width);
void progress_simple(int percent); void progress_simple(int percent);
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);
#ifndef touch #ifndef touch
#include <sys/stat.h> /* utimensat() */
#include <sys/time.h> /* utimensat() on *BSD */
static inline int touch(const char *path) static inline int touch(const char *path)
{ {
if (mknod((path), S_IFREG|0644, 0) && errno != EEXIST) if (mknod((path), S_IFREG|0644, 0)) {
if (errno == EEXIST)
return utimensat(AT_FDCWD, path, NULL, 0);
return -1; return -1;
}
return 0; return 0;
} }
#endif #endif
@@ -151,13 +177,8 @@ static inline int erase(const char *path)
#define NELEMS(array) (sizeof(array) / sizeof(array[0])) #define NELEMS(array) (sizeof(array) / sizeof(array[0]))
#endif #endif
/* Mark a function variable as unused, useful for generic callbacks */
#ifndef UNUSED
#define UNUSED(x) UNUSED_ ## x __attribute__ ((unused))
#endif
/* Does directory end with a slash? */ /* Does directory end with a slash? */
static inline int fisslashdir(char *dir) static inline int fisslashdir(const char *dir)
{ {
if (!dir) if (!dir)
return 0; return 0;
@@ -169,12 +190,16 @@ static inline int fisslashdir(char *dir)
} }
/* Compat */ /* Compat */
#define copy_filep(src,dst) fcopyfile(src,dst) #define copy_filep(src, dst) fcopyfile(src, dst)
#define pidfile_read_pid(file) pifile_read(file) #define pidfile_read_pid(file) pifile_read(file)
#define signal_pidfile(file,signo) pidfile_signal(file,signo) #define signal_pidfile(file, signo) pidfile_signal(file, signo)
#endif /* LITE_H_ */ #endif /* LITE_H_ */
#ifdef __cplusplus
}
#endif
/** /**
* Local Variables: * Local Variables:
* indent-tabs-mode: t * indent-tabs-mode: t
+8 -3
View File
@@ -29,13 +29,13 @@
* Returns: * Returns:
* POSIX OK(0) on success, otherwise -1 with @errno set. * POSIX OK(0) on success, otherwise -1 with @errno set.
*/ */
int mkpath(char *dir, mode_t mode) int mkpath(const char *dir, mode_t mode)
{ {
struct stat sb; struct stat sb;
if (!dir) { if (!dir) {
errno = EINVAL; errno = EINVAL;
return 1; return -1;
} }
if (!stat(dir, &sb)) if (!stat(dir, &sb))
@@ -50,13 +50,18 @@ int mkpath(char *dir, mode_t 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.
* *
* Comment:
* It is recommended to use mkpath() over this function since it has
* the @mode argument while this function instead default ot 0777,
* which in most cases is insecure.
*
* Returns: * Returns:
* POSIX OK (0) on success, otherwise -1 and errno set appropriately. * POSIX OK (0) on success, otherwise -1 and errno set appropriately.
* This function returns EINVAL on bad argument, or ENOMEM when it * This function returns EINVAL on bad argument, or ENOMEM when it
* fails allocating temporary memory. For other error codes see the * fails allocating temporary memory. For other error codes see the
* mkdir() syscall description. * mkdir() syscall description.
*/ */
int makepath(char *dir) int makepath(const char *dir)
{ {
return mkpath(dir, 0777); return mkpath(dir, 0777);
} }
View File
File renamed without changes.
+4 -4
View File
@@ -1,6 +1,6 @@
/* Functions for dealing with PID files (client side) /* 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 * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * 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; return 1;
ret = kill(pid, signal); ret = kill(pid, signal);
if ((ret == -1) || (signal == SIGTERM) || (signal == SIGKILL)) if (!ret && signal == SIGKILL)
(void)remove(pidfile); ret = remove(pidfile);
return 0; return ret;
} }
/** /**
+1 -1
View File
@@ -1,6 +1,6 @@
/* Simple termios based progress bar /* 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 * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+9
View File
@@ -32,6 +32,11 @@
* @(#)queue.h 8.5 (Berkeley) 8/20/94 * @(#)queue.h 8.5 (Berkeley) 8/20/94
*/ */
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef _SYS_QUEUE_H_ #ifndef _SYS_QUEUE_H_
#define _SYS_QUEUE_H_ #define _SYS_QUEUE_H_
@@ -531,3 +536,7 @@ struct { \
} while (0) } while (0)
#endif /* !_SYS_QUEUE_H_ */ #endif /* !_SYS_QUEUE_H_ */
#ifdef __cplusplus
}
#endif
File renamed without changes.
+55 -21
View File
@@ -1,6 +1,6 @@
/* Micro "rsync" implementation. /* 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 * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@@ -16,6 +16,7 @@
*/ */
#include <errno.h> #include <errno.h>
#include <fcntl.h> /* AT_* macros */
#include <stdlib.h> /* NULL, free() */ #include <stdlib.h> /* NULL, free() */
#include <string.h> /* strlen() */ #include <string.h> /* strlen() */
#include <strings.h> /* rindex() */ #include <strings.h> /* rindex() */
@@ -26,16 +27,17 @@
#include "lite.h" #include "lite.h"
static int copy(char *src, char *dst); static int copy(char *src, char *dst, int opt);
static int mdir(char *buf, size_t buf_len, char *dir, char *name, mode_t mode); static int mdir(char *buf, size_t buf_len, char *dir, char *name, struct stat *st);
static int prune(char *dst, char **new_files, int new_num); static int prune(char *dst, char **new_files, int new_num);
static int set_mtime(char *fn, struct stat *st);
/** /**
* rsync - Synchronize contents and optionally remove non-existing backups * rsync - Synchronize contents and optionally remove non-existing backups
* @src: Source directory * @src: Source directory
* @dst: Destination directory * @dst: Destination directory
* @delete: Prune files from @dst that no longer exist in @src. * @opt: An option mask of %LITE_FOPT_RSYNC_DELETE, %LITE_FOPT_KEEP_MTIME
* @filter: Optional filtering function for source directory. * @filter: Optional filtering function for source directory.
* *
* This is a miniature implementation of the famous rsync for local use only. * This is a miniature implementation of the famous rsync for local use only.
@@ -44,19 +46,29 @@ static int prune(char *dst, char **new_files, int new_num);
* files removed from src since last backup are pruned from the destination * files removed from src since last backup are pruned from the destination
* (backup) directory. * (backup) directory.
* *
* The filter callback, @filter, if provided, is used to determine what files to * The @opt parameter to rsync() is an option mask for the most common
* include from the source directory when backing up. If a file is to be skipped * rsync(1) options. Previously this argument was called @delete and
* the callback should simply return zero. * to maintain backwards compatibility the value 1 is reserved:
*
* %LITE_FOPT_RSYNC_DELETE: Prune files from @dst that no longer exist in @src.
* %LITE_FOPT_KEEP_MTIME: Preserve modification time
*
* The filter callback, @filter, if provided, is used to determine what
* files to include from the source directory when backing up. If a
* file is to be skipped the callback should simply return zero.
* *
* Returns: * Returns:
* POSIX OK(0), or non-zero with @errno set on error. * POSIX OK(0), or non-zero with @errno set on error.
*/ */
int rsync(char *src, char *dst, int delete, int (*filter) (const char *file)) int rsync(char *src, char *dst, int opt, int (*filter)(const char *file))
{ {
char source[256]; char source[256];
char dest[256]; char dest[256];
int i = 0, num = 0, result = 0; int delete = (opt & LITE_FOPT_RSYNC_DELETE) != 0;
int keep_mtim = (opt & LITE_FOPT_KEEP_MTIME);
int i = 0, num = 0, result = 0, do_mtim = 0;
char **files; /* Array of file names. */ char **files; /* Array of file names. */
struct stat st;
if (!fisdir(dst)) if (!fisdir(dst))
makedir(dst, 0755); makedir(dst, 0755);
@@ -65,7 +77,7 @@ int rsync(char *src, char *dst, int delete, int (*filter) (const char *file))
if (!fexist(src)) if (!fexist(src))
return 1; return 1;
if (copy(src, dst)) if (copy(src, dst, keep_mtim))
result++; result++;
return errno; return errno;
@@ -80,9 +92,13 @@ int rsync(char *src, char *dst, int delete, int (*filter) (const char *file))
else else
ptr++; ptr++;
if (mdir(dest, sizeof(dest), dst, ptr, fmode(src))) if (stat(src, &st))
return 1;
if (mdir(dest, sizeof(dest), dst, ptr, &st))
return 1; return 1;
dst = dest; dst = dest;
do_mtim = keep_mtim;
} }
num = dir(src, "", filter, &files, 0); num = dir(src, "", filter, &files, 0);
@@ -91,21 +107,31 @@ int rsync(char *src, char *dst, int delete, 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;
strcat(source, "/"); strcat(source, "/");
if (mdir (dst2, sizeof(dst2), dst, files[i], fmode(source))) { if (stat(source, &st))
return 1;
if (mdir(dst2, sizeof(dst2), dst, files[i], &st)) {
result++; result++;
continue; continue;
} }
rsync(source, dst2, delete, filter); rsync(source, dst2, opt, filter);
if (keep_mtim)
set_mtime(dst2, &st);
continue; /* Next file/dir in @src to copy... */ continue; /* Next file/dir in @src to copy... */
} }
if (copy(source, dst)) if (copy(source, dst, keep_mtim))
result++; result++;
} }
if (do_mtim)
set_mtime(dest, &st);
/* We ignore any errors from the pruning, that phase albeit useful is only /* We ignore any errors from the pruning, that phase albeit useful is only
* cosmetic. --Jocke 2011-03-24 */ * cosmetic. --Jocke 2011-03-24 */
if (delete) if (delete)
@@ -120,11 +146,9 @@ int rsync(char *src, char *dst, int delete, int (*filter) (const char *file))
return result; return result;
} }
static int copy(char *src, char *dst) static int copy(char *src, char *dst, int opt)
{ {
errno = 0; copyfile(src, dst, 0, opt | LITE_FOPT_COPYFILE_SYM);
copyfile(src, dst, 0, 1);
if (errno) { if (errno) {
if (errno != EEXIST) if (errno != EEXIST)
return 1; return 1;
@@ -136,10 +160,10 @@ static int copy(char *src, char *dst)
} }
/* Creates dir/name @mode ... skipping / if dir already ends so. */ /* Creates dir/name @mode ... skipping / if dir already ends so. */
static int mdir(char *buf, size_t buf_len, char *dir, char *name, mode_t mode) static int mdir(char *buf, size_t buf_len, char *dir, char *name, struct stat *st)
{ {
snprintf(buf, buf_len, "%s%s%s/", dir, fisslashdir(dir) ? "" : "/", name); snprintf(buf, buf_len, "%s%s%s", dir, fisslashdir(dir) ? "" : "/", name);
if (mkdir(buf, mode)) { if (mkdir(buf, st->st_mode)) {
if (EEXIST != errno) if (EEXIST != errno)
return 1; return 1;
@@ -193,6 +217,16 @@ static int prune(char *dst, char **new_files, int new_num)
return result; return result;
} }
static int set_mtime(char *fn, struct stat *st)
{
struct timespec tv[2];
tv[0] = st->st_atim;
tv[1] = st->st_mtim;
return utimensat(AT_FDCWD, fn, tv, AT_SYMLINK_NOFOLLOW);
}
/** /**
* Local Variables: * Local Variables:
* indent-tabs-mode: t * indent-tabs-mode: t
+10
View File
@@ -23,6 +23,12 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * USE OR OTHER DEALINGS IN THE SOFTWARE.
* ========================================================================== * ==========================================================================
*/ */
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef LITE_STRDUPA_H #ifndef LITE_STRDUPA_H
#define LITE_STRDUPA_H #define LITE_STRDUPA_H
@@ -50,3 +56,7 @@
#endif /* !HAVE_STRDUPA */ #endif /* !HAVE_STRDUPA */
#endif /* LITE_STRDUPA_H */ #endif /* LITE_STRDUPA_H */
#ifdef __cplusplus
}
#endif
View File
File renamed without changes.
View File
File renamed without changes.
+33 -16
View File
@@ -1,6 +1,6 @@
/* Collection of frog DNA /* 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -21,14 +21,42 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef LITE_STRING_H_ #ifndef LITE_STRING_H_
#define LITE_STRING_H_ #define LITE_STRING_H_
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, INT32_MAX, etc. */
#include <string.h> #include <string.h>
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
#include "strdupa.h" #include "strdupa.h"
#include "strndupa.h" #include "strndupa.h"
#include "strnlen.h" #include "strnlen.h"
#ifndef min
#define min(a,b) \
({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; \
})
#endif
#ifndef max
#define max(a,b) \
({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; \
})
#endif
int strnmatch (const char *str, const char **list, size_t num);
int strmatch (const char *str, const char **list);
#ifndef strlcpy #ifndef strlcpy
size_t strlcpy (char *dst, const char *src, size_t siz); size_t strlcpy (char *dst, const char *src, size_t siz);
#endif #endif
@@ -82,19 +110,8 @@ static inline int string_case_compare(const char *a, const char *b)
return strlen (a) == strlen (b) && !strcasecmp (a, b); return strlen (a) == strlen (b) && !strcasecmp (a, b);
} }
#define min(a,b) \
({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; \
})
#define max(a,b) \
({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; \
})
#endif /* LITE_STRING_H_ */ #endif /* LITE_STRING_H_ */
#ifdef __cplusplus
}
#endif
+89
View File
@@ -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:
*/
+10
View File
@@ -23,6 +23,12 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. * USE OR OTHER DEALINGS IN THE SOFTWARE.
* ========================================================================== * ==========================================================================
*/ */
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef LITE_STRNDUPA_H_ #ifndef LITE_STRNDUPA_H_
#define LITE_STRNDUPA_H_ #define LITE_STRNDUPA_H_
@@ -51,3 +57,7 @@
#endif /* !HAVE_STRNDUPA */ #endif /* !HAVE_STRNDUPA */
#endif /* GNU_STRING_STRNDUPA_H */ #endif /* GNU_STRING_STRNDUPA_H */
#ifdef __cplusplus
}
#endif
+10 -1
View File
@@ -1,6 +1,6 @@
/* strnlen.h - Re-implementation of GLIBC strnlen() /* 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 * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * 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. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef LITE_STRNLEN_H_ #ifndef LITE_STRNLEN_H_
#define LITE_STRNLEN_H_ #define LITE_STRNLEN_H_
@@ -41,3 +46,7 @@ static inline size_t xstrnlen(const char *str, size_t lim)
#endif #endif
#endif /* LITE_STRNLEN_H_ */ #endif /* LITE_STRNLEN_H_ */
#ifdef __cplusplus
}
#endif
+10 -1
View File
@@ -26,6 +26,15 @@
#define TOOSMALL 2 #define TOOSMALL 2
#define TOOLARGE 3 #define TOOLARGE 3
#ifndef LLONG_MAX
# define LLONG_MAX 0x7fffffffffffffffLL
#endif
#ifndef LLONG_MIN
# define LLONG_MIN (-0x7fffffffffffffffLL - 1)
#endif
long long long long
strtonum(const char *numstr, long long minval, long long maxval, strtonum(const char *numstr, long long minval, long long maxval,
const char **errstrp) const char **errstrp)
@@ -49,7 +58,7 @@ strtonum(const char *numstr, long long minval, long long maxval,
error = INVALID; error = INVALID;
} else { } else {
ll = strtoll(numstr, &ep, 10); ll = strtoll(numstr, &ep, 10);
if (numstr == ep || *ep != '\0') if (errno == EINVAL || numstr == ep || *ep != '\0')
error = INVALID; error = INVALID;
else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
error = TOOSMALL; error = TOOSMALL;
+291
View File
@@ -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:
*/
+2 -2
View File
@@ -1,6 +1,6 @@
/* A secure tmpfile() replacement. /* 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 * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@@ -45,7 +45,7 @@ FILE *tempfile(void)
if (-1 == fd) if (-1 == fd)
return NULL; return NULL;
return fdopen(fd, "rw"); return fdopen(fd, "w+");
#else #else
return tmpfile(); /* Fallback on older GLIBC/Linux and actual UNIX systems */ return tmpfile(); /* Fallback on older GLIBC/Linux and actual UNIX systems */
#endif #endif
+9
View File
@@ -24,6 +24,11 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef _SYS_TREE_H_ #ifndef _SYS_TREE_H_
#define _SYS_TREE_H_ #define _SYS_TREE_H_
@@ -746,3 +751,7 @@ name##_RB_MINMAX(struct name *head, int val) \
(x) = (y)) (x) = (y))
#endif /* _SYS_TREE_H_ */ #endif /* _SYS_TREE_H_ */
#ifdef __cplusplus
}
#endif
+127
View File
@@ -0,0 +1,127 @@
/* C implementation of UNIX which(1)
*
* 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
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <ctype.h>
#include <errno.h>
#include <stdio.h> /* snprintf() */
#include <stdlib.h> /* realloc(), free() */
#include <string.h> /* strtok_r() */
#include <unistd.h> /* access() */
/* Strip any arguments in "/path/to/bin --some args", modifies input string */
static char *strip_args(char *path)
{
size_t i = 0;
if (!path)
return NULL;
/* Find first whitespace (space/tab/etc.) */
while (path[i] && !isspace(path[i]))
i++;
path[i] = 0;
return path;
}
/*
* Like which(1), returns a malloc'ed path to cmd on success, or NULL
*/
char *which(const char *cmd)
{
size_t pathlen = 0;
char *ptr, *tok, *env, *path = NULL;
if (!cmd) {
errno = EINVAL;
return NULL;
}
if (cmd[0] == '/') {
path = strip_args(strdup(cmd));
if (!path)
return NULL;
if (!access(path, X_OK))
return path;
if (path)
free(path);
return NULL;
}
ptr = getenv("PATH");
if (!ptr)
return NULL;
env = strdup(ptr);
if (!env)
return NULL;
tok = strtok_r(env, ":", &ptr);
while (tok) {
size_t len = strlen(tok) + strlen(cmd) + 2;
if (pathlen < len) {
path = realloc(path, len);
if (!path) {
free(env);
return NULL;
}
pathlen = len;
}
snprintf(path, pathlen, "%s/%s", tok, cmd);
path = strip_args(path);
if (!path || !access(path, X_OK)) {
free(env);
return path;
}
tok = strtok_r(NULL, ":", &ptr);
}
if (path)
free(path);
free(env);
return NULL;
}
/*
* Like which(), above, but only answers TRUE(1)/FALSE(0)
*/
int whichp(const char *cmd)
{
char *path;
path = which(cmd);
if (path) {
free(path);
return 1;
}
return 0;
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+92
View File
@@ -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:
*/
+7
View File
@@ -1,3 +1,4 @@
*.o
*.log *.log
*.trs *.trs
chomp chomp
@@ -9,7 +10,13 @@ fsendfile
lfile lfile
makepath makepath
pidfile pidfile
printhdr
progress progress
rsync rsync
str
strmatch
tempfile tempfile
touch
tree tree
which
yorn
+10 -4
View File
@@ -11,14 +11,20 @@ TESTS += fsendfile
TESTS += lfile TESTS += lfile
TESTS += makepath TESTS += makepath
TESTS += pidfile TESTS += pidfile
TESTS += printhdr
TESTS += progress TESTS += progress
TESTS += rsync TESTS += rsync
TESTS += str
TESTS += strmatch
TESTS += touch
TESTS += tempfile TESTS += tempfile
TESTS += tree TESTS += which
TESTS += yorn
check_PROGRAMS = $(TESTS) check_PROGRAMS = $(TESTS)
# Ignore warnings about unused result, in e.g. write() # Ignore warnings about unused result, in e.g. write()
CPPFLAGS = -D_GNU_SOURCE CFLAGS += -Wno-unused-result
LDADD = -L../ ../libite.la CPPFLAGS += -D_GNU_SOURCE
LDFLAGS = -static LDADD = -L../src/ ../src/libite.la
LDFLAGS += -static
+4 -1
View File
@@ -6,7 +6,10 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "../lite.h" #include "../src/conio.h"
#include "../src/lite.h"
#define PRINT(args...) if (verbose) printf(args)
#define fail_unless(test) \ #define fail_unless(test) \
do { \ do { \
+10 -3
View File
@@ -6,7 +6,7 @@
static int fstab(void) static int fstab(void)
{ {
int field = 1; int field = 1;
char *token, *dev; char *token;
lfile_t *lf; lfile_t *lf;
lf = lfopen(FSTAB, " \t\n"); lf = lfopen(FSTAB, " \t\n");
@@ -15,12 +15,19 @@ static int fstab(void)
return 1; return 1;
} }
printheader(NULL, "FILE SYSTEM MOUNT OPTIONS D P", 0);
while ((token = lftok(lf))) { while ((token = lftok(lf))) {
if (field == 1) if (field == 1)
dev = token; printf("%-41s ", token);
if (field == 2)
printf("%-9s ", token);
if (field == 4)
printf("%-17s ", token);
if (field == 5)
printf("%d ", atoi(token));
if (field == 6) { if (field == 6) {
field = 0; field = 0;
printf("Found %s passno %d\n", dev, atoi(token)); printf("%d\n", atoi(token));
} }
field++; field++;
+2 -2
View File
@@ -4,7 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "check.h" #include "check.h"
int checkpath(char *dir) int checkpath(const char *dir)
{ {
char tmp[256]; char tmp[256];
struct stat sb; struct stat sb;
@@ -20,7 +20,7 @@ int checkpath(char *dir)
return 1; return 1;
} }
int test_makepath(char *dir) int test_makepath(const char *dir)
{ {
int ret = makepath(dir); int ret = makepath(dir);
+2 -4
View File
@@ -6,8 +6,6 @@
#include "check.h" #include "check.h"
#define PRINT(args...) if (verbose) printf(args)
extern char *__pidfile_name; extern char *__pidfile_name;
extern char *__pidfile_path; extern char *__pidfile_path;
@@ -17,13 +15,13 @@ static char PIDFILE[42];
static int verbose = 0; static int verbose = 0;
static struct stat before, after; static struct stat before, after;
static void sigterm_handler(int UNUSED(signo)) static void sigterm_handler(int signo)
{ {
PRINT("Exiting ...\n"); PRINT("Exiting ...\n");
remove(PIDFILE); remove(PIDFILE);
} }
static void sigalrm_handler(int UNUSED(signo)) static void sigalrm_handler(int signo)
{ {
PRINT("Calling pidfile(%s)\n", pidfile_arg ?: "NULL"); PRINT("Calling pidfile(%s)\n", pidfile_arg ?: "NULL");
if (pidfile(pidfile_arg)) if (pidfile(pidfile_arg))
+20
View File
@@ -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;
}
-1
View File
@@ -2,7 +2,6 @@
#include <unistd.h> /* usleep() */ #include <unistd.h> /* usleep() */
#include "check.h" #include "check.h"
#include "../conio.h"
#define MAX_WIDTH 80 #define MAX_WIDTH 80
#define msleep(msec) usleep(msec * 1000) #define msleep(msec) usleep(msec * 1000)
+4 -3
View File
@@ -53,9 +53,9 @@ static void check_tree(char *heading, char *dir)
if (verbose) { if (verbose) {
if (heading) if (heading)
puts(heading); puts(heading);
tree(dir, 1);
} }
// XXX: Fixme, add code to list tree, nftw() possibly
} }
int run_test(void) int run_test(void)
@@ -72,7 +72,8 @@ int run_test(void)
#endif #endif
setup_test(); setup_test();
result += rsync(BASE "src", DST, 0, NULL); sleep(1);
result += rsync(BASE "src", DST, LITE_FOPT_KEEP_MTIME, NULL);
check_tree("Only partial rsync of src <-- No slash!", BASE); check_tree("Only partial rsync of src <-- No slash!", BASE);
#if 0 #if 0
cleanup_test(); cleanup_test();
+27
View File
@@ -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;
}
+44
View File
@@ -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;
}
+13 -2
View File
@@ -8,18 +8,29 @@
#warning O_TMPFILE is missing, either too old GLIBC, Linux, or non-Linux system #warning O_TMPFILE is missing, either too old GLIBC, Linux, or non-Linux system
#endif #endif
#define READBACK "Reality is frequently inaccurate.\n"
int main(void) int main(void)
{ {
int ret;
FILE *fp; FILE *fp;
char buf[80] = "";
printf("Before tempfile():\n"); printf("Before tempfile():\n");
system("ls -lrt " _PATH_TMP " | tail -3"); ret = system("ls -lrt " _PATH_TMP " | tail -3");
fp = tempfile(); fp = tempfile();
fail_unless(fp != NULL); fail_unless(fp != NULL);
ret = fputs(READBACK, fp);
rewind(fp);
if (fgets(buf, sizeof(buf), fp))
fprintf(stderr, "\nRead-back from tempfile: %s", buf);
fail_unless(!strcmp(buf, READBACK));
printf("\nAfter tempfile(), should be same list:\n"); printf("\nAfter tempfile(), should be same list:\n");
system("ls -lrt " _PATH_TMP " | tail -3"); ret = system("ls -lrt " _PATH_TMP " | tail -3");
return fclose(fp); return fclose(fp);
} }
+61
View File
@@ -0,0 +1,61 @@
#include <err.h>
#include <paths.h>
#include <signal.h>
#include <stdarg.h>
#include <time.h>
#include "check.h"
int verbose = 0;
static int mtime(char *file)
{
int ret;
char buf[80];
struct stat before, after;
PRINT("Calling touch() to create file ...\n");
touch(file);
stat(file, &before);
/* Must sleep a while here otherwise we execute too fast => no mtime change :-( */
usleep(10000);
PRINT("Calling touch() again to update mtime ...\n");
if (touch(file)) {
erase(file);
err(1, "Failed creating %s", file);
}
stat(file, &after);
ret = timespec_newer(&after.st_mtim, &before.st_mtim);
PRINT("Before: %s\n", timespec2str(&before.st_mtim, buf, sizeof(buf)));
PRINT("After : %s\n", timespec2str(&after.st_mtim, buf, sizeof(buf)));
return !ret;
}
int main(int argc, char *argv[])
{
int fd;
char file[42] = "/tmp/touch_test.XXXXXX";
if (argc > 1 && !strcmp(argv[1], "-v"))
verbose = 1;
fd = mkstemp(file);
if (fd < 0)
err(1, "Failed creating tempfile, %s", file);
close(fd);
return mtime(file);
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* compile-command: "make pidfile && ./pidfile -v"
* End:
*/
-19
View File
@@ -1,19 +0,0 @@
#include "check.h"
int main(void)
{
int result = 0;
size_t i;
struct { char *path; int fail; } arr[] = {
{ "/etc/passwd", -1 },
{ "/dev", 0 },
{ "/sbin", 0 },
};
for (i = 0; i < NELEMS(arr); i++) {
if (tree(arr[i].path, 1) != arr[i].fail)
result++;
}
return result;
}
+50
View File
@@ -0,0 +1,50 @@
#include "check.h"
struct tc {
char *cmd;
int exp;
int res;
};
int main(void)
{
int result = 0;
size_t i;
struct tc test[] = {
{ "ls", 1 },
{ "free", 1 },
{ "modinfo", 1 },
{ "useradd", 1 },
{ "/usr/bin/which", 1 },
{ "/bin/ps aux", 1 },
{ "/etc/passwd", 0 },
{ NULL, 0 }
};
setenv("PATH", "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin", 1);
for (i = 0; test[i].cmd; i++) {
char *path;
path = which(test[i].cmd);
if (!path) {
test[i].res = 0;
fprintf(stderr, "%20s : Not hot dog\n", test[i].cmd);
} else {
test[i].res = 1;
fprintf(stderr, "%20s : hot dog --> %s\n", test[i].cmd, path);
free(path);
}
}
for (i = 0; test[i].cmd; i++)
result += test[i].exp != test[i].res;
return result;
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+32
View File
@@ -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);
}
-128
View File
@@ -1,128 +0,0 @@
/* Simple /bin/tree replacement
*
* Copyright (c) 2015 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 <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
static int all = 0;
static int filter(const struct dirent *entry)
{
/* Skip current dir ".", and prev dir "..", from list of files */
if ((1 == strlen(entry->d_name) && entry->d_name[0] == '.') ||
(2 == strlen(entry->d_name) && !strcmp(entry->d_name, "..")))
return 0;
if (!all && entry->d_name[0] == '.')
return 0;
return 1;
}
static void get_perms(struct stat *st, char *buf, size_t len)
{
mode_t m = st->st_mode;
snprintf(buf, len, "[%c%c%c%c%c%c%c%c%c%c] ",
S_ISCHR(m) ? 'c' : S_ISBLK(m) ? 'b' : S_ISFIFO(m) ? 'p' : S_ISLNK(m) ? 'l' : S_ISSOCK(m) ? 's' : '-',
(m & S_IRUSR) ? 'r' : '-',
(m & S_IWUSR) ? 'w' : '-',
(m & S_ISUID ) ? 's' : (m & S_IXUSR) ? 'x' : '-',
(m & S_IRGRP) ? 'r' : '-',
(m & S_IWGRP) ? 'w' : '-',
(m & S_ISGID) ? 's' : (m & S_IXGRP) ? 'x' : '-',
(m & S_IROTH) ? 'r' : '-',
(m & S_IWOTH) ? 'w' : '-',
(m & S_IXOTH) ? 'x' : '-'
);
}
static int descend(char *path, int show_perms, char *pfx)
{
int result = 0;
struct stat st;
if (-1 == lstat(path, &st))
return 1;
if ((st.st_mode & S_IFMT) == S_IFDIR) {
int i, n;
struct dirent **namelist = NULL;
n = scandir(path, &namelist, filter, alphasort);
if (n) {
for (i = 0; i < n; i++) {
char t = ' ', p[14] = "", s[256] = "";
char buf[256];
char dir[80];
if (i + 1 == n) {
printf("%s `- ", pfx);
snprintf(dir, sizeof(dir), "%s ", pfx);
} else {
printf("%s|-- ", pfx);
snprintf(dir, sizeof(dir), "%s| ", pfx);
}
snprintf(buf, sizeof(buf), "%s/%s", path, namelist[i]->d_name);
if (!lstat(buf, &st)) {
if (show_perms)
get_perms(&st, p, sizeof(p));
if ((st.st_mode & S_IFMT) == S_IFDIR)
t = '/';
if (S_ISLNK(st.st_mode)) {
snprintf(s, sizeof(s), "-> ");
if (-1 == readlink(buf, &s[3], sizeof(s) - 3))
s[0] = 0;
}
}
printf("%s%s%c%s\n", p, namelist[i]->d_name, t, s);
if (t == '/')
result += descend(buf, show_perms, dir);
free(namelist[i]);
}
free(namelist);
}
} else {
errno = ENOTDIR;
result = -1;
}
return result;
}
int tree(char *path, int show_perms)
{
printf("[%s]\n", path);
return descend(path, show_perms, "");
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/