Compare commits

...
468 Commits
Author SHA1 Message Date
Joachim Wiberg c1e050f93c Update ChangeLog and bump version for v2.6.2 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-11-22 21:59:46 +01:00
Joachim Wiberg 0e45929323 Make note of possible extensions
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-11-22 21:44:20 +01:00
Joachim Wiberg 958502d982 Fix memory leak in which() on realloc() failure
Avoid leaking memory when realloc() fails by using a temporary pointer
and only updating the original on success. Also remove redundant NULL
check before free().

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-11-22 20:48:35 +01:00
Joachim Wiberg f0cb0b7bf2 .github: bump actions
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-04-28 08:34:00 +02:00
Joachim Wiberg ee5788d49b Create SECURITY.md policy 2025-04-28 07:54:35 +02:00
Joachim Wiberg 9bfe54f959 pidfile(): ensure prefix path ends with slash
For some builds using Buildroot, the system default _PATH_VARRUN did not
include a trailing slas '/', which cause the pidfile() function to fail.

Example:
  pidfile("arg") => "/var/runarg.pid"

Since the __pidfile_path can be overridden we add a check if that prefix
path ends with '/', if not we add one in the path composition.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-03-25 05:23:41 +01:00
Joachim Wiberg 960e7f69ed Update changelog and bump version for v2.6.1 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-10-15 10:22:36 +02:00
Joachim Wiberg 68bc83f08f FTBFS uClibc and musl libc, lite.h missing stdarg.h include
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-10-15 10:21:30 +02:00
Joachim Wiberg 986d29caf0 m4: sync with latest ax_prog_doxygen.m4
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-10-15 10:18:33 +02:00
Joachim Wiberg 2d9f8f595d Update ChangeLog and bump version to v2.6.0 GA
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 16:59:24 +02:00
Joachim Wiberg 3f8ad99f1f Fix varargs bug/usage, found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 12:47:59 +02:00
Joachim Wiberg 63e25ecae4 .github: use new syntax for setting variables
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 12:47:43 +02:00
Joachim Wiberg 6c53ee819b test: adjust times again
Running the tests in a Debian container seem to be taking way too long.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 12:26:08 +02:00
Joachim Wiberg da21e02be0 Update ChangeLog diffs
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 12:19:13 +02:00
Joachim Wiberg c33500c372 .github: import release job from Mg project
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 12:17:53 +02:00
Joachim Wiberg bed65c84e6 .github: bump action versions, node12 deprecated
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 12:17:27 +02:00
Joachim Wiberg c4f262b721 debian: prepare new release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 12:17:14 +02:00
Joachim Wiberg 563b387ec7 test: increase delay waiting for background job in Debian container
GitHub action fails, probably due to too short wait delay.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 12:11:51 +02:00
Joachim Wiberg b93d74c065 Update ChangeLog and bump version for v2.6.0-rc1
Bump ABI: 5.3.2 -> 5.4.0

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 12:00:04 +02:00
Joachim Wiberg c1f7bc2bbb Update copyright years
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 11:56:26 +02:00
Joachim Wiberg 99f644b512 doc: document new procfile functions
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 11:48:37 +02:00
Joachim Wiberg 92bb0ca399 runbg: new helper function inspired by the Infix project
The runbg() function is a delayed execvp() that has double-forked to the
background (to not create zombies).  It is useful for running commands
in the background for APIs that need to return a reply, e.g. a NETCONF
RPC to reboot the system.

Compared to the original in Infix, this version double forks to reparent
itself to PID 1 (init), closes all open files, including stdio.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 11:00:09 +02:00
Joachim Wiberg 921afdecb4 Minor, indent
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 10:49:25 +02:00
Joachim Wiberg 47b02df823 Minor, spellcheck
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-09-17 10:49:13 +02:00
Joachim Wiberg 4dd14dac42 New helper functions to read/write /proc and /sys style files
From the Infix project.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-06-11 13:19:05 +02:00
Joachim Wiberg 97a3d43e9c Reminder
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-06-11 12:47:49 +02:00
Joachim Wiberg 784a667584 New helper function, fexistf(), made for the Infix project
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-06-11 12:18:45 +02:00
Joachim Wiberg 1f6ff90d9e New helper function, vfopenf(), inspired by the Infix project
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-06-11 12:16:58 +02:00
Joachim Wiberg 9eb847e56c New helper function, popenf(), from the Infix project
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-06-11 12:03:24 +02:00
Joachim Wiberg 55272c13f7 Start new devel cycle for v2.6.0 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-06-11 11:38:01 +02:00
Joachim Wiberg 34097d33b6 Update changelog and bump version for v2.5.3 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-08 07:05:58 +02:00
Joachim Wiberg 311288eec9 test: major refactor and cleanup
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-08 06:51:25 +02:00
Joachim Wiberg 63cf8867c5 test: refactor, each test in separate func
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-08 06:00:47 +02:00
Joachim Wiberg ac7b4194cf Fix copyfile() regression introduced in 4e9b5c13
Caught in release cycle.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-08 05:55:48 +02:00
Joachim Wiberg e44aaa4fd5 test: slight refactor to add diff -q A B check to fcopyfile()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-08 05:55:48 +02:00
Joachim Wiberg 97cb2cb87c test: reproduce copyfile() off by one regression
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-08 05:55:39 +02:00
Joachim Wiberg 837c3f23be Prepare for v2.5.3 bug fix release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-02 22:20:03 +02:00
Joachim Wiberg 4e9b5c13c1 copyfile: allow copying empty files to non-existing destination dirs
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-02 22:17:47 +02:00
Joachim Wiberg d61b847e55 rsync: fix check for missing dst when dst is a directory
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-02 22:17:09 +02:00
Joachim Wiberg 90fdcdeb39 rsync: fix return value when copying a single file
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-02 22:16:50 +02:00
Joachim Wiberg e36ac8f462 test: finalize rsync unit test to reproduce bugs
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-04-02 22:16:21 +02:00
Joachim Wiberg eb3bb94cfa Update changelog and bump version for v2.5.2 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-04-17 14:19:11 +02:00
Joachim Wiberg 11b9c88732 Add printf format attribute to all vararg functions
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-04-17 14:11:31 +02:00
Joachim Wiberg 11d4aafce1 Merge pull request #20 from yangfl/upstream
Fix for some non-linux
2022-01-27 11:34:50 +01:00
yangfl 5cdc5736f3 Replace mknod() with creat()
For mknod(), mode must be S_IFIFO otherwise the behaviour is unspecified
according to SUS, and apparently Debian/kFreeBSD is in the hater list.
2022-01-27 00:11:00 +08:00
yangfl 059bfd7806 test: use sleep() for mtime delay
For filesystems without high-resolution time support, an usleep() is too short
to alter mtime. Though 1s is quite safe, sleep for 2s in case it gets awaken
right within that second.
2022-01-26 23:57:27 +08:00
yangfl 0cda6339a4 Fix fisdir sigfault on Hurd
Apparently Hurd's stat() does not like NULL and will sigfault, this patch takes
care of it.
2022-01-26 02:11:08 +08:00
Joachim Wiberg 8120492fc8 Update changelogs and bump version for v2.5.1
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-12-02 00:43:02 +01:00
Joachim Wiberg 2065165ae9 debian: use dh_link(1) instead to create /usr/inclute/lite symlink
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-12-02 00:42:19 +01:00
Joachim Wiberg 95e5fdba9b Bump version for v2.5.0 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-30 07:01:09 +01:00
Joachim Wiberg b21d1c8e9b More syntactic sugar
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-29 18:49:20 +01:00
Joachim Wiberg 5b670951a3 More experimenting and some reflow of a paragraph
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-29 00:33:10 +01:00
Joachim Wiberg 612290c9e2 Experiment with syntax highlighting
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-29 00:28:39 +01:00
Joachim Wiberg 80d11dccf7 Update changelogs for upcoming v2.5.0 release
This should be it, but let's sleep on it for good measure.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-29 00:25:53 +01:00
Joachim Wiberg 438e7a2722 debian: update libite-dev, headers in libite/*.h and lite symlink
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-29 00:25:21 +01:00
Joachim Wiberg 96e023e58e Update README wrt the namespace change
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-29 00:23:24 +01:00
Joachim Wiberg 67a9b379ba Update comments, also namespace is one word
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-29 00:22:38 +01:00
Joachim Wiberg 1c0988b8e2 Fix #18: optional compat symlink lite -> libite/
Default is to create the symlink, to facilitate upgrades.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-28 19:22:45 +01:00
Joachim Wiberg 407b8f6dbf Prefix include guards with LIBITE_ to safe guard name space
The tree.h and queue.h include guards must remain so users don't
accidentally get their system queue.h included as well.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-28 19:20:53 +01:00
Joachim Wiberg bc72e1c3ad Change -lite include path/name space; lite/*.h -> libite/*.h
First step in fixing issue #18.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-28 19:09:55 +01:00
Joachim Wiberg 2d10cf0402 Prepare ChangeLog for upcoming v2.5.0 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-28 19:08:32 +01:00
Joachim Wiberg 7adf2a01f2 Bump version for v2.5.0 release cycle (-dev)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-28 19:07:54 +01:00
Joachim Wiberg a4ff8cce01 strnlen(): defensive programming, check limit before indexing array
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-28 16:36:43 +01:00
Joachim Wiberg 12b9196c65 Bump ABI version 5.3.0 -> 5.3.1 according to doc/HACKING.md
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-09 09:21:41 +02:00
Joachim Wiberg 6eee1b1baf doc: update project name
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-09 09:19:49 +02:00
Joachim Wiberg 1a5b184391 debian: add doxygen to Build-Depends-Indep
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-09 09:13:09 +02:00
Joachim Wiberg 832c4a936b Update changelogs and bump version for v2.4.1 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-09 08:57:49 +02:00
Joachim Wiberg a712364d49 tempfile(): use same fallback also when O_TMPFILE is missing
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-06 18:05:45 +02:00
Joachim Wiberg fae83c9be3 Use mkostemp() instead of insecure tmpfile() as fallback
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-06 17:51:07 +02:00
Joachim Wiberg 48202ef19e Slightly rearrange and fix URL
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 22:40:11 +02:00
Joachim Wiberg 7c36f715c7 Split README.md in two, create a new doc/API.md
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 22:37:55 +02:00
Joachim Wiberg 328b28f2d1 Restore spacing between badges
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 22:32:08 +02:00
Joachim Wiberg 970fa47ecf Update code docs for string functions and macros as well
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 22:30:20 +02:00
Joachim Wiberg 0a98f5bbd1 Mention API documentation
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 21:34:12 +02:00
Joachim Wiberg 85336b1f2b Link to blog post, to free up GitHub home URL for docs
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 21:31:59 +02:00
Joachim Wiberg 8128e63898 Add codedocs status badge
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 21:29:16 +02:00
Joachim Wiberg b52f1e5ad6 debian: drop sdbuf, unused internal variable
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 19:14:22 +02:00
Joachim Wiberg 5d1e884d6f Initial codedocs.xyz integration
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 19:10:45 +02:00
Joachim Wiberg 6537b11e34 doc: initial effort to enable doxygen
Framework from libuEv.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 19:08:40 +02:00
Joachim Wiberg 03598fc01e .github: rename test result artifact
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 14:55:42 +02:00
Joachim Wiberg d4649b8284 test: clean up any lingering core file after systemf() test
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 13:22:01 +02:00
Joachim Wiberg 3d2a975f11 Fix issue with tempfile() returning EOPNOTSUPP on Azure
Turns out O_TMPFILE can fail in interesting ways when the underlying
filesystem doesn't support unnamed inodes, e.g. Azure used by GitHub
Actions.  Here's the exact qoute from open(2):

  "O_TMPFILE requires support by the underlying filesystem; only a
  subset of Linux filesystems provide that support.  In the initial
  implementation, support was provided in the ext2, ext3, ext4, UDF,
  Minix, and shmem filesystems.  Support for other filesystems has
  subsequently been added as follows: XFS (Linux 3.15); Btrfs (Linux
  3.16); F2FS (Linux 3.16); and ubifs (Linux 4.9)"

This patch adds a silent fallback to tmpfile() in these cases.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:55:01 +02:00
Joachim Wiberg 1b6707f44e test: investigate why tempfile() fails on debian:stable
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:42:16 +02:00
Joachim Wiberg bdebca9681 .github: separate check and distcheck steps, use -j3
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:35:21 +02:00
Joachim Wiberg d364f6b4e1 .github: if debian distcheck fails, show test-suite.log
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:29:52 +02:00
Joachim Wiberg 6db730aeff Bump version for v2.4.1 release cycle (-beta1)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:24:21 +02:00
Joachim Wiberg c512e1cabd .github: prepare initial release general
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:23:23 +02:00
Joachim Wiberg 5d94ca9a14 .github: add coverity scan workflow
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:23:23 +02:00
Joachim Wiberg f0efcb5340 Minor updates and fixes
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:23:23 +02:00
Joachim Wiberg 4ee5ca61b8 Drop Travis-CI in favor of GitHub Actions
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:22:48 +02:00
Joachim Wiberg ed491ecdba .github: enable bob
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:22:33 +02:00
Joachim Wiberg b6940814f4 .github: enable funding for this repo
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:22:33 +02:00
Joachim Wiberg 1e91e7ea3f .github: add contributing guidelines
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:22:33 +02:00
Joachim Wiberg 332861430d Minor, cleanup
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:22:33 +02:00
Joachim Wiberg 0813084aa7 Import release related fixes to top Makefile from libuEv
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:22:33 +02:00
Joachim Wiberg 990ee6874c Relocate libite.pc.in to src/
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:22:33 +02:00
Joachim Wiberg ef4a8691d3 test: fix build warnings for most tests
Let rsync.c continue to warn, it's not complete ...

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:22:33 +02:00
Joachim Wiberg 75139cdf3c Relocate lesser used docs to doc/
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:22:33 +02:00
Joachim Wiberg c9633ffbb0 Rename tests/ -> test/ and update internal refs.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:22:33 +02:00
Joachim Wiberg 692dbadd3a Prefix CFLAGS/CPPFLAGS/etc with AM_ to prevent env. clashes
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:22:33 +02:00
Joachim Wiberg b1a2975a76 Replace obsolete AM_CONFIG_HEADER with AC_CONFIG_HEADERS
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 12:21:03 +02:00
Joachim Wiberg 67529f2283 debian: update symbols file
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 10:24:05 +01:00
Joachim Wiberg 8e69676943 Increment ABI version 5.2.0 -> 5.3.0
The GNU libtool numbers are just SO confusing.

 - New interfaces (new functions) added/removed/changed: 7 -> 8
 - Interfaces added: 2 -> 3

End result, steps 5.2.0 to 5.3.0, which makes sense.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 09:26:04 +01:00
Joachim Wiberg 76faae4292 Update changelogs, and bump version in prep. for v2.4.0 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 09:18:22 +01:00
Joachim Wiberg e928c30fbd Revert "Travis-CI: disable clang temporarily for Coverity Scan run"
This reverts commit 951050fdd2.
2021-03-27 09:05:31 +01:00
Joachim Wiberg 3512201a58 Travis-CI: install to /tmp/foo and run distcheck at the end
- We shouldn't run ls -lr /tmp, in particular when Coverity runs, it
  keeps a LOT of files in /tmp causing Travis to terminate our jobs
- make check is cool, but distcheck also verifies our Makefile.am
  rules, ensuring make check also works from an unpacked tarball

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 08:56:27 +01:00
Joachim Wiberg dc5c4ae36c systemf(): simplify further, exited OK or was signaled
Coverity highlighted a problem with logically dead code from the change
prior that triggered this refactor.  When system() returns we may have
exited either normally or due to a signal.

My reasoning behind systemf() is to allow users to treat external calls
as any other syscall, abstracting away the WIFFOO() macros.  This leaves
us with either the return value of the external program >= 0, or -1 and
errno for everything else.  I.e., if fork() or alloca() fails we may get
ENOMEM and if the program doesn't catch signals properly, EINTR.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 08:48:09 +01:00
Joachim Wiberg 748948b665 Minor, use .svg Travis status badge
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 08:48:01 +01:00
Joachim Wiberg 951050fdd2 Travis-CI: disable clang temporarily for Coverity Scan run
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 08:09:17 +01:00
Joachim Wiberg d5c5996f03 Minor, whitespace
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 08:06:17 +01:00
Joachim Wiberg f5808e557e Add strtrim(), trims leading and trailing white-space from a string
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 08:05:36 +01:00
Joachim Wiberg d4b554ccdc Add erasef(), formatted version of erase()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-27 07:08:49 +01:00
Joachim Wiberg 098a020843 Bump version, 2.4.0 development cycle
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-26 12:39:32 +01:00
Joachim Wiberg 2040569f0a Add touchf(), formatted version of touch()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-26 12:39:32 +01:00
Joachim Wiberg 733a7062e9 Minor, whitespace
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-26 12:37:05 +01:00
Joachim Wiberg 7ad11a31df touch(): behavioral change, call utimensat() first, then mknod()
Optimize for the case the file exists already.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-26 12:35:41 +01:00
Joachim Wiberg 8ce46eb439 systemf(): fix improper handling of WEXITSTATUS()
The call to system() may return -1, e.g. if fork() fails or return
status from execl() cannot be read.  In these cases we should end
immediately and not call WIFEXITED() et al.

Also, WEXITSTATUS() should only be called if WEXITED() returns true.

For details, see system(3) and wait(2).

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-26 12:32:43 +01:00
Joachim Wiberg c15e883427 tests: update systemf() test to detect improper return code on error
Non-existing programs should return 127, and
killing ourselves with -9 should return -1

For details, see system(3).

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-26 12:29:55 +01:00
Joachim Wiberg 63d82da62d Update changelogs and bump version for v2.3.1 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 15:13:40 +01:00
Joachim Wiberg dd1c67b2b6 debian: add missing files to copyright
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 15:10:05 +01:00
Joachim Wiberg 08d9a90945 Makefile: use debuild to build .deb packages, also runs lintian
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 09:29:42 +01:00
Joachim Wiberg beba419a0f debian: makepath.c is copyright me, licensed as isc
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 09:29:01 +01:00
Joachim Wiberg 3d695eede5 Update copyright years and author surname
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 09:28:41 +01:00
Joachim Wiberg 6e18edea93 debian: set dist to stable, that's the only channel currently
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 08:28:18 +01:00
Joachim Wiberg 9c89daf770 Update changelogs and bump version for v2.3.0 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 08:24:30 +01:00
Joachim Wiberg b3d4674bf7 Makefile: add .sha256 checksums to release target
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 08:23:07 +01:00
Joachim Wiberg aa4576d5ea configure: enable tar.gz dist archives, by popular demand
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 08:22:32 +01:00
Joachim Wiberg ae56c9e33c debian: sync rules with libuev
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 08:21:42 +01:00
Joachim Wiberg 3387c737be debian: update symbols file, new functions introduced in 2.3.0
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 08:21:23 +01:00
Joachim Wiberg 8d90ede158 Update changelog with new function
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-01 19:12:44 +01:00
Joachim Nilsson b1fe8a1271 debian: Update .gitignore
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-06-02 06:56:41 +02:00
Joachim Nilsson 044c2621ac Add support for truncatef(), formatted truncate() replacement
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-06-02 06:56:02 +02:00
Joachim Nilsson 7396dd83c7 Merge pull request #15 from yangfl/upstream
Fix #14: Avoid (some) hard-coded pathes in tests
2020-06-01 17:18:11 +02:00
yangfl e5fe988cdc Avoid (some) hard-coded pathes in tests 2020-06-01 23:04:29 +08:00
Joachim Nilsson 824da13977 Update ChangeLog, added fremove()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-29 00:33:39 +02:00
Joachim Nilsson efb1470008 Update ChangeLog with ETIMEDOUT fix to telnet_open()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-27 23:23:21 +02:00
Joachim Nilsson d2d0792c06 telnet_open(): Handle ETIMEDOUT in connect()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-27 23:20:55 +02:00
Joachim Nilsson 711c59e3a6 telnet: Refactor, rename local variable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-27 23:20:55 +02:00
Joachim Nilsson f85ff3c835 tests: Add fremove() pass to fopenf() unit test for cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-27 23:18:47 +02:00
Joachim Nilsson 16ea69adb4 Add support for fremove(), formatted remove() replacement
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-27 23:18:10 +02:00
Joachim Nilsson ae492581f8 tests: Keep same width for pass sub-headings as as test framework
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-27 23:17:50 +02:00
Joachim Nilsson d16385415c Simplify va_start/_end handling and return ENOMEM if alloca() fails
Be consistent with errno codes from libite, we already have other APIs
that return ENOMEM if alloca() fails, so let's do the same for these
new ones as well.

Also, simplify va_start()/va_end() handling in these APIs, no point
in the extra complexity before this patch.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-27 23:14:56 +02:00
Joachim Nilsson d27518c5b8 Bump version for 2.3.0-dev release cycle
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-27 22:45:41 +02:00
Joachim Nilsson 724926896a Add mising bullet and document new APIs better 2020-03-26 05:41:41 +01:00
Joachim Nilsson ef04307b4a debian: Update symbols file, new APIs introduced in v2.2.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-16 17:41:44 +01:00
Joachim Nilsson 5d035d955e debian: Add missing libtool to Build-Depends
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-16 17:38:25 +01:00
Joachim Nilsson b65175782d Bump ABI version, new APIs added
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-16 17:38:25 +01:00
Joachim Nilsson c27a8e7ec6 Update changelogs and bump version for v2.2.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-16 16:01:46 +01:00
Joachim Nilsson d231c1e1eb Revert "Travis-CI: Disable clang temporarily for Coverity Scan run"
This reverts commit 2a6adeebcd.
2020-03-16 10:41:27 +01:00
Joachim Nilsson 247fb67274 Add Coverity Scan badge
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-16 10:37:21 +01:00
Joachim Nilsson c716cc5835 copyfile(): Check return value of fstat(), prevent faulty futimens()
Found by Coverity Scan

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-16 10:31:50 +01:00
Joachim Nilsson e81ce85867 rsync(): Fix possible memory leak, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-16 10:31:50 +01:00
Joachim Nilsson 549f325c21 rsync(): Fix variable shadowing, found by clang-tidy
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-16 10:31:46 +01:00
Joachim Nilsson 2a6adeebcd Travis-CI: Disable clang temporarily for Coverity Scan run
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-14 10:56:23 +01:00
Joachim Nilsson cb2beacf2c Travis-CI: Add support for Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-14 10:55:27 +01:00
Joachim Nilsson 256b6ba038 Add origin section to README, better place for history or project
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-14 10:48:55 +01:00
Joachim Nilsson 61d9b5fac7 Update Changelog for upcoming v2.2.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-14 10:43:48 +01:00
Joachim Nilsson 38ad841389 Bump version for v2.2.0 release cycle
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-14 10:39:17 +01:00
Joachim Nilsson f1a1a21569 Add support for systemf(), formatted system() replacement
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-14 10:32:52 +01:00
Joachim Nilsson 7f3f4df9e9 Add support for fmkpath(), formatted string mkpath()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-11 20:03:03 +01:00
Joachim Nilsson 02a42a1cad Add support for fopenf(), formatted string fopen()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-10 09:07:56 +01:00
Joachim Nilsson 28c11f010a Check for existence of AM_PROG_AR macro
This patch facilitates building newer versions of libite on systems with
older versions of autoconf and automake.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 15:47:28 +01:00
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
Joachim Nilsson 8587971fb9 Update ChangeLog and bump version for v1.8.3 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-08 15:17:17 +01:00
Joachim Nilsson 6545ac8fd4 Bump ABI revision 3:0:0 --> 3:1:0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-08 15:16:36 +01:00
Joachim Nilsson 9105e8d3d8 Update pidfile() documentation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-08 15:16:00 +01:00
Joachim Nilsson 3555af6a6a Update ChangeLog and bump version for upcoming v1.8.3 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-07 13:58:59 +01:00
Joachim Nilsson 42715eab8a ChangeLog: Add missing link to v1.8.2 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-07 13:57:57 +01:00
Joachim Nilsson 497d58dbf0 ChangeLog: Minor Markdown fixes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-07 13:57:21 +01:00
Joachim Nilsson 9ab70ebbcd Build all unit tests static, for easier debugging
- Add -static to LDFLAGS
- Remove CFLAGS override, respect input from configure script

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-07 13:00:08 +01:00
Joachim Nilsson bad363883d Fix leaky makepath() unit test
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-07 12:59:27 +01:00
Joachim Nilsson 7f3215b3e6 Update pidfile unit test to cover new use-case
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-07 12:59:02 +01:00
Joachim Nilsson 729cc5307f pidfile: Add support for absolute path
The OpenBSD version of pidfile() makes sure to place all PID files in
the same, canonical, location: _PATH_VARRUN.  On Linux, however, some
disitributions prefer to place PID files in a sub-directory under the
canonical location: _PATH_VARRUN + __progname/ ...

This patch adds support for creating PID files in any location. If the
PID file name argument starts with a '/', the function assumes the rest
of the string is the full PATH to the PID file.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-07 12:55:26 +01:00
Joachim Nilsson 66290d132f pidfile: Re-create file on consequetive calls if it doesn't exist
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-07 08:15:49 +01:00
Joachim Nilsson 59f7a78441 pidfile: Always initialize global variables
Always initialize global variables, even though they cannot be used in
current code paths without being initialized at runtime.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-07 08:15:42 +01:00
Joachim Nilsson b716776863 tests/pidfile: Cleanup test files from /tmp
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-07 06:53:21 +01:00
Joachim Nilsson 018ecaca15 debian/source/format: Change to native mode to allow building from GIT
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-07 04:10:21 +01:00
Joachim Nilsson a293c37777 debian/: Support for building .deb packages
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-29 08:32:06 +01:00
Joachim Nilsson a4937a93e2 Add reminder about umask()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-02 12:13:43 +02:00
Joachim Nilsson 94d547c9ec Unit test: fix search path for library header
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-05 00:19:52 +02:00
Joachim Nilsson 68cf8b6576 Update ChangeLog and bump version for v1.8.2 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-05 00:13:03 +02:00
Joachim Nilsson b6a55fcc46 Add err.h include to tests
lite.h no longer includes err.h it has to be included in each test.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-05 00:07:24 +02:00
Joachim Nilsson 5f29ef6413 Convert touch() et al to inline functions
The touch(), makedir(), makefifo(), and erase() macros print warnings to
stderr, which mess up the logging in Finit.  This patch refactors these
macros into inline functions and in the process removes the warn() use.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 23:58:32 +02:00
Joachim Nilsson 627c47caff Bump version for v1.8.2 devel
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-22 01:33:12 +02:00
Joachim Nilsson 7c2ed556b9 Replace \e GNUism w/ ISO \033 for escape sequences
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-22 01:31:49 +02:00
Joachim Nilsson 6dec4e3858 Extend lfile test with fstab parser
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-02 00:29:52 +02:00
Joachim Nilsson dff92356b3 Remove sys/cdefs.h include, does not exist in musl libc
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-19 15:39:57 +02:00
Joachim Nilsson 883c90112d Update modification date
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-04 12:46:44 +02:00
Joachim Nilsson a2c8dddaad Free pidfile_path atexit()
To prevent warnings from tools like Valgrind, or handle issues
with RAM leaks on non-MMU systems like uClinux, we must free
the memory allocated by pidfile().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-04 12:42:22 +02:00
Joachim Nilsson 14f547b638 Add ldconfig to build instructions, thanks rooth!
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-30 18:53:59 +02:00
Joachim Nilsson 6f2a03bba7 Update ChangeLog & bump version for v1.8.1 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-25 12:50:21 +02:00
Joachim Nilsson cdfffa312b Update ChangeLog for upcoming v1.8.1 fix release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-08 07:18:30 +02:00
Joachim Nilsson 50cb72018f pidfile: Portability fix, utimensat() in sys/time.h
For building libite on NetBSD, and probably other BSD's as well.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-08 06:25:02 +02:00
Joachim Nilsson e8a3117158 fparseln: Portability fix _DIAGASSERT()
Only define _DIAGASSERT() if it's not already defined.
For building libite on NetBSD.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-08 06:23:34 +02:00
Joachim Nilsson 7cf2a3786c Bump version and ABI for v1.8.0 release
- Change from v1.7.1 to v1.8.0 due to amount of changes
  including ABI bump
- Update ChangeLog
- Bump library ABI version due to change in API semantics

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 19:05:26 +02:00
Joachim Nilsson 1c1d5c94e3 Clarify ABI versioning and encourage more unit tests
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 19:00:14 +02:00
Joachim Nilsson 23703c75da tests/dir.c: Remove nested checker function
Move nested check function is_startup_config() outside main().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 18:15:47 +02:00
Joachim Nilsson efae15416c Bump version to -rc1, many changes since last release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 18:11:03 +02:00
Joachim Nilsson 661b4b4d0b Remove last remnants of old build/unit test framework
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 18:09:59 +02:00
Joachim Nilsson 682b662bd5 Add unit test for chomp()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 18:09:29 +02:00
Joachim Nilsson 75d4edb424 check.h: Add stdlib.h for exit()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 18:08:54 +02:00
Joachim Nilsson 141d4f6936 Add unit test for copyfile()/fcopyfile()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 17:59:52 +02:00
Joachim Nilsson 63aa6c5d07 Add unit test for dir()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 17:56:13 +02:00
Joachim Nilsson 1d698418c7 dir(): Do not assert(), return -1 and errno
The dir() function, although useless compared to glob(), called assert()
and perror() instead of returning an error code.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 17:56:13 +02:00
Joachim Nilsson 92d81280a9 Add unit test for fexist()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 17:45:19 +02:00
Joachim Nilsson 267465f3d2 Add unit test for fisdir()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 17:42:31 +02:00
Joachim Nilsson c22a6e64d9 Add unit test for progress bars
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 17:39:31 +02:00
Joachim Nilsson 16ae343df2 Add missing progress bar API's
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 17:39:31 +02:00
Joachim Nilsson 6e558e98f0 Add unit test for rsync
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 17:28:41 +02:00
Joachim Nilsson 69291d3e74 Add unit test for fsendfile()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 17:20:58 +02:00
Joachim Nilsson 6fdffeb355 fsendfile(): Change return type size_t --> ssize_t
Most send/recv/read/write API's return -1 on error and today use the
agreed upon type ssize_t for this purpose.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 17:19:54 +02:00
Joachim Nilsson b2f6721813 Clarify LITE file API in README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 17:12:42 +02:00
Joachim Nilsson 3c350b8862 Add unit test for LITE file API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 17:11:22 +02:00
Joachim Nilsson 5b786ce221 Add unit test for tempfile()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 17:07:14 +02:00
Joachim Nilsson 86b883e2af strdupa.h: Unify header guards with other headers
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 15:32:35 +02:00
Joachim Nilsson 2d6e8850a2 Add unit test for tree
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 15:32:35 +02:00
Joachim Nilsson d8cb477861 Ignore *.log and *.trs files in unit test dir
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 15:31:24 +02:00
Joachim Nilsson 27644677dd Clean *.trs and *.log files from unit test dir
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 15:31:24 +02:00
Joachim Nilsson 3588c9b01f Rename unit tests, drop _func suffix
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 15:31:24 +02:00
Joachim Nilsson ca3ea5ae92 Add unit test for mkpath() and makepath() funcs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 15:31:23 +02:00
Joachim Nilsson 188d968f89 Remove previous pidfilefn() unit test makefile
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 15:03:56 +02:00
Joachim Nilsson 8e2c58501c Build all unit tests with -W -Wall -Wextra
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 14:02:36 +02:00
Joachim Nilsson 1da317ce1e Add missing signal.h include
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 14:02:27 +02:00
Joachim Nilsson fe39284d50 Travis-CI: Verify installation and run unit tests
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 12:42:33 +02:00
Joachim Nilsson c3c23b9aef Update ChangeLog for upcoming v1.7.1 fix release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 12:39:50 +02:00
Joachim Nilsson d45f2bad5b Update pidfile() description with hidden features
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 12:35:01 +02:00
Joachim Nilsson 61fb7aeca2 New unit test framework, first test pidfile funcs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 12:30:35 +02:00
Joachim Nilsson dedcaf92d5 Minor style fix, to keep with pidfile.c style
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 12:16:14 +02:00
Joachim Nilsson c009c49a92 Expose __pidfile_path to override _PATH_VARRUN
This patch makes it possible to override the default pidfile() path used
for PID files, _PATH_VARRUN, with a custom path, e.g. _PATH_TMP.

This change does not affect the ABI of pidfile()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 12:14:26 +02:00
Joachim Nilsson 12f619a320 Fix minor build error in new strndupa() header
Wrong path to local strnlen.h file.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 11:04:17 +02:00
Joachim Nilsson c1b3b76ea3 Update ChangeLog and bump version for v1.7.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-05 00:36:43 +02:00
Joachim Nilsson 8108b8ec14 Add HACKING.md for release policy ABI versioning etc.
Most of the text shamelessly stolen from the libConfuse project :)

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 19:01:18 +02:00
Joachim Nilsson 0e2d365eb9 Update ChangeLog with fixes and new features
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 18:56:07 +02:00
Joachim Nilsson 8b499aa9cd Add compat strnlen() implementation for non-GLIBC systems
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 18:51:25 +02:00
Joachim Nilsson f4fa44fe60 Add strndupa.h to distribution and update README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 15:13:16 +02:00
Joachim Nilsson be08bcd09d strndupa.h: #error if building with non-GCC on non-GNU systems
At the moment only GCC is supported on non-GNU systems, unfortunately.
GNU systems usually have GLIBC, or another library with strndupa().
This strndupa() implementation requires GCC for the builtin alloca API.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 15:12:02 +02:00
Joachim Nilsson 1495a3f858 Add compat strndupa() implementation from libnostd
This patch adds compat support, to *BSD and other UNIX, for the GLIBC
strndupa() function.  The implementation is taken from libnostd written
by William Ahern.

http://www.25thandclement.com/~william/projects/libnostd.html

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 15:07:17 +02:00
Joachim Nilsson 5eb816b4c0 Update ChangeLog and README with new strdupa()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-03 23:12:50 +02:00
Valery Frolov 456c58d52d Add new headers, for strdupa(), to distribution
Signed-off-by: Valery Frolov <fvgenn@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-03 23:08:08 +02:00
Joachim Nilsson 59869b876e strdupa.h: #error if building with non-GCC on non-GNU systems
At the moment only GCC is supported on non-GNU systems, unfortunately.
GNU systems usually have GLIBC, or another library with strdupa().  This
strdupa() implementation requires GCC for the builtin alloca API.

Followup to pull-request #4

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-02 19:51:43 +02:00
Joachim Nilsson 113c3487bd Add info on building directly from GIT
Followup to pullrequest #4

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-02 19:44:49 +02:00
Joachim Nilsson de73e268d3 Merge branch 'abs0-master'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-30 22:32:43 +02:00
Joachim Nilsson b57c257f09 Cleanup of old shared rules.mk file, now only used by unit tests.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-30 22:31:59 +02:00
Joachim Nilsson 94d42b3df7 Add compat strdupa() implementation from libnostd
This patch adds compat support, to *BSD and other UNIX, for GLIBC
strdupa() function, used in mkpath().  The implementation is taken
from http://www.25thandclement.com/~william/projects/libnostd.html
by William Ahern.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-30 22:29:30 +02:00
Joachim Nilsson 94ad65a121 Factor out string functions to lite/strlite.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-30 22:27:41 +02:00
David Brownlee f3f6947604 Handle old Linux/(G)LIBC and UNIX systems the same
Linux systems pre Linux 3.11, and UNIX do not have the O_TMPFILE flag,
so let's treat them the same, by wrapping tmpfile().

Signed-off-by: David Brownlee <abs@absd.org>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-30 21:05:21 +02:00
Joachim Nilsson 613d397161 Fix mkpath() to handle relative dirs
After input from both StackOverflow and Valery Frolov.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-23 09:15:50 +02:00
Joachim Nilsson 7df1b75fa0 Bump version for v1.6.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-13 07:22:25 +02:00
Joachim Nilsson 9b1b7ca4cf ChangeLog: Fix Markdown links in v1.6.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-13 07:21:45 +02:00
Joachim Nilsson 1e064b8b4d Update ChangeLog for v1.6.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-12 21:13:10 +02:00
Joachim Nilsson 18dde87f0a Add NetBSD fparseln(3) v1.10
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-09 19:14:05 +02:00
Joachim Nilsson fcb38c9cc5 Constify fisdir() argument
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-09 19:10:05 +02:00
Joachim Nilsson ab69ae8374 Add OpenBSD reallocarray(3) v1.2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-09 00:37:05 +02:00
Joachim Nilsson 95f7a91a8a Bump version for v1.6.0 release cycle
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-09 00:33:16 +02:00
Joachim Nilsson aab5a1145c Remove Emacs version-control handling
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-07 22:35:49 +02:00
Joachim Nilsson fe1a3a731d Update ChangeLog and bump version for v1.5.1 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-17 16:27:02 +02:00
Joachim Nilsson cd073f5221 fcopyfile: Westermo fixes and code simplification
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-17 16:17:00 +02:00
Joachim Nilsson 1a9d3bd91b Spellcheck
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-17 01:25:46 +02:00
Joachim Nilsson 8cc267f259 Markdown formatting
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-17 01:03:53 +02:00
Joachim Nilsson 35d396ec27 Is --> Are, a --> an ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-17 01:02:09 +02:00
Joachim Nilsson 7e91307138 Add Table of Contents
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-17 00:54:22 +02:00
Joachim Nilsson 2b8f54fbc7 Update build & install instructions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-17 00:53:57 +02:00
Joachim Nilsson 2e58dd3203 Simplify configure script
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-17 00:47:21 +02:00
Joachim Nilsson 41392f7e85 Remove bogus autoconf version requirement
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-17 00:46:58 +02:00
Joachim Nilsson e4329d6c25 Add some integration tips when using GNU autotools
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-17 00:46:14 +02:00
Joachim Nilsson 7113b3d1d8 Add basic TODO file to keep track of stuff
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-11 01:24:53 +02:00
Joachim Nilsson 9b6ef1f053 pidfile(): Activate use of utimensat() to update atime+mtime
Due to problems with the unit tests the use of utimensat() in pidfile()
was disabled, and forgotten.  This patch enables it, but beware, this
thing is QUICK on any system with a L2 cache or better.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-11 01:18:57 +02:00
Joachim Nilsson efc70e3a75 Update ChangeLog and bump version for v1.5.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-20 02:24:26 +01:00
Joachim Nilsson 147df0c6da ABI revision bump
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-20 02:21:33 +01:00
Joachim Nilsson 7f89000c6c pidfilefn.c: Update unittests, add mtime test and prettyfy output
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-20 02:15:35 +01:00
Joachim Nilsson 7607148d46 Build unit tests with -g -O0 for debugging
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-20 02:14:55 +01:00
Joachim Nilsson 979f76aea7 pidfile(): Use utimensat() to update atime+mtime
This patch update the `-lite` patch to OpenBSD `pidfile()` by changing
the update atime+mtime patch from writing the PID again to instead use
utimensat(). Less overhead and nanosecond resolution.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-20 02:14:30 +01:00
Joachim Nilsson ac41fa70aa Update ChangeLog and bump version to v1.5.0-dev
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-13 01:59:41 +01:00
Joachim Nilsson 5f820b17b6 Change namespace for header files libite/lite.h --> lite/lite.h
The `libite/` namespace for header files has been the same since the
first public release in v1.0.0.  This patch surprisingly changes it to
the less surprising `lite/`.  Hopefully there aren't that many users of
this library out there yet, apart from myself.

Apologies if you are affected!

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-13 01:58:56 +01:00
Joachim Nilsson 53b715c094 Remove surprise from pkg-config output
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-13 00:38:53 +01:00
Joachim Nilsson 1b4cd7b20b Update ChangeLog and bump version for v1.4.4 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-23 14:23:12 +01:00
Joachim Nilsson 8e379ca358 Update ChangeLog
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-22 19:11:29 +01:00
Joachim Nilsson 12241dcdfe libite.pc.in: Remove spurious @LTLIBINTL@ after copy-paste from libConfuse
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-20 22:26:24 +01:00
Joachim Nilsson 0ce1b3bf44 Add pkg-config support
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-20 22:03:25 +01:00
Joachim Nilsson 38ff0af61a Update ChangeLog with details on issue #3
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-15 18:20:25 +01:00
Joachim Nilsson 00737a5b74 Merge pull request #3 from askerin/tempfile-archfix
Tempfile() is dependent on $ARCH

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-12 16:15:53 +01:00
Joachim Nilsson 1b8b164ed4 Test build with both GCC and Clang (LLVM)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-12 16:15:15 +01:00
Joachim Nilsson 9f279c0fec Disable sudo for build while auto-tests are reintegrated
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-12 16:14:59 +01:00
Johan Askerin 4d7e6d4f78 In tempfile(): O_DIRECTORY is dependent on $ARCH, don't hardcore O_TMPFILE
Signed-off-by: Johan Askerin <johan.askerin@gmail.com>
2016-02-12 15:17:25 +01:00
Joachim Nilsson 0a57f2128f Update ChangeLog and bump version for v1.4.3 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-02 09:37:40 +01:00
Joachim Nilsson e254db48a8 Remove AUTHORS file from distribution, doesn't exist
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-02 08:40:14 +01:00
Joachim Nilsson 0fe429dcbe Update ChangeLog in preparation for v1.4.3 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-02 08:25:16 +01:00
Joachim Nilsson f1a2e01775 Makefile.am: Update to install and distribute README.md, LICENSE, etc.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-02 08:24:15 +01:00
Joachim Nilsson e5eef2ae59 Remove confusing symlinks, it's a brave Markdown world
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-02 08:22:13 +01:00
Joachim Nilsson f9caffc9b7 Update ChangeLog and bump version for v1.4.2 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-23 11:29:50 +01:00
Joachim Nilsson 604b503b84 Fix issue #2: GCC6 -Wmisleading-indentation causing FTBFS in pimd
- Add function comment
- Fix misleading indentaion
- Fix coding sttle

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-23 11:16:53 +01:00
Joachim Nilsson 5fc248522c Update ChangeLog and bump version for v1.4.1 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-22 01:07:35 +01:00
Joachim Nilsson c0b8bab164 Use pkginclude_HEADERS for libite include files
The v1.4.0 release installs the header files in $(prefix)/include, this
patch installs them in the proper $(prefix)/include/$(PACKAGE) dir.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-22 01:03:19 +01:00
Joachim Nilsson c0e9c0431a Bump version for 1.4.1-dev cycle
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-22 01:01:22 +01:00
Joachim Nilsson efdd61648a Update ChangeLog and bump version for release v1.4.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-22 00:05:01 +01:00
Joachim Nilsson 2e8e64fd2a Step ABI version 2:0:0 --> 2:1:0
Slight change in how `pidfile()` behaves, now exporting __pidfile_name.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-22 00:01:19 +01:00
Joachim Nilsson c4109e7e74 Add Niels Provos' famous splay and red-black tree implementation
This is the OpenBSD sys/tree.h r1.14

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-21 23:51:40 +01:00
Joachim Nilsson 5d07594709 Update pidfile() documentation and add unit test for __pidfile_name
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-21 23:30:08 +01:00
Joachim Nilsson 253460b4b8 Make pidfile() name accessible (read-only) to daemon as __pidfile_name
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-21 23:28:59 +01:00
Joachim Nilsson acc59e0c1f Remove AM_MAINTAINER_MODE from configure script, not recommended anymore
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-21 22:32:23 +01:00
Joachim Nilsson 90374fc237 README: Add a Build & Install section
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-18 20:11:19 +01:00
Joachim Nilsson 7f375b6e9d Remove -Werror due to O_TMPFILE is missing on older kernels
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-14 21:49:49 +01:00
Joachim Nilsson e4236db2bd Ignore all generated files from build system
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-14 21:43:02 +01:00
Joachim Nilsson 42a5a906fc ChangeLog: Prepare for upcoming v1.4.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-14 21:28:08 +01:00
Joachim Nilsson 10b28127f5 Update .gitignore, add bogus m4/.gitignore to make Travis-CI happy
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-14 21:27:04 +01:00
Joachim Nilsson d265a05422 Update build script for Travis-CI with GNU configure and build system
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-14 18:56:01 +01:00
Joachim Nilsson f07c05138d Initial conversion to the GNU configure and build system
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-14 17:40:26 +01:00
Joachim Nilsson e1f8224666 Update ChangeLog and bump version for release v1.3.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-07 02:58:06 +01:00
Joachim Nilsson 84650d8836 Update include file boiler plate
We're not in Kansas anymore, Toto.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-07 02:58:06 +01:00
Joachim Nilsson b4fbd54a8c Update copyright years
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-07 02:58:06 +01:00
Joachim Nilsson c14c6a1e62 pidfile.c: Add LITE #ifdef pidfile and comment LITE mtime extension
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-07 02:58:06 +01:00
Joachim Nilsson 8aecba2b7a strtonum.c: Update to OpenBSD v1.7, style tweaks
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-07 02:58:06 +01:00
Joachim Nilsson 74dcaddc55 strlcat.c: Update to OpenBSD v1.14, readability fixes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-07 02:57:59 +01:00
Joachim Nilsson c5a36ff7bd strlcpy.c: Update to OpenBSD v1.12, readability fixes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-07 02:57:51 +01:00
Joachim Nilsson 3371e42035 queue.h: Update to OpenBSD v1.43 -- NOTE: Removes CIRCLEQ support!
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-07 02:03:10 +01:00
Joachim Nilsson 4e57a78255 README: Update section on OpenBSD Functions as well
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-06 13:35:35 +01:00
Joachim Nilsson ce3bd4ec8a README: Update documentation for pidfile() fn
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-06 13:31:32 +01:00
Joachim Nilsson 805571a7ef ChangeLog: Fix missing README link
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-05 13:34:41 +01:00
Joachim Nilsson 36435997bf ChangeLog: Fix Markdown links
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-05 13:33:34 +01:00
Joachim Nilsson f961889724 Add documentation for new macros and prepare ChangeLog for v1.3.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-05 13:27:40 +01:00
Tobias Waldekranz 6605fb9771 Makefile: Make sure queue.h and conio.h also are installed
This patch adds the BSD queue.h and the Borland inspired conio.h to the
install-dev Makefile target.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-05 13:17:16 +01:00
Tobias Waldekranz 61254279b9 lite.h: Add min() and max() macros
These macros take care to avoid double evaluation.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-05 13:16:34 +01:00
Joachim Nilsson e42aca8856 Makefile: Split install-dev taget into install-dev and install-data
This makes it possible to skip installing any unnecessary cruft.
Useful for embedded targets.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-05 13:14:37 +01:00
Joachim Nilsson 16611f3e5f Add ChangeLog to project and bump version for new release cycle
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-05 13:13:26 +01:00
Joachim Nilsson 975df87d6b Update unit test for pidfile()
Add ocular verification step for mtime update when pidfile() is
called more than once.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-17 00:15:18 +01:00
Joachim Nilsson 148027674a pidfile: Only update mtime i called multiple times
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-16 18:40:34 +01:00
Joachim Nilsson 12ed342d55 Bump version for v1.2.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-23 00:32:56 +01:00
Joachim Nilsson 23badc990d lfile: Improve unittest/example with /etc/group + passwd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-26 00:50:18 +01:00
Joachim Nilsson ca53e097c3 lfile: Initialize strtok_r() save pointer
Must initialize the save pointer in the parser context, otherwise
strtok_r() will fail on statically built embedded targets.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-26 00:16:36 +01:00
Joachim Nilsson a7b5c240c1 Add UNIX lfile_t parser API to lite.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-25 23:25:17 +01:00
Joachim Nilsson c4eb5cb124 Add simple parser for UNIX configuration files.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-25 22:50:10 +01:00
Joachim Nilsson db08b20f23 Make sure we don't inherit LDFLAGS from environment.
To pass custom LDFLAGS to libite, use EXTRA_LDFLAGS.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-22 18:35:35 +02:00
Joachim Nilsson 8779f54125 Do not allow VERSION to be overloaded by build system.
When integrating libite as a component in another piece of software,
that build system may set VERSION as an environment variable.  We do
not want that version to be set as the version of libite.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-03 09:13:37 +02:00
Joachim Nilsson bd9a618ea3 Bump version for v1.1.1 patch release.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-27 00:59:54 +02:00
Joachim Nilsson 3f89fafe24 Fix macro definitions for compat APIs
Seems cpp is a bit uptight about spaces.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-27 00:56:20 +02:00
Joachim Nilsson ebec48d671 Silence annoying warnings from GNU ar
In (very) modern versions of binutils, for instance v2.25.1 shipped in
Ubuntu 15.10, ar complains about the VERY common `crus` argument.  This
patch silences this noise:

    $ make -j5
      ARCHIVE libite.a
    ar: `u' modifier ignored since `D' is the default (see `U')

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-27 00:55:26 +02:00
148 changed files with 12473 additions and 2531 deletions

No files matched your search

+193
View File
@@ -0,0 +1,193 @@
# CodeDocs.xyz Configuration File
#
# Rename this example to '.codedocs' and put it in the root directory of your
# repository. This file is optional, documentation will still be generated
# without it using sensible defaults.
#---------------------------------------------------------------------------
# CodeDocs Configuration
#---------------------------------------------------------------------------
# Include the Doxygen configuration from another file.
# The file must be a relative path with respect to the root of the repository.
# If any of the options in this doxyfile include a path (ie, INPUT), these
# paths will be considered relative to the root of the repository, not the
# location of the DOXYFILE.
DOXYFILE = doc/Doxyfile
# Specify external repository to link documentation with.
# This is similar to Doxygen's TAGFILES option, but will automatically link to
# tags of other repositories already using CodeDocs. List each repository to
# link with by giving its location in the form of owner/repository.
# For example:
# TAGLINKS = doxygen/doxygen CodeDocs/osg
# Note: these repositories must already be built on CodeDocs.
TAGLINKS =
#---------------------------------------------------------------------------
# Doxygen Configuration
#---------------------------------------------------------------------------
# Doxygen configuration may also be placed in this file.
# Currently, the following Doxygen configuration options are available. Refer
# to http://doxygen.org/manual/config.html for detailed explanation of the
# options. To request support for more options, contact support@codedocs.xyz.
#
# ABBREVIATE_BRIEF =
# ALIASES =
# ALLEXTERNALS =
# ALLOW_UNICODE_NAMES =
# ALPHABETICAL_INDEX =
# ALWAYS_DETAILED_SEC =
# AUTOLINK_SUPPORT =
# BRIEF_MEMBER_DESC =
# BUILTIN_STL_SUPPORT =
# CALLER_GRAPH =
# CALL_GRAPH =
# CASE_SENSE_NAMES =
# CITE_BIB_FILES =
# CLASS_DIAGRAMS =
# CLASS_GRAPH =
# COLLABORATION_GRAPH =
# COLS_IN_ALPHA_INDEX =
# CPP_CLI_SUPPORT =
# DIAFILE_DIRS =
# DIRECTORY_GRAPH =
# DISABLE_INDEX =
# DISTRIBUTE_GROUP_DOC =
# DOTFILE_DIRS =
# DOT_FONTNAME =
# DOT_FONTSIZE =
# DOT_GRAPH_MAX_NODES =
# DOT_IMAGE_FORMAT =
# DOT_TRANSPARENT =
# DOXYFILE_ENCODING =
# ENABLED_SECTIONS =
# ENABLE_PREPROCESSING =
# ENUM_VALUES_PER_LINE =
# EXAMPLE_PATH =
# EXAMPLE_PATTERNS =
# EXAMPLE_RECURSIVE =
EXCLUDE = src/README.md
# EXCLUDE_PATTERNS =
# EXCLUDE_SYMBOLS =
# EXPAND_AS_DEFINED =
# EXPAND_ONLY_PREDEF =
# EXTENSION_MAPPING =
# EXTERNAL_GROUPS =
# EXTERNAL_PAGES =
# EXTRACT_ALL =
# EXTRACT_ANON_NSPACES =
# EXTRACT_LOCAL_CLASSES =
# EXTRACT_LOCAL_METHODS =
# EXTRACT_PACKAGE =
# EXTRACT_PRIVATE =
# EXTRACT_STATIC =
# EXT_LINKS_IN_WINDOW =
# FILE_PATTERNS =
# FORCE_LOCAL_INCLUDES =
# FORMULA_FONTSIZE =
# FORMULA_TRANSPARENT =
# FULL_PATH_NAMES =
# GENERATE_BUGLIST =
# GENERATE_DEPRECATEDLIST =
# GENERATE_LEGEND =
# GENERATE_TESTLIST =
# GENERATE_TODOLIST =
# GENERATE_TREEVIEW =
# GRAPHICAL_HIERARCHY =
# GROUP_GRAPHS =
# GROUP_NESTED_COMPOUNDS =
# HIDE_COMPOUND_REFERENCE= =
# HIDE_FRIEND_COMPOUNDS =
# HIDE_IN_BODY_DOCS =
# HIDE_SCOPE_NAMES =
# HIDE_UNDOC_CLASSES =
# HIDE_UNDOC_MEMBERS =
# HIDE_UNDOC_RELATIONS =
# HTML_COLORSTYLE_GAMMA =
# HTML_COLORSTYLE_HUE =
# HTML_COLORSTYLE_SAT =
# HTML_DYNAMIC_SECTIONS =
# HTML_EXTRA_FILES =
# HTML_EXTRA_STYLESHEET =
# HTML_FOOTER =
# HTML_HEADER =
# HTML_INDEX_NUM_ENTRIES =
# HTML_STYLESHEET =
# HTML_TIMESTAMP =
# IDL_PROPERTY_SUPPORT =
# IGNORE_PREFIX =
# IMAGE_PATH =
# INCLUDED_BY_GRAPH =
# INCLUDE_FILE_PATTERNS =
# INCLUDE_GRAPH =
# INCLUDE_PATH =
# INHERIT_DOCS =
# INLINE_GROUPED_CLASSES =
# INLINE_INFO =
# INLINE_INHERITED_MEMB =
# INLINE_SIMPLE_STRUCTS =
# INLINE_SOURCES =
INPUT = src/ README.md doc/API.md
# INPUT_ENCODING =
# INTERACTIVE_SVG =
# INTERNAL_DOCS =
# JAVADOC_AUTOBRIEF =
# LAYOUT_FILE =
# MACRO_EXPANSION =
# MARKDOWN_SUPPORT =
# MAX_DOT_GRAPH_DEPTH =
# MSCFILE_DIRS =
# MULTILINE_CPP_IS_BRIEF =
# OPTIMIZE_FOR_FORTRAN =
# OPTIMIZE_OUTPUT_FOR_C =
# OPTIMIZE_OUTPUT_JAVA =
# OPTIMIZE_OUTPUT_VHDL =
# OUTPUT_LANGUAGE =
# PLANTUML_JAR_PATH =
# PREDEFINED =
# PROJECT_BRIEF =
# PROJECT_LOGO =
# PROJECT_NAME =
# PROJECT_NUMBER =
# QT_AUTOBRIEF =
# RECURSIVE =
# REFERENCED_BY_RELATION =
# REFERENCES_LINK_SOURCE =
# REFERENCES_RELATION =
# REPEAT_BRIEF =
# SEARCHENGINE =
# SEARCH_INCLUDES =
# SEPARATE_MEMBER_PAGES =
# SHORT_NAMES =
# SHOW_FILES =
# SHOW_GROUPED_MEMB_INC =
# SHOW_INCLUDE_FILES =
# SHOW_NAMESPACES =
# SHOW_USED_FILES =
# SIP_SUPPORT =
# SKIP_FUNCTION_MACROS =
# SORT_BRIEF_DOCS =
# SORT_BY_SCOPE_NAME =
# SORT_GROUP_NAMES =
# SORT_MEMBERS_CTORS_1ST =
# SORT_MEMBER_DOCS =
# SOURCE_BROWSER =
# SOURCE_TOOLTIPS =
# STRICT_PROTO_MATCHING =
# STRIP_CODE_COMMENTS =
# STRIP_FROM_INC_PATH =
# STRIP_FROM_PATH =
# SUBGROUPING =
# TAB_SIZE =
# TEMPLATE_RELATIONS =
# TREEVIEW_WIDTH =
# TYPEDEF_HIDES_STRUCT =
# UML_LIMIT_NUM_FIELDS =
# UML_LOOK =
USE_MDFILE_AS_MAINPAGE = README.md
# VERBATIM_HEADERS =
#
+90
View File
@@ -0,0 +1,90 @@
Contributing to the Project
===========================
Thank you for considering contributing back to [Free Software][1]!
There are a few things we would like you to consider when filing an
issue or pull request with this project:
1. If you are filing a bug report or feature request
Please take the time to check if an issue already has been filed
matching your problem
2. What version are you running, have you tried the latest release?
UNIX distributions often package and test software for their
particular brand. If you are using a pre-packaged version,
then please file a bug with that distribution instead.
3. Coding Style
Lines are allowed to be longer than 72 characters these days, there
is no enforced max. length.
> **Tip:** Always submit code that follows the style of surrounding code!
The coding style itself is strictly Linux [KNF][], like GIT it is
becoming a de facto standard for C programming
https://www.kernel.org/doc/Documentation/CodingStyle
4. Logical Change Sets
Changes should be broken down into logical units that add a feature
or fix a bug. Keep changes separate from each other and do not mix a
bug fix with a whitespace cleanup or a new feature addition.
This is important not only for readability, or for the possibility of
maintainers to revert changes, but does also increase your chances of
having a change accepted.
5. Commit messages
Commit messages exist to track *why* a change was made. Try to be as
clear and concise as possible in your commit messages, and always, be
proud of your work and set up a proper GIT identity for your commits:
git config --global user.name "J. Random Hacker"
git config --global user.email random.j.hacker@example.com
See this helpful guide for how to write simple, readable commit
messages, or have at least a look at the below example.
http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
Example
-------
Example commit message from the [Pro Git][gitbook] online book, notice
how `git commit -s` is used to automatically add a `Signed-off-by`:
Capitalized, short (50 chars or less) summary
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body. The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.
Write your commit message in the imperative: "Fix bug" and not "Fixed bug"
or "Fixes bug." This convention matches up with commit messages generated
by commands like git merge and git revert.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, followed by a
single space, with blank lines in between, but conventions vary here
- Use a hanging indent
Signed-off-by: J. Random Hacker <random.j.hacker@example.com>
[1]: http://www.gnu.org/philosophy/free-sw.en.html
[KNF]: https://en.wikipedia.org/wiki/Kernel_Normal_Form
[gitbook]: https://git-scm.com/book/ch5-2.html
+3
View File
@@ -0,0 +1,3 @@
# These are supported funding model platforms
github: [troglobit]
+12
View File
@@ -0,0 +1,12 @@
# Security Policy
## Supported Versions
libite (-lite) is a small project, as such we have no possibility to support older versions.
The only supported version is the latest released on GitHub:
<https://github.com/troglobit/libite/releases>
## Reporting a Vulnerability
Contact the project's main author and owner to report and discuss vulnerabilities.
+71
View File
@@ -0,0 +1,71 @@
name: Bob the Builder
# Run on all branches, including all pull requests, except the 'dev'
# branch since that's where we run Coverity Scan (limited tokens/day)
on:
push:
branches:
- '**'
- '!dev'
pull_request:
branches:
- '**'
jobs:
build:
# Verify we can build on latest Ubuntu with both gcc and clang
name: ${{ matrix.compiler }}
runs-on: ubuntu-latest
strategy:
matrix:
compiler: [gcc, clang]
fail-fast: false
env:
MAKEFLAGS: -j3
CC: ${{ matrix.compiler }}
steps:
- name: Install dependencies
run: |
sudo apt-get -y update
sudo apt-get -y install tree doxygen
- uses: actions/checkout@v4
- name: Configure
run: |
./autogen.sh
./configure --prefix= --disable-silent-rules
- name: Build
run: |
make
- name: Install to ~/tmp and Inspect
run: |
DESTDIR=~/tmp make install-strip
tree ~/tmp
- name: Run Unit Tests
run: |
make check || (cat test/test-suite.log; false)
- name: Upload Test Results
uses: actions/upload-artifact@v4
with:
name: libite-test-${{ matrix.compiler }}
path: test/*
debian:
name: Verify Debian Package
runs-on: ubuntu-latest
container: debian:stable
env:
MAKEFLAGS: -j3
steps:
- uses: actions/checkout@v4
- name: Installing dependencies
run: |
apt-get update
apt-get install -y build-essential autoconf automake pkg-config doxygen \
dpkg-dev debhelper devscripts
- name: Building Debian package
run: |
./autogen.sh
./configure
make check || (cat test/test-suite.log; false)
make distcheck
make package
cat ../*.changes
+80
View File
@@ -0,0 +1,80 @@
name: Coverity Scan
on:
push:
branches:
- 'dev'
env:
PROJECT_NAME: libite
CONTACT_EMAIL: troglobit@gmail.com
COVERITY_NAME: troglobit-libite
COVERITY_PROJ: troglobit%2Flibite
jobs:
coverity:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fetch latest Coverity Scan MD5
id: var
env:
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
run: |
wget -q https://scan.coverity.com/download/cxx/linux64 \
--post-data "token=$TOKEN&project=${COVERITY_PROJ}&md5=1" \
-O coverity-latest.tar.gz.md5
echo "md5=$(cat coverity-latest.tar.gz.md5)" | tee -a $GITHUB_OUTPUT
- uses: actions/cache@v4
id: cache
with:
path: coverity-latest.tar.gz
key: ${{ runner.os }}-coverity-${{ steps.var.outputs.md5 }}
restore-keys: |
${{ runner.os }}-coverity-${{ steps.var.outputs.md5 }}
${{ runner.os }}-coverity-
${{ runner.os }}-coverity
- name: Download Coverity Scan
env:
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
run: |
if [ ! -f coverity-latest.tar.gz ]; then
wget -q https://scan.coverity.com/download/cxx/linux64 \
--post-data "token=$TOKEN&project=${COVERITY_PROJ}" \
-O coverity-latest.tar.gz
else
echo "Latest Coverity Scan available from cache :-)"
md5sum coverity-latest.tar.gz
fi
mkdir coverity
tar xzf coverity-latest.tar.gz --strip 1 -C coverity
- name: Install dependencies
run: |
sudo apt-get -y update
sudo apt-get -y install pkg-config
- name: Configure
run: |
./autogen.sh
./configure --prefix= --disable-silent-rules
- name: Build
run: |
export PATH=`pwd`/coverity/bin:$PATH
cov-build --dir cov-int make
- name: Submit results to Coverity Scan
env:
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
run: |
tar czvf ${PROJECT_NAME}.tgz cov-int
curl \
--form project=${COVERITY_NAME} \
--form token=$TOKEN \
--form email=${CONTACT_EMAIL} \
--form file=@${PROJECT_NAME}.tgz \
--form version=trunk \
--form description="${PROJECT_NAME} $(git rev-parse HEAD)" \
https://scan.coverity.com/builds?project=${COVERITY_PROJ}
- name: Upload build.log
uses: actions/upload-artifact@v4
with:
name: coverity-build.log
path: cov-int/build-log.txt
+37
View File
@@ -0,0 +1,37 @@
name: Release General
on:
push:
tags:
- 'v*'
jobs:
release:
name: Build and upload release tarball
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Installing dependencies ...
run: |
sudo apt-get -y update
sudo apt-get -y install tree doxygen
- name: Creating Makefiles ...
run: |
./autogen.sh
./configure --prefix=
- name: Build release ...
run: |
make release
mkdir -p artifacts/
mv ../*.tar.* artifacts/
- name: Extract ChangeLog entry ...
run: |
awk '/-----*/{if (x == 1) exit; x=1;next}x' ChangeLog.md \
|head -n -1 > release.md
cat release.md
- uses: ncipollo/release-action@v1
with:
name: Libite (-lite) ${{ github.ref_name }}
bodyFile: "release.md"
artifacts: "artifacts/*"
+21 -5
View File
@@ -1,5 +1,21 @@
*.d
*.o
*.so
*.so.*
*.a
*~
ID
GPATH
GRTAGS
GTAGS
compile
config.*
configure
depcomp
install-sh
libtool
ltmain.sh
missing
stamp-h1
Makefile
Makefile.in
aclocal.m4
ar-lib
autom4te.cache
test-driver
libite.pc
-11
View File
@@ -1,11 +0,0 @@
# Travis CI integration -- https://travis-ci.org/troglobit/libuev
# Defaults to GNU GCC and autotools: ./configure && make && make test
language: c
# Some of the autotests may use sudo, so use non-dockerized build atm.
# http://stackoverflow.com/questions/26299552/travis-sudo-is-disabled
sudo: true
script:
- make
- make test
+567
View File
@@ -0,0 +1,567 @@
Change Log
==========
All notable changes to the project are documented in this file.
[v2.6.2][] - 2025-11-22
-----------------------
### Fixes
- Fix memory leak in `which()` on `realloc()` failure
- Fix `pidfile()` to handle missing trailing slash in prefix path
[v2.6.1][] - 2023-10-15
-----------------------
### Fixes
- FTBFS uClibc and musl libc, `lite.h` missing `stdarg.h` include
[v2.6.0][] - 2023-09-17
-----------------------
### Changes
- New APIs from the [Infix Project](https://github.com/kernelkit/infix):
- `fexistf()`
- `vfopenf()`
- `popenf()`
- `vreadsnf()`, `readsnf()`, `writesf()`
- `vreadllf()`, `readllf()`, `readdf()`
- `writellf()`, `writedf()`
### Fixes
- Spellchecking of API docs
[v2.5.3][] - 2023-04-08
-----------------------
### Changes
- Refactor `copyfile()` unit test and verify number of bytes copied
- Add missing `rsync()` unit test to ensure proper function
### Fixes
- `rsync()` does not copy single files correctly
- `copyfile()` does not handle empty source files correctly (error)
- `copyfile()` does not properly create destination dir
[v2.5.2][] - 2022-04-17
-----------------------
### Changes
- Add printf format attribute hint to all vararg functions. This will
help users of these functions by telling CC what to look for
### Fixes
- Fix `fisdir()` segfault on GNU/Hurd
- Fix `touch)` on Debian/kFreeBSD, use `creat()` instad of `mknod()`
[v2.5.1][] - 2021-12-02
-----------------------
Debian-only fix.
### Fixes
- Use `dh_link(1)` to install `/usr/include/lite -> libite/`. The
symlink created by libite installer itself is not kept.
[v2.5.0][] - 2021-11-30
-----------------------
> **Note:** namespace change; the -lite library include files have moved
> from `lite/*.h` to `libite/*.h` due to an unfortunate clash
> with "LiTE is a Toobox Engine", from the DirectFB project.
> For a transitional period, however, a compatibility symlink
> is installed; `lite -> libite/`.
### Changes
- Header files have moved from `lite/*.h` to `libite/*.h` to prevent
clashing with DirectFB LiTE library.
- Include guards in header files have been renamed, much in the same
fashion as the move (above), from `LITE_foo_H_` to `LIBITE_FOO_H_`
- Add configure option to disable compatibility symlink, for systems
that do not want name clashes with DirectFB/LiTE, or do not need to
be backwards compatible; use `configure --without-symlink`
### Fixes
- Minor, use defensive coding in `strnlen()` replacement. Only used
on systems that do not have a native implementation.
[v2.4.1][] - 2021-10-09
-----------------------
### Changes
- Add doxygen API documentation to project, included in tarball, and
automatically generated at https://codedocs.xyz/troglobit/libite/
- Relocate `tests/` to `test/` in source tree
- Relocate `docs/` to `doc/` in source tree
### Fixes
- Prefix CFLAGS/CPPFLAGS/etc with `AM_` in `test/Makefile.am` to prevent
clashing with environment. Fix imported from libuEv
- Replace obsolete `AM_CONFIG_HEADER` with `AC_CONFIG_HEADERS`
- Fix issue with `tempfile()` returning EOPNOTSUPP on Azure, use
fallback to `mkostemp()` with `O_CLOEXEC` flag set
[v2.4.0][] - 2021-03-27
-----------------------
### Changes
- Add support for `touchf()`, formatted string support for `touch()`
- Add support for `erasef()`, formatted string support for `erase()`
- Add support for `strtrim()`, trims leading and trailing white-space
from a string
### Fixes
- Fix `systemf()` improper handling of `system()` return value. Now
checks if exited OK, then returning the exit status of the command, or
if not exited OK, then checks if the command was signaled, and returns
-1 with `errno` set. This also allows for returning 127, like
`system()`, if the shell, or the program itself, did not exist
[v2.3.1][] - 2021-02-12
-----------------------
### Changes
- Copyright updates, including LICENSE file, year + author last name
### Fixes
- Debian packaging fixes only
[v2.3.0][] - 2021-02-12
-----------------------
### Changes
- Add support for `fremove()`, formatted `remove()` replacement
- Add support for `truncatef()`, formatted `truncate()` replacement
- Add tar.gz archives to distribution
### Fixes
- Handle `ETIMEDOUT` error for `connect()` call in `telnet_open()`
[v2.2.0][] - 2020-03-16
-----------------------
### Changes
- Add support for `systemf()`, formatted string `system()` replacement
- Add support for `fmkpath()`, formatted string `mkpath()`
- Add support for `fopenf()`, formatted string `fopen()` replacement
### Fixes
- Fix possible memory leak in `rsync()`, found by Coverity Scan
- Check return value of `fstat()` to prevent bogus destination file
times when using `copyfile()`, found by Coverity Scan
[v2.1.2][] - 2020-02-22
-----------------------
### Fixes
- Fix Debian package upgrade from libite -> libite5
[v2.1.1][] - 2020-02-22
-----------------------
### Changes
- Add test/example for `printhdr()`
- Update copyright years
### Fixes
- chomp: Check for beginning of string while removing \n's
[v2.1.0][] - 2019-08-26
-----------------------
### Changes
- Add support for `strmatch()` and `strnmatch()`
- Add support for `yorn()`, safe yes-or-no prompt
- Add support for telnet expect/session APIs
- Add modified `printhdr()` which takes ANSI attribute
### Fixes
- Fix `pidfile_signal()`: always return result of `kill()`, or the
result of `remove()` if we successfully sent `SIGKILL`
- Fix `strtonum()`: POSIX `strtoll()` returns `EINVAL`, check that
- Fix #13, support C++ `extern "C" {}` for header files
[v2.0.2][] - 2018-05-10
-----------------------
### Fixes
- Fix issue #12, missing includes in `strlite.h` for standalone use
- FTBFS `strtonum.c` on older systems w/o `LLONG_MAX` and `LLONG_MIN`
[v2.0.1][] - 2017-12-22
-----------------------
### 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
-----------------------
### Changes
- Support absolute path in `pidfile()`. Needed by, e.g. Inadyn
- Add initial `debian/` packaging
- Update README with note on remembering to set `umask()`
### Fixes
- In use-cases when `pidfile()` is called consecutively, e.g. on
`SIGHUP`, recreate PID file if it no longer exists
[v1.8.2][] - 2016-09-05
-----------------------
### Changes
- Updated build instructions in README.
- Converted `touch()`, `makedir()`, `makefifo()`, and `erase()` from
macros to inline functions. Also removed implicit logging to stderr
on error.
### Fixes
- Fix small memory leak in `pidfile()` ... at exit.
- Fixes for building on musl libc
[v1.8.1][] - 2016-06-25
-----------------------
### Fixes
- `fparseln()`, portability fix for NetBSD
- `pidfile()`, portability fix for NetBSD and OpenBSD
[v1.8.0][] - 2016-06-06
-----------------------
### Changes
- Change return type of `fsendfile()` from `size_t` to `ssize_t`
- Change `dir()` semantics: do not assert and always return error
without calling `perror()` or similar.
- The OpenBSD `pidfile()` function's prefix path `_PATH_VARRUN`
can now be overridden by setting the hidden `__pidfile_path`
variable. E.g., to `_PATH_TMP`. Make sure read the docs!
- Add new unit test framework `make check`.
### Fixes
- Fix bad path in new `strndupa()` header file.
- Add missing progress bar API's to `lite.h`
[v1.7.0][] - 2016-06-05
-----------------------
### Changes
- Add support for GNU `strdupa()`, for [Inadyn][] on NetBSD.
- Add support for GNU `strndupa()` and `strnlen()`
### Fixes
- Fix `mkpath()` to handle creating relative directories.
[v1.6.0][] - 2016-05-13
-----------------------
### Changes
- Add support for NetBSD `fparaseln()` for the benefit of [Mg][]
- Add support for OpenBSD `reallocarray()` for the benefit of [Mg][]
- Constify `fisdir()` argument
[v1.5.1][] - 2016-04-17
-----------------------
Minor fix release.
### Changes
- Update README.md, add help when libite is used in autotools projects.
Spell checking and minor cleanup.
### Fixes
- Activate use of `utimensat()` when `pidfile()` is called multiple
times. This reduces the overhead of calling open+write+close to
simply updating the mtime of the PID file.
- Westermo fixes for `fcopyfile()`: nothing copied on embedded PPC
system when using `tmpfile()` as source.
[v1.5.0][] - 2016-03-20
-----------------------
This release changes the header file namespace. Apologies for any
problems this may cause!
### Changes
- Change namespace for header files: `libite/` to `lite/`, e.g. using
`pkg-config` your C program must now `#include <lite/lite.h>`
- Update `pidfile()` to use `utimensat()` to update atime+mtime instead
of opening and writing PID again. Less overhead and nanonsecond res.
[v1.4.4][] - 2016-02-23
-----------------------
### Changes
- Add `ibite.pc.in` for `pkg-config` support.
### Fixes
- Fix issue #3: `tempfile()` fails with bad `O_TMPFILE` on some embedded
targets, in particular PowerPC. On systems with older GLIBC but with
a sufficiently new kernel `O_TMPFILE` is missing and the local libite
definition was wrong, hard coded for x86. Fixed by Johan Askerin.
[v1.4.3][] - 2016-02-02
-----------------------
### Fixes
- Remove symlinks to Markdown files from GIT
- Distribute and install Markdown files: README.md, etc.
[v1.4.2][] - 2016-01-23
-----------------------
### Fixes
- Fix issue #2: GCC6 `-Wmisleading-indentation` causing FTBFS in pimd,
which enables `-Werror`
[v1.4.1][] - 2016-01-22
-----------------------
### Fixes
- Fix install path for include files, regression in v1.4.0 With the
introduction of GNU autotools include file namespace was unfortunately
lost. All include files were therefore installed in $(prefix)/include
instead of $(prefix)/include/libite.
[v1.4.0][] - 2016-01-22
-----------------------
### Changes
- Change to GNU configure and build system
- Add Niels Provos' splay and red-black tree implementation from OpenBSD
`sys/tree.h`, r1.14
- Make `pidfile()` file name accessible as `__pidfile_name`
- Step ABI revision to 2.1, with help from http://250bpm.com/blog:41
[v1.3.0][] - 2016-01-07
-----------------------
### Changes
- Add highly useful typeless `min()`/`max()` macros to `lite.h`,
courtesy of Tobias Waldekranz
- Add BSD `queue.h` and Borland inspired `conio.h` to `install-dev`
target. Needed by [Finit][].
- Note, this release update `queue.h` to OpenBSD v1.43, which removes
support for circular queues (CIRCLEQ).
- Update `strlcpy.c` to OpenBSD v1.12, readability fixes.
- Update `strlcat.c` to OpenBSD v1.14, readability fixes.
- Update `strtonum.c` to OpenBSD v1.7, tiniest of style tweaks.
### Fixes
- Only update mtime if `pidfile()` is called more than once, do not
install multiple `atexit()` handlers.
- Add `#ifndef pidfile`, as for other BSD functions, in case the user
already have a local copy, or a C library with one.
[v1.2.0][] - 2015-11-23
-----------------------
### Changes
- Add simple parser for UNIX configuration files, e.g. `/etc/group`,
`/etc/passwd`, and `/etc/protocols`:
- `lfopen()`
- `lfclose()`
- `lftok()`
- `lfgetkey()`
- `lfgetint()`
- `fgetint()`
### Fixes
- Do not allow `VERSION` to be overloaded by build system.
- Make sure we don't inherit `LDFLAGS` from environment.
[v1.1.1][] - 2015-09-27
-----------------------
### Fixes
* Silence annoying warnings from GNU ar
* Fix macro definitions for compat APIs
[v1.1.0][] - 2015-09-16
-----------------------
### Changes
- Support for `make distdir` used by automake based projects
- `lite.h` move from `error.h` to more BSD friendly `err.h`
- Add highly useful `NELEMS()` and bitmanip macros
- Lots of autotests added
- Add support for running autotests from Travis
- Add `progress()` simple progress bar
- Add `tree()` simple command line tree replacement
- Bump `SONAME` to `libite.so.2` on behalf of [Finit][]
### Fixes
- `pidfile()` upgrade to OpenBSD r1.11
- Lots of README updates, fixes and additions
[v1.0.0][] - 2015-07-12
-----------------------
Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
[UNRELEASED]: https://github.com/troglobit/libite/compare/v2.6.2...HEAD
[v2.6.2]: https://github.com/troglobit/libite/compare/v2.6.1...v2.6.2
[v2.6.1]: https://github.com/troglobit/libite/compare/v2.6.0...v2.6.1
[v2.6.0]: https://github.com/troglobit/libite/compare/v2.5.3...v2.6.0
[v2.5.3]: https://github.com/troglobit/libite/compare/v2.5.2...v2.5.3
[v2.5.2]: https://github.com/troglobit/libite/compare/v2.5.1...v2.5.2
[v2.5.1]: https://github.com/troglobit/libite/compare/v2.5.0...v2.5.1
[v2.5.0]: https://github.com/troglobit/libite/compare/v2.4.1...v2.5.0
[v2.4.1]: https://github.com/troglobit/libite/compare/v2.4.0...v2.4.1
[v2.4.0]: https://github.com/troglobit/libite/compare/v2.3.1...v2.4.0
[v2.3.1]: https://github.com/troglobit/libite/compare/v2.3.0...v2.3.1
[v2.3.0]: https://github.com/troglobit/libite/compare/v2.2.1...v2.3.0
[v2.2.1]: https://github.com/troglobit/libite/compare/v2.2.0...v2.2.1
[v2.2.0]: https://github.com/troglobit/libite/compare/v2.1.2...v2.2.0
[v2.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.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.0]: https://github.com/troglobit/libite/compare/v1.7.0...v1.8.0
[v1.7.0]: https://github.com/troglobit/libite/compare/v1.6.0...v1.7.0
[v1.6.0]: https://github.com/troglobit/libite/compare/v1.5.1...v1.6.0
[v1.5.1]: https://github.com/troglobit/libite/compare/v1.5.0...v1.5.1
[v1.5.0]: https://github.com/troglobit/libite/compare/v1.4.4...v1.5.0
[v1.4.4]: https://github.com/troglobit/libite/compare/v1.4.3...v1.4.4
[v1.4.3]: https://github.com/troglobit/libite/compare/v1.4.2...v1.4.3
[v1.4.2]: https://github.com/troglobit/libite/compare/v1.4.1...v1.4.2
[v1.4.1]: https://github.com/troglobit/libite/compare/v1.4.0...v1.4.1
[v1.4.0]: https://github.com/troglobit/libite/compare/v1.3.0...v1.4.0
[v1.3.0]: https://github.com/troglobit/libite/compare/v1.2.0...v1.3.0
[v1.2.0]: https://github.com/troglobit/libite/compare/v1.1.1...v1.2.0
[v1.1.1]: https://github.com/troglobit/libite/compare/v1.1.0...v1.1.1
[v1.1.0]: https://github.com/troglobit/libite/compare/v1.0.0...v1.1.0
[v1.0.0]: https://github.com/troglobit/libite/compare/TAIL...v1.0.0
[Finit]: https://github.com/troglobit/finit/
[Inadyn]: https://github.com/troglobit/inadyn/
[Mg]: https://github.com/troglobit/mg
[README]: https://github.com/troglobit/libite/blob/v1.0.0/README.md
+1 -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-2015 Joachim Nilsson <troglobit@gmail.com>
Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
-125
View File
@@ -1,125 +0,0 @@
# libite -- Light-weight utility functions and C-library extensions
#
# Copyright (c) 2008-2015 Joachim Nilsson <troglobit@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# 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.
.PHONY: install test
#VERSION = $(shell git tag -l | tail -1)
VERSION ?= 1.1.0
NAME = libite
PKG = $(NAME)-$(VERSION)
ARCHIVE = $(PKG).tar.xz
CFLAGS += -fPIC
CPPFLAGS += -W -Wall
DISTFILES = README LICENSE
HEADERS = lite.h
OBJS := chomp.o copyfile.o dir.o fexist.o fisdir.o fmode.o fsendfile.o
OBJS += ifconfig.o makepath.o pidfile.o pidfilefn.o progress.o rsync.o
OBJS += strlcpy.o strlcat.o strtonum.o tempfile.o tree.o
DEPS := $(OBJS:.o=.d)
JUNK = *~ *.bak *.map .*.d *.d DEADJOE semantic.cache *.gdb *.elf core core.*
VER = 2
LIBNAME = $(NAME)
SOLIB = $(LIBNAME).so.$(VER)
SYMLIB = $(LIBNAME).so
STATICLIB = $(LIBNAME).a
TARGET = $(STATICLIB) $(SOLIB)
# This magic trick looks like a comment, but works on BSD PMake
#include <rules.mk>
include rules.mk
test: clean
$(MAKE) -f chomp.mk
$(MAKE) -f copyfile.mk
$(MAKE) -f dir.mk
$(MAKE) -f fexist.mk
$(MAKE) -f fisdir.mk
$(MAKE) -f fsendfile.mk
$(MAKE) -f makepath.mk
$(MAKE) -f pidfilefn.mk
$(MAKE) -f progress.mk
$(MAKE) -f rsync.mk
$(MAKE) -f tempfile.mk
$(MAKE) -f tree.mk
$(OBJS): Makefile
$(SOLIB): Makefile $(OBJS)
$(PRINT) " LINK %s\n" $@
$(Q)$(CC) $(LDFLAGS) -shared -Wl,-soname,$@ -o $@ $(OBJS)
$(STATICLIB): Makefile $(OBJS)
$(Q)$(PRINT) " ARCHIVE $@\n"
$(Q)$(AR) $(ARFLAGS) $@ $(OBJS)
install-exec: all
$(PRINT) " INSTALL $(DESTDIR)$(libdir)/$(SOLIB)\n"
$(Q)install -d $(DESTDIR)$(libdir)
$(Q)$(STRIPINST) $(SOLIB) $(DESTDIR)$(libdir)/$(SOLIB)
$(Q)ln -sf $(SOLIB) $(DESTDIR)$(libdir)/$(SYMLIB)
install-dev:
$(Q)install -d $(DESTDIR)$(incdir)/$(LIBNAME)
$(Q)for file in $(HEADERS); do \
printf " INSTALL $(DESTDIR)$(incdir)/$(LIBNAME)/$$file\n"; \
$(INSTALL) -m 0644 $$file $(DESTDIR)$(incdir)/$(LIBNAME)/$$file; \
done
$(PRINT) " INSTALL $(DESTDIR)$(libdir)/$(STATICLIB)\n"
$(Q)install -d $(DESTDIR)$(libdir)
$(Q)$(INSTALL) $(STATICLIB) $(DESTDIR)$(libdir)/$(STATICLIB)
$(Q)install -d $(DESTDIR)$(datadir)
$(Q)for file in $(DISTFILES); do \
printf " INSTALL $(DESTDIR)$(datadir)/$$file\n"; \
install -m 0644 $$file $(DESTDIR)$(datadir)/$$file; \
done
install: install-exec install-dev
uninstall:
-$(Q)$(RM) -r $(DESTDIR)$(datadir)
-$(Q)$(RM) -r $(DESTDIR)$(incdir)/$(LIBNAME)
-$(Q)$(RM) $(DESTDIR)$(libdir)/$(SOLIB)
-$(Q)$(RM) $(DESTDIR)$(libdir)/$(SYMLIB)
-$(Q)$(RM) $(DESTDIR)$(libdir)/$(STATICLIB)
strip: $(TARGET)
$(Q)$(PRINT) " STRIP %s\n" $(TARGET)
$(Q)$(STRIP) --strip-unneeded $(TARGET)
$(Q)size $(TARGET)
# Runs Clang scan-build on the whole tree
check: clean
$(Q)scan-build $(MAKE) all
# When called from GNU configure and build system
distdir:
@git archive --format=tar HEAD | (cd $(distdir); tar xf -)
dist:
$(Q)echo "Building .xz tarball of $(PKG) in parent dir..."
git archive --format=tar --prefix=$(PKG)/ v$(VERSION) | xz >../$(ARCHIVE)
$(Q)(cd ..; md5sum $(ARCHIVE) | tee $(ARCHIVE).md5)
# Include automatically generated rules
-include $(DEPS)
+58
View File
@@ -0,0 +1,58 @@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src test
doc_DATA = README.md LICENSE ChangeLog.md
EXTRA_DIST = README.md LICENSE ChangeLog.md
if ENABLE_DOXYGEN
SUBDIRS += doc
.PHONY: doc
doc:
$(MAKE) -C @top_builddir@/doc $@
## The distribution should include man pages, which are generated
dist-hook: doc
else
doc:
@echo "Doxygen documentation (html + man) disabled, skipping ..."
endif
## Check if tagged in git
release-hook:
@if [ ! `git tag -l v$(PACKAGE_VERSION) | grep $(PACKAGE_VERSION)` ]; then \
echo; \
printf "\e[1m\e[41mCannot find release tag $(PACKAGE_VERSION)\e[0m\n"; \
printf "\e[1m\e[5mDo release anyway?\e[0m "; read yorn; \
if [ "$$yorn" != "y" -a "$$yorn" != "Y" ]; then \
printf "OK, aborting release.\n"; \
exit 1; \
fi; \
echo; \
else \
echo; \
printf "\e[1m\e[42mFound GIT release tag $(PACKAGE_VERSION)\e[0m\n"; \
printf "\e[1m\e[44m>>Remember to push tags!\e[0m\n"; \
echo; \
fi
## Generate .deb package
package:
@debuild -uc -us -B --lintian-opts --profile debian -i -I --show-overrides
## Target to run when building a release
release: release-hook distcheck
@for file in $(DIST_ARCHIVES); do \
md5sum $$file > ../$$file.md5; \
sha256sum $$file > ../$$file.sha256; \
done
@mv $(DIST_ARCHIVES) ../
@echo
@echo "Resulting release files:"
@echo "================================================================="
@for file in $(DIST_ARCHIVES); do \
printf "%-32s Distribution tarball\n" $$file; \
printf "%-32s " $$file.md5; cat ../$$file.md5 | cut -f1 -d' '; \
printf "%-32s " $$file.sha256; cat ../$$file.sha256 | cut -f1 -d' '; \
done
@for file in `cd ..; ls $(PACKAGE)*_$(VERSION)*`; do \
printf "%-32s Debian/Ubuntu package\n" $$file; \
done
-1
View File
@@ -1 +0,0 @@
README.md
+140 -243
View File
@@ -1,252 +1,149 @@
-lite | Frog DNA, basically
===========================
[![Travis Status][]][Travis]
[![GitHub Status][]][GitHub] [![codedocs status][]][codedocs] [![Coverity Status][]][Coverity Scan]
Libite is a lightweight library of *frog DNA*. It can be used to fill
Table of Contents
-----------------
* [Introduction](#introduction)
* [Using -lite](#using--lite)
* [API](doc/API.md#overview)
* [Important Node](doc/API.md#important-note)
* [Helper Macros](doc/API.md#helper-macros)
* [Generic Functions](doc/API.md#generic-functions)
* [GNU Functions](doc/API.md#gnu-functions)
* [OpenBSD/NetBSD/FreeBSD Functions](doc/API.md#openbsd-netbsd-freebsd-functions)
* [Build & Install](#build--install)
* [Origin & References](#origin--references)
> **NOTE:** Incompatible changes in v2.0 compared to v1.x!
Introduction
------------
Libite is a lightweight library of *frog DNA* that can be used to fill
the gaps in any dinosaur project. It holds useful functions and macros
developed by both [Finit][1] and the [OpenBSD][2] project. Most notably
the string functions: [strlcpy(3)][3], [strlcat(3)][3] and the highly
useful *BSD [sys/queue.h][4] API.
useful *BSD [sys/queue.h][4] and [sys/tree.h][7] API's.
Libite aims to fill in the gaps missing in GLIBC/EGLIBC. (It does not
aimo to become another [GLIB][5] though.) One such gap in GLIBC is the
missing `_SAFE` macros in `sys/queue.h` &mdash; highly recommended when
traversing lists to delete/free nodes.
Libite holds many of the missing pieces in GNU libc, although -lite does
not aim to become another [GLIB][5]. One noticeable gap in GLIBC is the
`_SAFE` macros available in the BSD `sys/queue.h` API &mdash; highly
recommended when traversing lists to delete/free nodes.
The code is open sourced under a mix of the [MIT/X11 license][MIT], the
[ISC license][ISC] used by OpenBSD, and [BSD licenses][BSD], all of them
are extremely liberal and can be used freely in proprietary software if
needed.
The code is open sourced under a mix of permissive Open Source licenses:
[MIT/X11 license][MIT], [ISC license][ISC], and [BSD licenses][BSD].
For an introduction to why Libite happened, and how you can use it, see
[this blog post][6].
Helper Macros
-------------
- `atonum(str)`
Convert string to natural number, works for 32-bit non-negative
integers. Returns -1 on error. (Uses `strtonum()` internally.)
- `blkdev(dev)`
Create block device
- `chardev(dev)`
Create character device
- `erase(path)`
Erase file/directory with `remove()`. Errors on stderr
- `makedir(path)`
Create directory, like `mkdir()`. Errors on stderr
- `makefifo(path)`
Create a FIFO, like `mkfifo()`. Errors on stderr
- `touch(path)`
Create a file, or update mtime. Errors on stderr
- `S_ISEXEC(mode_t m)`
Mysteriously missing from GLIBC
- `ISCLR(word,bit)`
Is bit in (integer) word cleared?
- `ISSET(word,bit)`
Is bit in (integer) word set?
- `ISOTHER(word,bit)`
Is any other bits, except bit, in (integer) word set?
- `SETBIT(word,bit)`
Set bit in (integer) word.
- `CLRBIT(word,bit)`
Clear bit in (integer) word.
- `NELEMS(array)`
Returns the number of elements in an array. From the great book, The
Practice of Programming, by Kernighan and Pike.
- `UNUSED(var)`
Shorter and more readable version of `var __attribute__ ((unused))`
Generic Functions
-----------------
- `chomp(str)`
Perl like chomp function, chop off last char if newline.
- `copyfile(src, dst, len, symlink)`
Like the shell `cp(1)` and `dd(1),` can also create symlinks.
- `dir(dir, ext, filter, list, strip)`
Wrapper for `scandir()` with optional filter. Returns a list of
names: files and directories that must be freed after use. See
the unit test at the bottom for an example.
- `fcopyfile(src, dst)`
Like `copyfile()` but uses already open `FILE *` pointers. Copies
from current file positions to current file positions until EOF.
- `fexist(file)`
Check for the existance of a file, returns True(1) or False(0).
- `fisdir(path)`
Check for the existance 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)`
Copy data between file streams, very similar to `fcopyfile()`, but
`dst` is allowed to be `NULL` to be able to read and discard `len`
bytes from `src`.
- `ifconfig(ifname, addr, mask, up)`
Basic ifconfig like operations on an interface. Only supports IPv4
adresses. Note that mask is not CIDR notation.
- `makepath(dir)`
Create all components of the specified directory.
- `mkpath(dir, mode)`
Like `makepath()`, but also takes a `mode_t` permission mode argument.
- `movefile(src, dst)`
Like `copyfile()`, but renames `src` to `dst`, or recreates symlink
with the `dst` name. On successful operation the source is removed
and the function returns POSIX OK (0).
- `pidfile(basename)`
Write a daemon pid file. Creates a pidfile in `_PATH_VARRUN` using
either `basename` or, if `basename` is `NULL`, `__progname`. The
file name has the form `/var/run/basename.pid`.
Use this function to create a pid file for your daemon when it is
ready to receive signals. A client application may poll for the
existence of this file, so make sure to have your signal handlers
properly setup before calling this function.
The pidfile is removed when the program exits, using an `atexit()`
handler. However, depending on how the program terminates the file
may still exist even though the program is no longer running. This
is only a problem for clients.
See below for link to OpenBSD man page.
- `pidfile_read(pidfile)`
Read PID from pid file created by `pidfile()`.
- `pidfile_signal(pidfile, signal)`
Send signal to PID found in pid file created by `pidfile()`.
- `progress(percent, max_width)`
Simple ASCII progress bar with a spinner. Start it with `percent=0`
and set the `max_width=chars` to indicate width of the progress bar.
Called multiple times with the same percentage value cause spinner to
spin.
- `rsync(src, dst, delete, *filter())`
Very simple `rsync()` to copy files files and directories
recursively.
- `tempfile()`
Secure replacement for `tmpfile()`. Creates an invisible temporary
file in `/tmp` that is removed when the returned `FILE` pointer is
closed.
**Note:** Requires Linux v3.11, or later, will fall back to the old
and unsafe `tmpfile()` on older systems.
- `tree(path, show_perms)`
Very simple `/bin/tree` replacement. Draw ASCII tree of `path`, with
optional listing of file and directory permissions if `show_perms` is
set. The `path` argument should be a directory.
OpenBSD Functions
-----------------
The following are the popular OpenBSD string functions.
- `pidfile(basename)`
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/pidfile.3
- `strlcpy(dst, src, len)`
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/strlcpy.3
- `strlcat(dst, src, len)`
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/strlcat.3
- `strtonum()`
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/strtonum.3
- `sys/queue.h` API
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/LIST_EMPTY.3
TODO
----
- Improve documentation, possibly use kdoc or gdoc2 to generate docs from API.
- Continuously, update OpenBSD functions/macros.
[1]: https://github.com/troglobit/finit
[2]: http://www.openbsd.org/
[3]: http://www.openbsd.org/cgi-bin/man.cgi?query=strlcpy
[4]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/LIST_EMPTY.3
[5]: https://developer.gnome.org/glib/
[6]: http://troglobit.com/blog/2015/07/02/howto-using-lite-with-a-git-based-application/
[MIT]: https://en.wikipedia.org/wiki/MIT_License
[ISC]: https://en.wikipedia.org/wiki/ISC_license
[BSD]: https://en.wikipedia.org/wiki/BSD_licenses
[Travis]: https://travis-ci.org/troglobit/libite
[Travis Status]: https://travis-ci.org/troglobit/libite.png?branch=master
<!--
-- Local Variables:
-- mode: markdown
-- End:
-->
> **Tip:** have a look at my blog post about other useful UNIX API's!
> https://troglobit.com/post/2020-02-22-useful-unix-apis/
Using -lite
-----------
Libite is by default installed as a library and a set of include files.
To prevent clashing with include files of the same name `-lite` employs
an include file namespace `libite/`, which is strongly recommended to
use in your applications:
```C
#include <libite/lite.h>
#include <libite/conio.h>
#include <libite/queue.h>
#include <libite/tree.h>
```
> **Note:** prior to v2.5.0, the `lite/` namespace was used for headers,
> which is still available in the default install. This clashed with
> the headers of the LiTE library from the DirectFB project.
The output from the `pkg-config` tool holds no surprises:
```bash
$ pkg-config --libs --static --cflags libite
-I/usr/local/include -D_LIBITE_LITE -L/usr/local/lib -lite
```
> **Note:** `_LIBITE_LITE` is defined since v2.5.0, useful for software
> that want to be able to build against headers from an older libite:
>
> ```C
> #ifdef _LIBITE_LITE
> # include <libite/lite.h>
> #else
> # include <lite/lite.h>
> #endif
> ```
The prefix path `/usr/local/` shown here is only the default. Use the
`configure` script to select a different prefix when installing libite.
For GNU autotools based projects, use the following in `configure.ac`:
```m4
# Check for required libraries
PKG_CHECK_MODULES([lite], [libite >= 1.5.0])
```
and in your `Makefile.am`:
```Makefile
proggy_CFLAGS = $(lite_CFLAGS)
proggy_LDADD = $(lite_LIBS)
```
> API Documentaion: https://codedocs.xyz/troglobit/libite/
Build & Install
---------------
This library was initially built for and developed on GNU/Linux systems
as a light weight utility library, these days NetBSD should also work.
```bash
$ ./configure
$ make -j5
$ sudo make install-strip
$ sudo ldconfig
```
Use <kbd>./configure --without-symlink</kbd> to prevent the install step
from creating the `lite -> libite/` compatibility symlink for the header
files, required for systems with DirectFB LiTE. The default, however,
is to install the symlink to ensure compatibility with existing software
that depends on the `-lite` library headers in their previous namespace.
**Note:** When checking out code from GIT, use <kbd>./autogen.sh</kbd>
to generate a `configure` script. It is a generated file and otherwise
only included in released tarballs.
Origin & References
-------------------
Much of the code in libite (-lite) is written by [Claudio Matsuoka][]
for the original [Finit][original finit] and released under the MIT/X11
license. Joachim Wiberg later improved on the [Finit][1] code base and
included pieces of software released under the ISC and BSD licenses.
See each respective file for license details.
[1]: https://github.com/troglobit/finit
[2]: http://www.openbsd.org/
[3]: http://www.openbsd.org/cgi-bin/man.cgi?query=strlcpy
[4]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/LIST_EMPTY.3
[5]: https://developer.gnome.org/glib/
[7]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/SPLAY_FOREACH.3
[MIT]: https://en.wikipedia.org/wiki/MIT_License
[ISC]: https://en.wikipedia.org/wiki/ISC_license
[BSD]: https://en.wikipedia.org/wiki/BSD_licenses
[GitHub]: https://github.com/troglobit/libite/actions/workflows/build.yml/
[GitHub Status]: https://github.com/troglobit/libite/actions/workflows/build.yml/badge.svg
[Coverity Scan]: https://scan.coverity.com/projects/20602
[Coverity Status]: https://img.shields.io/coverity/scan/20602.svg
[codedocs]: https://codedocs.xyz/troglobit/libite.log
[codedocs status]: https://codedocs.xyz/troglobit/libite.svg
[Claudio Matsuoka]: https://github.com/cmatsuoka
[original finit]: http://helllabs.org/finit/
+15
View File
@@ -0,0 +1,15 @@
* TODO Write tests for new APIs
* More formatted variants?
- symlinkf()
- accessf()
- statf() / lstatf()
* Relocate from Finit
- fnread()
- fnwrite()
- fngetint()
- paste()
- unquote()
Executable
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
autoreconf -W portability -visfm
-4
View File
@@ -1,4 +0,0 @@
OBJS =
TARGET = chomp.test clean
include rules.mk
+39
View File
@@ -0,0 +1,39 @@
AC_INIT(libite, 2.6.2, https://github.com/troglobit/libite/issues)
AC_CONFIG_AUX_DIR(aux)
AM_INIT_AUTOMAKE([1.11 foreign dist-xz])
AM_SILENT_RULES([yes])
AC_CONFIG_SRCDIR(src/lite.h)
AC_CONFIG_HEADERS(config.h)
AC_CONFIG_FILES([Makefile doc/Makefile doc/Doxyfile src/Makefile src/libite.pc test/Makefile])
AC_CONFIG_MACRO_DIR([m4])
AC_PROG_CC
AC_PROG_INSTALL
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
LT_INIT
# Check for Doxygen and enable its features.
# For details, see m4/ax_prog_doxygen.m4 and
# http://www.bioinf.uni-freiburg.de/~mmann/HowTo/automake.html#doxygenSupport
DX_DOXYGEN_FEATURE(ON)
DX_DOT_FEATURE(OFF)
DX_CHI_FEATURE(OFF)
DX_RTF_FEATURE(OFF)
DX_XML_FEATURE(OFF)
DX_PDF_FEATURE(OFF)
DX_PS_FEATURE(OFF)
DX_CHM_FEATURE(OFF)
DX_HTML_FEATURE(ON)
DX_MAN_FEATURE(OFF)
DX_INIT_DOXYGEN(${PACKAGE_NAME}, [${top_builddir}/doc/Doxyfile], [${top_builddir}/doc])
AC_ARG_WITH([symlink],
AS_HELP_STRING([--without-symlink], [Disable compat /usr/include/lite -> libite symlink]),,
[with_symlink=yes])
AM_CONDITIONAL([ENABLE_DOXYGEN], [test "x${DX_FLAG_doc}" = x1])
AM_CONDITIONAL([ENABLE_HTML], [test "x${DX_FLAG_html}" = x1])
AM_CONDITIONAL([COMPAT_SYMLINK], [test "x$with_symlink" != "xno"])
AC_OUTPUT
-82
View File
@@ -1,82 +0,0 @@
/* A conio.h like implementation for VTANSI displays.
*
* Copyright (c) 2009-2013 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.
*/
#ifndef CONIO_H_
#define CONIO_H_
#include <stdio.h>
/* Attributes */
#define RESETATTR 0
#define BRIGHT 1
#define DIM 2
#define UNDERSCORE 4
#define BLINK 5 /* May not work on all displays. */
#define REVERSE 7
#define HIDDEN 8
/* Colors for text and background */
#define BLACK 0x0
#define RED 0x1
#define GREEN 0x2
#define BROWN 0x3
#define BLUE 0x4
#define MAGENTA 0x5
#define CYAN 0x6
#define LIGHTGREY 0x7
#define DARKGREY 0x10
#define LIGHTRED 0x11
#define LIGHTGREEN 0x12
#define YELLOW 0x13
#define LIGHTBLUE 0x14
#define LIGHTMAGENTA 0x15
#define LIGHTCYAN 0x16
#define WHITE 0x17
/* Esc[2JEsc[1;1H - Clear screen and move cursor to 1,1 (upper left) pos. */
#define clrscr() fputs ("\e[2J\e[1;1H", stdout)
/* Esc[K - Erases from the current cursor position to the end of the current line. */
#define clreol() fputs ("\e[K", stdout)
/* Esc[2K - Erases the entire current line. */
#define delline() fputs ("\e[2K", stdout)
/* Esc[Line;ColumnH - Moves the cursor to the specified position (coordinates) */
#define gotoxy(x,y) printf("\e[%d;%dH", y, x)
/* Esc[?25l (lower case L) - Hide Cursor */
#define hidecursor() fputs ("\e[?25l", stdout)
/* Esc[?25h (lower case H) - Show Cursor */
#define showcursor() fputs ("\e[?25h", stdout)
/* Esc[Value;...;Valuem - Set Graphics Mode */
#define __set_gm(attr,color,val) \
if (!color) \
printf("\e[%dm", attr); \
else \
printf("\e[%d;%dm", color & 0x10 ? 1 : 0, (color & 0xF) + val)
#define textattr(attr) __set_gm(attr, 0, 0)
#define textcolor(color) __set_gm(RESETATTR, color, 30)
#define textbackground(color) __set_gm(RESETATTR, color, 40)
#endif /* CONIO_H_ */
/**
* Local Variables:
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
-4
View File
@@ -1,4 +0,0 @@
OBJS = fisdir.o fexist.o fmode.o
TARGET = $(OBJS) copyfile.test clean
include rules.mk
+12
View File
@@ -0,0 +1,12 @@
*.log
*.substvars
.debhelper/*
tmp/*
libite/*
libite5/*
libite-dev/*
autoreconf*
debhelper*
files
!*.dirs
!*.install
+178
View File
@@ -0,0 +1,178 @@
libite (2.6.0) stable; urgency=medium
* New APIs from Infix Project:
- fexistf()
- vfopenf()
- popenf()
- vreadsnf(), readsnf(), writesf()
- vreadllf(), readllf(), readdf()
- writellf(), writedf()
* Spellchecking of API docs
-- Joachim Wiberg <troglobit@gmail.com> Sun, 17 Sep 2023 12:16:47 +0200
libite (2.5.3) stable; urgency=medium
* rsync() does not copy single files correctly
* copyfile() does not handle empty source files correctly (error)
* copyfile() does not properly create destination dir
* Add printf format attribute hint to all vararg functions
* Fix fisdir() segfault on GNU/Hurd
* Fix touch() on Debian/kFreeBSD, use creat() instad of mknod()
-- Joachim Wiberg <troglobit@gmail.com> Sat, 08 Apr 2023 07:04:00 +0200
libite (2.5.1) stable; urgency=medium
* Use dh_link(1) to install `/usr/include/lite -> libite/`.
-- Joachim Wiberg <troglobit@gmail.com> Thu, 02 Dec 2021 00:08:41 +0100
libite (2.5.0) stable; urgency=medium
* Header files have moved from `lite/*.h` to `libite/*.h` to prevent
clashing with DirectFB LiTE library. For a transitional period,
however, a compatibility symlink is installed; `lite -> libite/`.
-- Joachim Wiberg <troglobit@gmail.com> Tue, 30 Nov 2021 06:57:17 +0100
libite (2.4.1) stable; urgency=medium
* Add doxygen documentation, https://codedocs.xyz/troglobit/libite/
* Fix issue with tempfile() returning EOPNOTSUP on certain file systems,
added fallback that uses mkstemp() with O_CLOEXEC flag set
-- Joachim Wiberg <troglobit@gmail.com> Sat, 09 Oct 2021 08:56:43 +0200
libite (2.4.0) stable; urgency=medium
* New functions:
- touchf(), formatted string support for touch()
- erasef(), formatted string support for erase()
- strtrim(), trims leading and trailing white-space from a string
* Fix systemf() improper handling of system() return value. Now checks
if exited OK, then returning the exit status of the command, or if not
exited OK, then checks if the command was signaled, and returns -1 with
errno set. This also allows for returning 127, like system(), if the
shell, or the program itself, did not exist.
-- Joachim Wiberg <troglobit@gmail.com> Sat, 27 Mar 2021 09:12:32 +0100
libite (2.3.1) stable; urgency=medium
* Minor packaging fixes.
* Copyright updates, including LICENSE file, year + author last name
-- Joachim Wiberg <troglobit@gmail.com> Fri, 12 Feb 2021 15:10:42 +0100
libite (2.3.0) stable; urgency=medium
* New functions:
- Add support for fremove(), formatted remove() replacement
- Add support for truncatef(), formatted truncate() replacement
* Fixes
- Handle ETIMEDOUT error for connect() call in telnet_open()
-- Joachim Wiberg <troglobit@gmail.com> Fri, 12 Feb 2021 08:03:47 +0100
libite (2.2.0) stable; urgency=medium
* New functions:
- systemf(), formatted string system() replacement
- fmkpath(), formatted string mkpath() replacement
- fopenf(), formatted string fopen() replacement
* Fixes
- possible memory leak in rsync()
- Check return value of fstat() to prevent bogus destination file
times when using copyfile()
-- Joachim Nilsson <troglobit@gmail.com> Mon, 16 Mar 2020 15:42:02 +0100
libite (2.1.2) stable; urgency=high
* Fix upgrade of base package, new library name to match SONAME
breaks upgrade from libite_2.0.x.deb to libite5_2.1.x.deb
-- Joachim Nilsson <troglobit@gmail.com> Sat, 22 Feb 2020 15:04:27 +0100
libite (2.1.1) stable; urgency=medium
* Fix to chomp(), ensure stopping before beginning of string
* Added example of printhdr()
* Update copyright years
* Add missing libite5.symbols file, found by lintian
* Fix package short description, found by linitian
-- Joachim Nilsson <troglobit@gmail.com> Sat, 22 Feb 2020 13:52:24 +0100
libite (2.1.0) unstable; urgency=medium
* New functions; strmatch(), strnmatch(), yorn(), telnet expect APIs
* Fixes to pidfile_signal(), strtonum() and C++ linking
-- Joachim Nilsson <troglobit@gmail.com> Mon, 26 Aug 2019 20:21:46 +0200
libite (2.0.2) unstable; urgency=medium
* Fix issues with using `strlite.h` standalone
* Fix build issue with `strtonum.c` older GLIBC
-- Joachim Nilsson <troglobit@gmail.com> Thu, 10 May 2018 19:12:57 +0200
libite (2.0.1-1) unstable; urgency=medium
* New upstream release, v2.0.1, fixes to:
- 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
* Initial release.
-- Joachim Nilsson <troglobit@gmail.com> Tue, 29 Nov 2016 08:23:35 +0100
+1
View File
@@ -0,0 +1 @@
config.log
+1
View File
@@ -0,0 +1 @@
10
+56
View File
@@ -0,0 +1,56 @@
Source: libite
Section: libs
Priority: optional
Maintainer: Joachim Wiberg <troglobit@gmail.com>
Build-Depends: debhelper (>= 10)
Build-Depends-Indep: doxygen
Standards-Version: 4.3.0
Homepage: https://github.com/troglobit/libite/
Vcs-Browser: https://github.com/troglobit/libite/
Vcs-Git: https://github.com/troglobit/libite.git
Package: libite-dev
Priority: optional
Section: libdevel
Architecture: any
Depends: ${misc:Depends}, libite5 (= ${binary:Version})
Description: static library, header files, and docs for libite
Static library, header files, and documentation for libite.
.
Libite is a lightweight library of frog DNA. It can be used to fill
the gaps in any dinosaur project. It holds useful functions and macros
developed by both Finit and the OpenBSD project. Most notably the
string functions: strlcpy(3), strlcat(3) and the highly useful *BSD
sys/queue.h and sys/tree.h API's.
.
Libite is the frog DNA missing in GNU libc. However, -lite does not
aim to become another GLIB! One noticeable gap in GLIBC is the missing
_SAFE macros in the BSD sys/queue.h API — highly recommended when
traversing lists to delete/free nodes.
.
The code is open sourced under a mix of the MIT/X11 license, the ISC
license used by OpenBSD, and BSD licenses, all of them are extremely
liberal and can be used freely in proprietary software if needed.
Package: libite5
Replaces: libite
Conflicts: libite
Provides: libite
Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends}
Description: That missing frog DNA you've been looking for
Libite, or -lite, is a lightweight library of frog DNA. It can be used
to fill the gaps in any dinosaur project. It holds useful functions
and macros developed by both Finit and the OpenBSD project. Most
notably the string functions: strlcpy(3), strlcat(3) and the highly
useful *BSD sys/queue.h and sys/tree.h API's.
.
Libite is the frog DNA missing in GNU libc. However, -lite does not
aim to become another GLIB! One noticeable gap in GLIBC is the missing
_SAFE macros in the BSD sys/queue.h API — highly recommended when
traversing lists to delete/free nodes.
.
The code is open source software under a mix of the MIT/X11 license,
the ISC license used by OpenBSD, and BSD licenses, all of them are
extremely liberal and can be used freely in proprietary software if
needed.
+128
View File
@@ -0,0 +1,128 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Source: https.//github.com/troglobit/libite/
Files: *
Copyright:
2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
2008-2021 Joachim Wiberg <troglobit@gmail.com>
License: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
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.
Files: chomp.c
Copyright: 2014-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: conio.?
Copyright: 2009-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: dir.c
Copyright: 2008-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: fopenf.c fremove.c systemf.c truncatef.c
Copyright: 2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: fparseln.c
Copyright: 1997 Christos Zoulas
License: BSD-2-clause
Files: fsendfile.c
Copyright: 2013 Tobias Waldekranz <tobias@waldekranz.com>
License: MIT
Files: lfile.c
Copyright: 2015-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: makepath.c
Copyright: 2016-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: pidfile.c
Copyright: 1999 The NetBSD Foundation, Inc.
License: BSD-2-clause
Files: pidfilefn.c
Copyright: 2009-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: progress.c
Copyright: 2012-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: queue.h
Copyright: 1991, 1993 The Regents of the University of California.
License: BSD-3-clause
Files: reallocarray.c
Copyright: 2008 Otto Moerbeek <otto@drijf.net>
License: ISC
Files: rsync.c
Copyright: 2011-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: strdupa.h strndupa.h
Copyright: 2009 William Ahern
License: MIT
Files: strlcat.c strlcpy.c
Copyright: 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
License: MIT
Files: strlite.h
Copyright: 2008-2021 Joachim Wiberg <troglobit@gmail.com>
License: MIT
Files: strmatch.c
Copyright: 2009-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: strnlen.c
Copyright: 2016-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: strtonum.c
Copyright: 2004 Ted Unangst and Todd Miller
License: ISC
Files: telnet.c
Copyright: 2010-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: tempfile.c
Copyright: 2015-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: tree.h
Copyright: 2002 Niels Provos <provos@citi.umich.edu>
License: BSD-2-clause
Files: which.c
Copyright: 2017-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: yorn.c
Copyright: 2009-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: test/*.c
License: public-domain
Vendored
+1
View File
@@ -0,0 +1 @@
README.md
+2
View File
@@ -0,0 +1,2 @@
usr/lib
usr/include
+4
View File
@@ -0,0 +1,4 @@
usr/include/libite/*.h
usr/lib/*/lib*.a
usr/lib/*/lib*.so
usr/lib/*/pkgconfig/lib*.pc
+1
View File
@@ -0,0 +1 @@
/usr/include/libite /usr/include/lite
+1
View File
@@ -0,0 +1 @@
usr/lib
+1
View File
@@ -0,0 +1 @@
usr/lib/*/lib*.so.*
+52
View File
@@ -0,0 +1,52 @@
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
erasef@Base 2.4.0
fcopyfile@Base 2.0.0
fexist@Base 2.0.0
fgetint@Base 2.0.0
fisdir@Base 2.0.0
fmkpath@Base 2.2.0
fopenf@Base 2.2.0
fparseln@Base 2.0.0
fremove@Base 2.3.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
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
strtrim@Base 2.4.0
systemf@Base 2.2.0
telnet_close@Base 2.1.0
telnet_expect@Base 2.1.0
telnet_open@Base 2.1.0
telnet_session@Base 2.1.0
tempfile@Base 2.0.0
touchf@Base 2.4.0
truncatef@Base 2.3.0
which@Base 2.0.0
whichp@Base 2.0.0
yorn@Base 2.1.0
Vendored Executable
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
%:
dh $@ --with autoreconf
override_dh_auto_configure:
dh_auto_configure -- --without-symlink
override_dh_installchangelogs:
dh_installchangelogs ChangeLog.md
override_dh_auto_install:
dh_auto_install
find debian -name LICENSE -delete
+1
View File
@@ -0,0 +1 @@
3.0 (native)
+1
View File
@@ -0,0 +1 @@
compression=xz
-229
View File
@@ -1,229 +0,0 @@
/* Functions for operating on files in directories.
*
* Copyright (c) 2008-2014 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 <assert.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static const char *matcher_type = NULL;
static int (*matcher_filter) (const char *file) = NULL;
static int matcher(const struct dirent *entry)
{
char *pos = strrchr(entry->d_name, '.');
if (matcher_filter && !matcher_filter(entry->d_name))
/* User matcher overrides the rest. */
return 0;
/* Skip current 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;
/* filetype == "" */
if (matcher_type[0] == 0)
return 1;
/* Entry has no "." */
if (!pos)
return 0;
return !strcmp(pos, matcher_type);
}
/**
* dir - List all files of a certain type in the given directory.
* @dir: Base directory for dir operation.
* @type: File type suffix, e.g. ".cfg".
* @filter: Optional file name filter.
* @list: Pointer to an array of file names.
* @strip: Flag, if set dir() strips the file type.
*
* This function returns a @list of files, matching the @type suffix,
* in the given directory @dir.
*
* The @list argument is a pointer to where to store the dynamically
* allocated list of file names. This list should be free'd by first
* calling free() on each file name and then on the list itself.
*
* If @filter is not %NULL it will be called for each file found. If
* @filter returns non-zero the @file argument will be included in the
* resulting @list. If @filter returns zero for given @file it will
* be discarded.
*
* If the @strip flag is set the resulting @list of files has their
* file type stripped, including the dot. So a match "config0.cfg"
* would be returned as "config0".
*
* Returns:
* Number of files in @list, zero if no matching files of @type.
*/
int dir(const char *dir, const char *type, int (*filter) (const char *file), char ***list, int strip)
{
int i, n, num = 0;
char **files;
struct dirent **namelist;
assert(list);
if (!dir)
/* Assuming current directory */
dir = ".";
if (!type)
/* Assuming all files. */
type = "";
matcher_type = type;
matcher_filter = filter;
n = scandir(dir, &namelist, matcher, alphasort);
if (n < 0) {
perror("scandir");
} else if (n > 0) {
files = (char **)malloc(n * sizeof(char *));
for (i = 0; i < n; i++) {
if (files) {
char *name = namelist[i]->d_name;
char *type = strrchr(name, '.');
if (type && strip)
*type = 0;
files[i] = strdup(name);
num++;
}
free(namelist[i]);
}
if (num)
*list = files;
}
if (namelist)
free(namelist);
return num;
}
#ifdef UNITTEST
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "lite.h"
#define DIR_TYPE_IMAGE ".img"
#define DIR_TYPE_SYSLOG ""
#define DIR_TYPE_CONFIG ".cfg"
#define STARTUP_CONFIG "startup-config.cfg"
int simulate_files(int creat)
{
int i;
char *files[] =
{ "config0.cfg", "config1.cfg", "config2.cfg", "config3.cfg",
"rr109.img", "rx100.img", "rx107.img", "rm957.img", "messages"
};
for (i = 0; i < NELEMS(files); i++) {
if (creat)
touch(files[i]);
else
erase(files[i]);
}
if (creat)
symlink("config2.cfg", STARTUP_CONFIG);
else
erase(STARTUP_CONFIG);
return 0;
}
static int cfg_dir_filter(const char *file)
{
/* Skip the STARTUP_CONFIG file, it is a symbolic link to the
* current startup configuration. */
return ! !strcmp(file, STARTUP_CONFIG);
}
int main(int argc, char *argv[])
{
int i, num;
char *type = DIR_TYPE_CONFIG;
char **files;
int once = 1;
int is_startup_config(const char *entry) {
static char file[80];
if (once) {
int len = readlink(STARTUP_CONFIG, file, sizeof(file));
if (len == -1)
return 0;
file[len] = 0;
once = 0; /* Only once per call to dir() */
}
//printf ("Comparing link %s with entry %s\n", file, entry);
return !strcmp(file, entry);
}
simulate_files(1);
if (argc >= 2) {
if (!strcasecmp("CONFIG", argv[1])) {
type = DIR_TYPE_CONFIG;
system("ls -l *" DIR_TYPE_CONFIG);
}
if (!strcasecmp("IMAGE", argv[1])) {
type = DIR_TYPE_IMAGE;
system("ls -l *" DIR_TYPE_IMAGE);
}
if (!strcasecmp("SYSLOG", argv[1])) {
type = DIR_TYPE_SYSLOG;
system("ls -l *");
}
}
num = dir(NULL, type, cfg_dir_filter, &files, 0);
if (num) {
for (i = 0; i < num; i++) {
printf("%s", files[i]);
if (is_startup_config(files[i]))
printf(" --> startup-config");
printf("\n");
free(files[i]);
}
free(files);
}
simulate_files(0);
return 0;
}
#endif /* UNITTEST */
/**
* Local Variables:
* compile-command: "make V=1 -f dir.mk"
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
-4
View File
@@ -1,4 +0,0 @@
OBJS =
TARGET = dir.test clean
include rules.mk
+3
View File
@@ -0,0 +1,3 @@
html/*
libite.tag
Doxyfile
+459
View File
@@ -0,0 +1,459 @@
API Documentation
=================
Important Note
--------------
When using functions like `mkpath()`, `makepath()`, and `makefifo()`,
make sure your `umask()` is correct so you do not accidentally create
files and directories accessible to other users than intended.
Helper Macros
-------------
- `atonum(str)`
Convert string to natural number, works for 32-bit non-negative
integers. Returns -1 on error. (Uses `strtonum()` internally.)
- `blkdev(dev)`
Create block device
- `chardev(dev)`
Create character device
- `erase(path)`
Erase file/directory with `remove()`. Errors on `stderr`
- `erasef(fmt, ...)`
Like `erase()` but takes a formatted printf-like string as argument.
- `makedir(path)`
Create directory, like `mkdir()`. Errors on `stderr`
- `makefifo(path)`
Create a FIFO, like `mkfifo()`. Errors on `stderr`
- `min(a,b)`/`max(a,b)`
These macros take care to avoid double evaluation.
- `touch(path)`
Create a file, or update mtime. Errors on `stderr`
- `touchf(fmt, ...)`
Like `touch()` but takes a formatted printf-like string as argument.
- `S_ISEXEC(mode_t m)`
Mysteriously missing from GLIBC
- `ISCLR(word,bit)`
Is bit in (integer) word cleared?
- `ISSET(word,bit)`
Is bit in (integer) word set?
- `ISOTHER(word,bit)`
Are any other bits, except bit, in (integer) word set?
- `SETBIT(word,bit)`
Set bit in (integer) word.
- `CLRBIT(word,bit)`
Clear bit in (integer) word.
- `NELEMS(array)`
Returns the number of elements in an array. From the great book, The
Practice of Programming, by Kernighan and Pike.
Generic Functions
-----------------
- `chomp(str)`
Perl like chomp function, chop off last char if newline.
- `copyfile(src, dst, len, opt)`
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)`
Wrapper for `scandir()` with optional filter. Returns a list of
names: files and directories that must be freed after use. See
the unit test for an example, or take a look at `glob(3)`, it's
probably what you want anyway.
- `fcopyfile(src, dst)`
Like `copyfile()` but uses already open `FILE *` pointers. Copies
from current file positions to current file positions until EOF.
- `fexist(file)`
Check for the existence of a file, returns True(1) or False(0).
- `fisdir(path)`
Check for the existence of a directory, returns True(1) or False(0).
- `fopenf(mode, fmt, ...)` and `vfopenf(mode, fmt, ap)`
Like `fopen()`, but takes a formatted string as argument. This
greatly simplifies operations that usually consist of composing a
filename from parts into a dynamic buffer before actually opening
the file.
> **Notice:** the swapped order of `pathname` and `mode`!
- `fremove(fmt, ...)`
Like `remove()`, but takes a formatted string as argument. This
greatly simplifies operations that usually consist of composing a
filename from parts into a dynamic buffer before actually removing
the file.
- `fsendfile(src, dst, len)`
Copy data between file streams, very similar to `fcopyfile()`, but
`dst` is allowed to be `NULL` to be able to read and discard `len`
bytes from `src`.
- `ifconfig(ifname, addr, mask, up)`
Basic ifconfig like operations on an interface. Only supports IPv4
addresses. Note that mask is not CIDR notation.
- `lfopen(file, sep)`, `lfclose(lf)`
LITE file API for parsing UNIX style configuration files like
`/etc/protocols` and `/etc/services`.
- `lftok(lf)`
Read tokens, delimited by `sep`, from file opened with `lfopen()`.
- `lfgetkey(lf, key)`
Find `key` in file opened with `lfopen()`, return value/argument.
- `lfgetint(lf, key)`
Wrapper for `lfgetkey()`, returns positive integer value to `key`,
or `-1` if `key` is not found.
- `fgetint(file, sep, key)`
Wrapper for `lfopen()`, `lfgetint()`, and `lfclose()`. Useful for
when only reading a single `key` from a file.
- `makepath(dir)`
Create all components of the specified directory.
- `mkpath(dir, mode)`
Like `makepath()`, but also takes a `mode_t` permission mode argument.
- `fmkpath(mode, fmt, ...)`
Like `mkpath()`, but takes a formatted string as argument.
> **Notice:** the swapped order of `pathname` and `mode`!
- `movefile(src, dst)`
Like `copyfile()`, but renames `src` to `dst`, or recreates symlink
with the `dst` name. On successful operation the source is removed
and the function returns POSIX OK (0).
- `pidfile(name)`
Create a daemon PID file using either the `name` as a full path, if
`name` starts with `/`, or in `_PATH_VARRUN` using `name` as the
basename of the application. If `name` is `NULL`, then `__progname`
is used as the basename. The resulting file name is available to the
user as a read-only pointer:
extern char *__pidfile_name;
Use this function to create a PID file for your daemon when it is
ready to receive signals. A client application may poll for the
existence of this file, so make sure to have your signal handlers
properly setup before calling this function.
The PID file is removed when the program exits, using an `atexit()`
handler. However, depending on how the program terminates the file
may still exist even though the program is no longer running.
Calling this function multiple times updates the mtime of the file.
Only one `atexit()` handler is created, regardless of the amount of
times the function is called. If the file is removed, subsequent
calls to this function will recreate the file.
See below for a link to OpenBSD man page.
- `pidfile_read(pidfile)`
Read PID from pid file created by `pidfile()`.
- `pidfile_signal(pidfile, signal)`
Send signal to PID found in pid file created by `pidfile()`.
- `progress(percent, max_width)`
Simple ASCII progress bar with a spinner. Start it with `percent=0`
and set the `max_width=chars` to indicate width of the progress bar.
Called multiple times with the same percentage value cause spinner to
spin.
- `rsync(src, dst, opt, *filter())`
Very simple `rsync()` to copy files and directories recursively. It
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.
- `runbg(cmd, delay)`
Run a command in the background, after delay microseconds, essentially
a background `execvp()` with a delay. The function employs double-fork
to prevent zombies and closes all open files, including stdio.
```C
char *cmd[] = { "sh", "-c", "echo 'hej' >/tmp/foo", NULL};
runbg(cmd, 200000); /* Create /tmp/foo after 200 millisec */
/* Execution continues here immediately */
```
- `strmatch(str, list)`, `strnmatch(str, list, len)`
Find matching string in an array of strings. Returns index in array on
match, or `-1` on error or not found. `strnmatch()` takes an extra arg
to compare only `len` number of characters from `str`.
- `strtrim(str)`
Trims a string from any leading and trailing white-space, returns the
trimmed result in the same buffer.
- `systemf(fmt, ...)`
Like `system()`, but takes a formatted string as argument. This
greatly simplifies operations that usually consist of composing a
command from parts into a dynamic buffer before calling it.
- `telnet_open(addr, port), telnet_close(ctx), telnet_expect(ctx, script, output)`
Poor mans telnet expect in C. Opens connection to a Telnet service;
FTP, Telnet, similar, and run an expect-like script.
- `telnet_session(addr, port, script output)`
Wrapper for the above three in one API.
- `tempfile()`
Secure replacement for `tmpfile()`. Creates an invisible temporary
file in `/tmp` that is removed when the returned `FILE` pointer is
closed.
**Note:** Requires Linux v3.11, or later, will fall back to the old
and unsafe `tmpfile()` on older systems.
- `truncatef(length, fmt, ...)`
Like `truncate()`, but takes a formatted string as argument. This
simplifies some operations when the filename otherwise have to be
composed from parts into a separate array before calling the real
function.
- `which(cmd)`, `whichp(cmd)`
C implementation of UNIX which(1). Returns a malloc'ed string with the
full path to `cmd` on success, otherwise `NULL`.
`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.
Procfile Functions
------------------
These functions can be used to simplify access to data in `/proc` and
`/sys` on a Linux system.
### String Functions
- `readsnf(line, len, fmt, ...)`
Read first line from a file composed from `fmt`, with optional args.
At most `len` bytes from the file are stored in `line`.
On success this function returns `line` with any trailing newlines
`chomp()`ed off. On error `NULL` is returned.
- `vreadsnf(line, len, fmt, ap)`
Similar to `readsnf()` but takes a `va_list` argument instead.
- `writesf(str, mode, fmt, ...)`
Write the string buffer `str`, with an additional newline, to a file
composed from `fmt`, with optional args. The file is opened with the
given `mode`, e.g. "w+", which allows for both replacing and appending
file content.
The function returns POSIX OK(0) on success or -1 on failure with the
`errno` variable set to a value from either `fopen()` or `fclose()`.
### Integer Functions
Read and write 32-bit and 64-bit signed values from/to files.
- `vreadllf(value, fmt, ap)` and `readllf(value, fmt, ...)`
Only the first line is read. If the line has newline that is stripped
before calling `strtoll()` on the line. The arguments to the latter
function is such that it can convert also from a hexadecimal value.
This function may fail and return -1 on opening the file, reading a
line, or if the `strtoll()` function fails. All of which set the
`errno` variable. Otherwise this function return POSIX OK(0).
- `readdf(value, fmt, ...)`
Read a signed 32-bit value from a file composed from `fmt`, with
optional args. This function use `vreadllf()` with an additional
range checking for `INT_MIN` and `INT_MAX`. Values outside that
cause this function to return -1 with `errno` set to `ERANGE`.
- `writedf(value, mode, fmt, ...)`
Write a signed 32-bit `value` to a file composed from `fmt`, with
optional args. The file is opened with the given `mode`, e.g. "w+",
which allows for both replacing and appending file content.
The function returns POSIX OK(0) on success or -1 on failure with the
`errno` variable set to a value from either `fopen()` or `fclose()`.
- `writellf(value, mode, fmt, ...)`
Write a signed 64-bit `value` to a file composed from `fmt`, with
optional args. The file is opened with the given `mode`, e.g. "w+",
which allows for both replacing and appending file content.
The function returns POSIX OK(0) on success or -1 on failure with the
`errno` variable set to a value from either `fopen()` or `fclose()`.
GNU Functions
-------------
The following are useful GNU functions, that do not exist on *BSD, and
some other platforms.
- `strdupa(str)`
http://man7.org/linux/man-pages/man3/strdupa.3.html
- `strndupa(str)`
http://man7.org/linux/man-pages/man3/strndupa.3.html
- `strnlen(str, lim)`
http://man7.org/linux/man-pages/man3/strnlen.3.html
OpenBSD/NetBSD/FreeBSD Functions
--------------------------------
The following are popular functions and highly useful macros from the
*BSD world of UNIX that are sadly missing on Linux.
- `fparseln(fp, *len, *lineno, delim, flags)`
http://man.openbsd.org/OpenBSD-current/man3/fparseln.3
- `pidfile(basename)`
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/pidfile.3
**Note:** the version of `pidfile()` in -lite has been extended to
handle it being called multiple times, i.e. to not create multiple
`atexit()` handlers, and also to export a few internal paths:
- `__pidfile_path`: prefix path, default `_PATH_VARRUN`. Notice the
trailing slash requirement if you want to override it!
- `__pidfile_name`: full path to PID file , similar to `__progname`.
See previous section for details.
- `reallocarray(ptr, nmemb, size)`
http://man.openbsd.org/OpenBSD-current/man3/reallocarray.3
- `strlcpy(dst, src, len)`
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/strlcpy.3
- `strlcat(dst, src, len)`
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/strlcat.3
- `strtonum()`
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/strtonum.3
- `sys/queue.h` API
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/LIST_EMPTY.3
- `sys/tree.h` API
Niels Provos' famous splay and red-black tree implementation.
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/SPLAY_FOREACH.3
+2579
View File
File diff suppressed because it is too large. Load diff
+104
View File
@@ -0,0 +1,104 @@
Maintenance and Release Checklist
=================================
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
* Reference issues from GitHub pull requests to alert issue subscribers
* Bump library ABI version just before release!
Release Checklist
-----------------
* Update ChangeLog, follow http://keepachangelog.com/ loosely
- Inform users in a plain language of changes and bug fixes
- Do *not* copy-paste GIT commit logs!
- Order entrys according to importance, most relevant first
* Run unit tests: `make check`
* Do we need to bump the ABI version? (Probably, see below)
* Tag
* Push last commit(s) *and* tags to GitHub
* Make release
make distclean
./autogen.sh
./configure
make release
* Create new release in GitHub releases page
* Copy and paste ChangeLog entry, check any stale links!
* Upload release tarball and MD5 files
Library Versioning
------------------
Libite (-lite) relies on GNU Libtool for building the library. For a
user of the library it is important to maintain a clear ABI versioning
scheme. This is not the same as the library version, but rather the
library "compatibility level".
The ABI version is specified in `src/Makefile.am` and looks like this:
libite_la_LDFLAGS = -version-info 0:0:0
\ \ `-- age
\ `--- revision
`---- current
It must be updated according to the [GNU Libtool recommendations][1]:
1. Start with version information of `0:0:0` for each libtool library.
2. Update the version information only immediately before a public
release of your software. More frequent updates are unnecessary, and
only guarantee that the current interface number gets larger faster.
3. If the library *source code has changed at all* since the last update,
then increment revision (`c:r:a` becomes `c:r+1:a`).
4. If any *interfaces have been added, removed, or changed* since the
last update, increment current, and set revision to 0.
5. If any *interfaces have been added* since the last public release,
then increment age.
6. If any *interfaces have been removed or changed* since the last
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 `libite.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
`libite.so.1.0.0`.
### Note
Usually, non-developers have no interest in running development versions
(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
the library version just prior to a release, point 2.
However, if releases are few and far between, distributors may start to
use snapshots. When a distributor uses a snapshot, the distributor has
to handle the library version manually. Things can get ugly when the
distributor has released an intermediate version with a bumped library
version, and when the official release is bumped to that version, the
distributor will then have to bump the library version for the official
release, and it can be confusing if someone reports bugs on versions
that you didn't even know existed.
The problem with bumping the version with every change is that if your
interface is not finished, the version number might run away, and it
looks pretty bad if a library is at version 262. It kind of tells the
user that the library interface is volatile, which is not good for
business.
[1]: https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
+22
View File
@@ -0,0 +1,22 @@
dist_doc_DATA = API.md
EXTRA_DIST = API.md Doxyfile.in
DISTCLEANFILES = libite.tag
if ENABLE_HTML
pkghtmldir = $(docdir)/html
pkghtml_DATA = html/*
#
# Doxygen rules from m4/ax_prog_doxygen.m4
#
@DX_RULES@
$(pkghtml_DATA): doxygen-doc
all-local: doc
clean-local:
-rm -rf html libite.tag
doc: doxygen-doc
endif
+8
View File
@@ -0,0 +1,8 @@
TODO ... in no particular order
===============================
* Improve documentation, possibly use kdoc or gdoc2 to generate docs from API
* Continuously, update OpenBSD functions/macros
* Investigate adding FreeBSD pidfile_open() et al
* Investigate FreeBSD libutil library, could be useful for porting between unices
-4
View File
@@ -1,4 +0,0 @@
OBJS =
TARGET = fexist.test clean
include rules.mk
-80
View File
@@ -1,80 +0,0 @@
/* Check if directory exists
*
* 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 <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
/**
* fexist - Check if a file exists and is a directory.
* @file: File to look for, with full path.
*
* Returns:
* %TRUE(1) if the file exists and is a directory, otherwise %FALSE(0).
*/
int fisdir(char *file)
{
struct stat sb;
if (!stat(file, &sb) && S_ISDIR(sb.st_mode))
return 1;
return 0;
}
#ifdef UNITTEST
#include "lite.h"
int main(void)
{
int i = 0;
struct { char *file; int exist; } arr[] = {
{ "/etc/passwd", 0 },
{ "/etc/", 1 },
{ "/sbin/init", 0 },
{ "/dev/null", 0 },
{ "/dev/", 1 },
{ NULL, 0 },
};
FILE *src, *dst;
for (i = 0; i < NELEMS(arr); i++) {
if (fisdir(arr[i].file) != arr[i].exist)
err(1, "Failed fisdir(%s)", arr[i].file ?: "NULL");
else
printf("fisdir() %-11s %-18s => OK!\n", arr[i].file ?: "NULL",
arr[i].exist ? "is a directory" : "is NOT a directory");
}
return 0;
}
#endif /* UNITTEST */
/**
* Local Variables:
* compile-command: "make V=1 -f fisdir.mk"
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
-4
View File
@@ -1,4 +0,0 @@
OBJS =
TARGET = fisdir.test clean
include rules.mk
-4
View File
@@ -1,4 +0,0 @@
OBJS =
TARGET = fsendfile.test clean
include rules.mk
-189
View File
@@ -1,189 +0,0 @@
/* Collection of utility funcs and C library extensions for finit & its plugins
*
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2015 Joachim Nilsson <troglobit@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* 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.
*/
#ifndef FINIT_LITE_H_
#define FINIT_LITE_H_
#include <err.h>
#include <stdio.h>
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, INT32_MAX, etc. */
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
#include <unistd.h>
char *chomp (char *str);
int fexist (char *file);
int fisdir (char *file);
mode_t fmode (char *file);
FILE *tempfile (void);
ssize_t copyfile (char *src, char *dst, int len, int sym);
int movefile (char *src, char *dst);
int fcopyfile (FILE *src, FILE *dst);
size_t fsendfile (FILE *src, FILE *dst, size_t len);
int ifconfig (char *ifname, char *addr, char *mask, int up);
int mkpath (char *dir, mode_t mode);
int makepath (char *dir);
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 pidfile (const char *basename);
int pidfile_signal(const char *pidfile, int signal);
pid_t pidfile_read (const char *pidfile);
pid_t pidfile_poll (const char *pidfile);
#ifndef strlcpy
size_t strlcpy (char *dst, const char *src, size_t siz);
#endif
#ifndef strlcat
size_t strlcat (char *dst, const char *src, size_t siz);
#endif
#ifndef strtonum
long long strtonum (const char *numstr, long long minval, long long maxval, const char **errstrp);
#endif
int tree(char *path, int show_perms);
#ifndef touch
# define touch(x) do { if (mknod((x), S_IFREG|0644, 0) && errno != EEXIST) warn("Failed creating %s", x); } while (0)
#endif
#ifndef makedir
# define makedir(x, p) do { if (mkdir(x, p) && errno != EEXIST) warn("Failed creating directory %s", x); } while (0)
#endif
#ifndef makefifo
# define makefifo(x, p) do { if (mkfifo(x, p) && errno != EEXIST) warn("Failed creating FIFO %s", x); } while (0)
#endif
#ifndef erase
# define erase(x) do { if (remove(x) && errno != ENOENT) warn("Failed removing %s", x); } while (0)
#endif
#ifndef chardev
# define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min)))
#endif
#ifndef blkdev
# define blkdev(x,m,maj,min) mknod((x), S_IFBLK|(m), makedev((maj),(min)))
#endif
#ifndef S_ISEXEC
# define S_ISEXEC(m) (((m) & S_IXUSR) == S_IXUSR)
#endif
/* Unline isset(), setbit() et al, these work with integers/shorts/longwords/etc. */
#ifndef ISCLR
#define ISCLR(word,bit) ((word & (1 << (bit)) ? 0 : 1))
#endif
#ifndef ISSET
#define ISSET(word,bit) ((word & (1 << (bit)) ? 1 : 0))
#endif
#ifndef ISOTHER
#define ISOTHER(word,bit) ((word & ~(1 << (bit)) ? 1 : 0)) /* Is any other bit set? */
#endif
#ifndef SETBIT
#define SETBIT(word,bit) (word |= (1 << (bit)))
#endif
#ifndef CLRBIT
#define CLRBIT(word,bit) (word &= ~(1 << (bit)))
#endif
/* From The Practice of Programming, by Kernighan and Pike */
#ifndef NELEMS
#define NELEMS(array) (sizeof(array) / sizeof(array[0]))
#endif
/* Mark a function variable as unused, useful for generic callbacks */
#ifndef UNUSED
#define UNUSED(x) UNUSED_ ## x __attribute__ ((unused))
#endif
static inline int fisslashdir(char *dir)
{
if (!dir) return 0;
if (strlen (dir) > 0) return dir[strlen (dir) - 1] == '/';
return 0;
}
/* Convert string to natural number (0-2147483647), returns -1 on error. */
static inline int atonum(const char *str)
{
int val = -1;
const char *errstr;
if (str) {
val = strtonum(str, 0, INT32_MAX, &errstr);
if (errstr)
return -1;
}
return val;
}
/* Validate string, non NULL and not zero length */
static inline int string_valid(const char *s)
{
return s && strlen(s);
}
/* Relaxed comparison, e.g., sys_string_match("small", "smaller") => TRUE */
static inline int string_match(const char *a, const char *b)
{
size_t min = MIN(strlen(a), strlen(b));
return !strncasecmp(a, b, min);
}
/* Strict comparison, e.g., sys_string_match("small", "smaller") => FALSE */
static inline int string_compare (const char *a, const char *b)
{
return strlen(a) == strlen(b) && !strcmp(a, b);
}
/* Strict comparison, like sys_string_compare(), but case insensitive,
* e.g., sys_string_match("small", "SmAlL") => TRUE
*/
static inline int string_case_compare (const char *a, const char *b)
{
return strlen (a) == strlen (b) && !strcasecmp (a, b);
}
/* Compat */
#define copy_filep (src, dst) fcopyfile (src,dst)
#define pidfile_read_pid (file) pifile_read (file)
#define signal_pidfile (file, signo) pidfile_signal (file,signo)
#endif /* FINIT_LITE_H_ */
/**
* Local Variables:
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+1
View File
@@ -0,0 +1 @@
*.m4
+585
View File
@@ -0,0 +1,585 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_prog_doxygen.html
# ===========================================================================
#
# SYNOPSIS
#
# DX_INIT_DOXYGEN(PROJECT-NAME, [DOXYFILE-PATH], [OUTPUT-DIR], ...)
# DX_DOXYGEN_FEATURE(ON|OFF)
# DX_DOT_FEATURE(ON|OFF)
# DX_HTML_FEATURE(ON|OFF)
# DX_CHM_FEATURE(ON|OFF)
# DX_CHI_FEATURE(ON|OFF)
# DX_MAN_FEATURE(ON|OFF)
# DX_RTF_FEATURE(ON|OFF)
# DX_XML_FEATURE(ON|OFF)
# DX_PDF_FEATURE(ON|OFF)
# DX_PS_FEATURE(ON|OFF)
#
# DESCRIPTION
#
# The DX_*_FEATURE macros control the default setting for the given
# Doxygen feature. Supported features are 'DOXYGEN' itself, 'DOT' for
# generating graphics, 'HTML' for plain HTML, 'CHM' for compressed HTML
# help (for MS users), 'CHI' for generating a separate .chi file by the
# .chm file, and 'MAN', 'RTF', 'XML', 'PDF' and 'PS' for the appropriate
# output formats. The environment variable DOXYGEN_PAPER_SIZE may be
# specified to override the default 'a4wide' paper size.
#
# By default, HTML, PDF and PS documentation is generated as this seems to
# be the most popular and portable combination. MAN pages created by
# Doxygen are usually problematic, though by picking an appropriate subset
# and doing some massaging they might be better than nothing. CHM and RTF
# are specific for MS (note that you can't generate both HTML and CHM at
# the same time). The XML is rather useless unless you apply specialized
# post-processing to it.
#
# The macros mainly control the default state of the feature. The use can
# override the default by specifying --enable or --disable. The macros
# ensure that contradictory flags are not given (e.g.,
# --enable-doxygen-html and --enable-doxygen-chm,
# --enable-doxygen-anything with --disable-doxygen, etc.) Finally, each
# feature will be automatically disabled (with a warning) if the required
# programs are missing.
#
# Once all the feature defaults have been specified, call DX_INIT_DOXYGEN
# with the following parameters: a one-word name for the project for use
# as a filename base etc., an optional configuration file name (the
# default is '$(srcdir)/Doxyfile', the same as Doxygen's default), and an
# optional output directory name (the default is 'doxygen-doc'). To run
# doxygen multiple times for different configuration files and output
# directories provide more parameters: the second, forth, sixth, etc
# parameter are configuration file names and the third, fifth, seventh,
# etc parameter are output directories. No checking is done to catch
# duplicates.
#
# Automake Support
#
# The DX_RULES substitution can be used to add all needed rules to the
# Makefile. Note that this is a substitution without being a variable:
# only the @DX_RULES@ syntax will work.
#
# The provided targets are:
#
# doxygen-doc: Generate all doxygen documentation.
#
# doxygen-run: Run doxygen, which will generate some of the
# documentation (HTML, CHM, CHI, MAN, RTF, XML)
# but will not do the post processing required
# for the rest of it (PS, PDF).
#
# doxygen-ps: Generate doxygen PostScript documentation.
#
# doxygen-pdf: Generate doxygen PDF documentation.
#
# Note that by default these are not integrated into the automake targets.
# If doxygen is used to generate man pages, you can achieve this
# integration by setting man3_MANS to the list of man pages generated and
# then adding the dependency:
#
# $(man3_MANS): doxygen-doc
#
# This will cause make to run doxygen and generate all the documentation.
#
# The following variable is intended for use in Makefile.am:
#
# DX_CLEANFILES = everything to clean.
#
# Then add this variable to MOSTLYCLEANFILES.
#
# LICENSE
#
# Copyright (c) 2009 Oren Ben-Kiki <oren@ben-kiki.org>
# Copyright (c) 2015 Olaf Mandel <olaf@mandel.name>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 20
## ----------##
## Defaults. ##
## ----------##
DX_ENV=""
AC_DEFUN([DX_FEATURE_doc], ON)
AC_DEFUN([DX_FEATURE_dot], OFF)
AC_DEFUN([DX_FEATURE_man], OFF)
AC_DEFUN([DX_FEATURE_html], ON)
AC_DEFUN([DX_FEATURE_chm], OFF)
AC_DEFUN([DX_FEATURE_chi], OFF)
AC_DEFUN([DX_FEATURE_rtf], OFF)
AC_DEFUN([DX_FEATURE_xml], OFF)
AC_DEFUN([DX_FEATURE_pdf], ON)
AC_DEFUN([DX_FEATURE_ps], ON)
## --------------- ##
## Private macros. ##
## --------------- ##
# DX_ENV_APPEND(VARIABLE, VALUE)
# ------------------------------
# Append VARIABLE="VALUE" to DX_ENV for invoking doxygen and add it
# as a substitution (but not a Makefile variable). The substitution
# is skipped if the variable name is VERSION.
AC_DEFUN([DX_ENV_APPEND],
[AC_SUBST([DX_ENV], ["$DX_ENV $1='$2'"])dnl
m4_if([$1], [VERSION], [], [AC_SUBST([$1], [$2])dnl
AM_SUBST_NOTMAKE([$1])])dnl
])
# DX_DIRNAME_EXPR
# ---------------
# Expand into a shell expression prints the directory part of a path.
AC_DEFUN([DX_DIRNAME_EXPR],
[[expr ".$1" : '\(\.\)[^/]*$' \| "x$1" : 'x\(.*\)/[^/]*$']])
# DX_IF_FEATURE(FEATURE, IF-ON, IF-OFF)
# -------------------------------------
# Expands according to the M4 (static) status of the feature.
AC_DEFUN([DX_IF_FEATURE], [ifelse(DX_FEATURE_$1, ON, [$2], [$3])])
# DX_REQUIRE_PROG(VARIABLE, PROGRAM)
# ----------------------------------
# Require the specified program to be found for the DX_CURRENT_FEATURE to work.
AC_DEFUN([DX_REQUIRE_PROG], [
AC_PATH_TOOL([$1], [$2])
if test "$DX_FLAG_[]DX_CURRENT_FEATURE$$1" = 1; then
AC_MSG_WARN([$2 not found - will not DX_CURRENT_DESCRIPTION])
AC_SUBST(DX_FLAG_[]DX_CURRENT_FEATURE, 0)
fi
])
# DX_TEST_FEATURE(FEATURE)
# ------------------------
# Expand to a shell expression testing whether the feature is active.
AC_DEFUN([DX_TEST_FEATURE], [test "$DX_FLAG_$1" = 1])
# DX_CHECK_DEPEND(REQUIRED_FEATURE, REQUIRED_STATE)
# -------------------------------------------------
# Verify that a required features has the right state before trying to turn on
# the DX_CURRENT_FEATURE.
AC_DEFUN([DX_CHECK_DEPEND], [
test "$DX_FLAG_$1" = "$2" \
|| AC_MSG_ERROR([doxygen-DX_CURRENT_FEATURE ifelse([$2], 1,
requires, contradicts) doxygen-DX_CURRENT_FEATURE])
])
# DX_CLEAR_DEPEND(FEATURE, REQUIRED_FEATURE, REQUIRED_STATE)
# ----------------------------------------------------------
# Turn off the DX_CURRENT_FEATURE if the required feature is off.
AC_DEFUN([DX_CLEAR_DEPEND], [
test "$DX_FLAG_$1" = "$2" || AC_SUBST(DX_FLAG_[]DX_CURRENT_FEATURE, 0)
])
# DX_FEATURE_ARG(FEATURE, DESCRIPTION,
# CHECK_DEPEND, CLEAR_DEPEND,
# REQUIRE, DO-IF-ON, DO-IF-OFF)
# --------------------------------------------
# Parse the command-line option controlling a feature. CHECK_DEPEND is called
# if the user explicitly turns the feature on (and invokes DX_CHECK_DEPEND),
# otherwise CLEAR_DEPEND is called to turn off the default state if a required
# feature is disabled (using DX_CLEAR_DEPEND). REQUIRE performs additional
# requirement tests (DX_REQUIRE_PROG). Finally, an automake flag is set and
# DO-IF-ON or DO-IF-OFF are called according to the final state of the feature.
AC_DEFUN([DX_ARG_ABLE], [
AC_DEFUN([DX_CURRENT_FEATURE], [$1])
AC_DEFUN([DX_CURRENT_DESCRIPTION], [$2])
AC_ARG_ENABLE(doxygen-$1,
[AS_HELP_STRING(DX_IF_FEATURE([$1], [--disable-doxygen-$1],
[--enable-doxygen-$1]),
DX_IF_FEATURE([$1], [don't $2], [$2]))],
[
case "$enableval" in
#(
y|Y|yes|Yes|YES)
AC_SUBST([DX_FLAG_$1], 1)
$3
;; #(
n|N|no|No|NO)
AC_SUBST([DX_FLAG_$1], 0)
;; #(
*)
AC_MSG_ERROR([invalid value '$enableval' given to doxygen-$1])
;;
esac
], [
AC_SUBST([DX_FLAG_$1], [DX_IF_FEATURE([$1], 1, 0)])
$4
])
if DX_TEST_FEATURE([$1]); then
$5
:
fi
if DX_TEST_FEATURE([$1]); then
$6
:
else
$7
:
fi
])
## -------------- ##
## Public macros. ##
## -------------- ##
# DX_XXX_FEATURE(DEFAULT_STATE)
# -----------------------------
AC_DEFUN([DX_DOXYGEN_FEATURE], [AC_DEFUN([DX_FEATURE_doc], [$1])])
AC_DEFUN([DX_DOT_FEATURE], [AC_DEFUN([DX_FEATURE_dot], [$1])])
AC_DEFUN([DX_MAN_FEATURE], [AC_DEFUN([DX_FEATURE_man], [$1])])
AC_DEFUN([DX_HTML_FEATURE], [AC_DEFUN([DX_FEATURE_html], [$1])])
AC_DEFUN([DX_CHM_FEATURE], [AC_DEFUN([DX_FEATURE_chm], [$1])])
AC_DEFUN([DX_CHI_FEATURE], [AC_DEFUN([DX_FEATURE_chi], [$1])])
AC_DEFUN([DX_RTF_FEATURE], [AC_DEFUN([DX_FEATURE_rtf], [$1])])
AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])])
AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])])
AC_DEFUN([DX_PDF_FEATURE], [AC_DEFUN([DX_FEATURE_pdf], [$1])])
AC_DEFUN([DX_PS_FEATURE], [AC_DEFUN([DX_FEATURE_ps], [$1])])
# DX_INIT_DOXYGEN(PROJECT, [CONFIG-FILE], [OUTPUT-DOC-DIR], ...)
# --------------------------------------------------------------
# PROJECT also serves as the base name for the documentation files.
# The default CONFIG-FILE is "$(srcdir)/Doxyfile" and OUTPUT-DOC-DIR is
# "doxygen-doc".
# More arguments are interpreted as interleaved CONFIG-FILE and
# OUTPUT-DOC-DIR values.
AC_DEFUN([DX_INIT_DOXYGEN], [
# Files:
AC_SUBST([DX_PROJECT], [$1])
AC_SUBST([DX_CONFIG], ['ifelse([$2], [], [$(srcdir)/Doxyfile], [$2])'])
AC_SUBST([DX_DOCDIR], ['ifelse([$3], [], [doxygen-doc], [$3])'])
m4_if(m4_eval(3 < m4_count($@)), 1, [m4_for([DX_i], 4, m4_count($@), 2,
[AC_SUBST([DX_CONFIG]m4_eval(DX_i[/2]),
'm4_default_nblank_quoted(m4_argn(DX_i, $@),
[$(srcdir)/Doxyfile])')])])dnl
m4_if(m4_eval(3 < m4_count($@)), 1, [m4_for([DX_i], 5, m4_count($@,), 2,
[AC_SUBST([DX_DOCDIR]m4_eval([(]DX_i[-1)/2]),
'm4_default_nblank_quoted(m4_argn(DX_i, $@),
[doxygen-doc])')])])dnl
m4_define([DX_loop], m4_dquote(m4_if(m4_eval(3 < m4_count($@)), 1,
[m4_for([DX_i], 4, m4_count($@), 2, [, m4_eval(DX_i[/2])])],
[])))dnl
# Environment variables used inside doxygen.cfg:
DX_ENV_APPEND(SRCDIR, $srcdir)
DX_ENV_APPEND(PROJECT, $DX_PROJECT)
DX_ENV_APPEND(VERSION, $PACKAGE_VERSION)
# Doxygen itself:
DX_ARG_ABLE(doc, [generate any doxygen documentation],
[],
[],
[DX_REQUIRE_PROG([DX_DOXYGEN], doxygen)
DX_REQUIRE_PROG([DX_PERL], perl)],
[DX_ENV_APPEND(PERL_PATH, $DX_PERL)])
# Dot for graphics:
DX_ARG_ABLE(dot, [generate graphics for doxygen documentation],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[DX_REQUIRE_PROG([DX_DOT], dot)],
[DX_ENV_APPEND(HAVE_DOT, YES)
DX_ENV_APPEND(DOT_PATH, [`DX_DIRNAME_EXPR($DX_DOT)`])],
[DX_ENV_APPEND(HAVE_DOT, NO)])
# Man pages generation:
DX_ARG_ABLE(man, [generate doxygen manual pages],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[],
[DX_ENV_APPEND(GENERATE_MAN, YES)],
[DX_ENV_APPEND(GENERATE_MAN, NO)])
# RTF file generation:
DX_ARG_ABLE(rtf, [generate doxygen RTF documentation],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[],
[DX_ENV_APPEND(GENERATE_RTF, YES)],
[DX_ENV_APPEND(GENERATE_RTF, NO)])
# XML file generation:
DX_ARG_ABLE(xml, [generate doxygen XML documentation],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[],
[DX_ENV_APPEND(GENERATE_XML, YES)],
[DX_ENV_APPEND(GENERATE_XML, NO)])
# (Compressed) HTML help generation:
DX_ARG_ABLE(chm, [generate doxygen compressed HTML help documentation],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[DX_REQUIRE_PROG([DX_HHC], hhc)],
[DX_ENV_APPEND(HHC_PATH, $DX_HHC)
DX_ENV_APPEND(GENERATE_HTML, YES)
DX_ENV_APPEND(GENERATE_HTMLHELP, YES)],
[DX_ENV_APPEND(GENERATE_HTMLHELP, NO)])
# Separate CHI file generation.
DX_ARG_ABLE(chi, [generate doxygen separate compressed HTML help index file],
[DX_CHECK_DEPEND(chm, 1)],
[DX_CLEAR_DEPEND(chm, 1)],
[],
[DX_ENV_APPEND(GENERATE_CHI, YES)],
[DX_ENV_APPEND(GENERATE_CHI, NO)])
# Plain HTML pages generation:
DX_ARG_ABLE(html, [generate doxygen plain HTML documentation],
[DX_CHECK_DEPEND(doc, 1) DX_CHECK_DEPEND(chm, 0)],
[DX_CLEAR_DEPEND(doc, 1) DX_CLEAR_DEPEND(chm, 0)],
[],
[DX_ENV_APPEND(GENERATE_HTML, YES)],
[DX_TEST_FEATURE(chm) || DX_ENV_APPEND(GENERATE_HTML, NO)])
# PostScript file generation:
DX_ARG_ABLE(ps, [generate doxygen PostScript documentation],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[DX_REQUIRE_PROG([DX_LATEX], latex)
DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex)
DX_REQUIRE_PROG([DX_DVIPS], dvips)
DX_REQUIRE_PROG([DX_EGREP], egrep)])
# PDF file generation:
DX_ARG_ABLE(pdf, [generate doxygen PDF documentation],
[DX_CHECK_DEPEND(doc, 1)],
[DX_CLEAR_DEPEND(doc, 1)],
[DX_REQUIRE_PROG([DX_PDFLATEX], pdflatex)
DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex)
DX_REQUIRE_PROG([DX_EGREP], egrep)])
# LaTeX generation for PS and/or PDF:
if DX_TEST_FEATURE(ps) || DX_TEST_FEATURE(pdf); then
DX_ENV_APPEND(GENERATE_LATEX, YES)
else
DX_ENV_APPEND(GENERATE_LATEX, NO)
fi
# Paper size for PS and/or PDF:
AC_ARG_VAR(DOXYGEN_PAPER_SIZE,
[a4wide (default), a4, letter, legal or executive])
case "$DOXYGEN_PAPER_SIZE" in
#(
"")
AC_SUBST(DOXYGEN_PAPER_SIZE, "")
;; #(
a4wide|a4|letter|legal|executive)
DX_ENV_APPEND(PAPER_SIZE, $DOXYGEN_PAPER_SIZE)
;; #(
*)
AC_MSG_ERROR([unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE'])
;;
esac
# Rules:
AS_IF([[test $DX_FLAG_html -eq 1]],
[[DX_SNIPPET_html="## ------------------------------- ##
## Rules specific for HTML output. ##
## ------------------------------- ##
DX_CLEAN_HTML = \$(DX_DOCDIR)/html]dnl
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
\$(DX_DOCDIR]DX_i[)/html]])[
"]],
[[DX_SNIPPET_html=""]])
AS_IF([[test $DX_FLAG_chi -eq 1]],
[[DX_SNIPPET_chi="
DX_CLEAN_CHI = \$(DX_DOCDIR)/\$(PACKAGE).chi]dnl
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).chi]])["]],
[[DX_SNIPPET_chi=""]])
AS_IF([[test $DX_FLAG_chm -eq 1]],
[[DX_SNIPPET_chm="## ------------------------------ ##
## Rules specific for CHM output. ##
## ------------------------------ ##
DX_CLEAN_CHM = \$(DX_DOCDIR)/chm]dnl
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
\$(DX_DOCDIR]DX_i[)/chm]])[\
${DX_SNIPPET_chi}
"]],
[[DX_SNIPPET_chm=""]])
AS_IF([[test $DX_FLAG_man -eq 1]],
[[DX_SNIPPET_man="## ------------------------------ ##
## Rules specific for MAN output. ##
## ------------------------------ ##
DX_CLEAN_MAN = \$(DX_DOCDIR)/man]dnl
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
\$(DX_DOCDIR]DX_i[)/man]])[
"]],
[[DX_SNIPPET_man=""]])
AS_IF([[test $DX_FLAG_rtf -eq 1]],
[[DX_SNIPPET_rtf="## ------------------------------ ##
## Rules specific for RTF output. ##
## ------------------------------ ##
DX_CLEAN_RTF = \$(DX_DOCDIR)/rtf]dnl
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
\$(DX_DOCDIR]DX_i[)/rtf]])[
"]],
[[DX_SNIPPET_rtf=""]])
AS_IF([[test $DX_FLAG_xml -eq 1]],
[[DX_SNIPPET_xml="## ------------------------------ ##
## Rules specific for XML output. ##
## ------------------------------ ##
DX_CLEAN_XML = \$(DX_DOCDIR)/xml]dnl
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
\$(DX_DOCDIR]DX_i[)/xml]])[
"]],
[[DX_SNIPPET_xml=""]])
AS_IF([[test $DX_FLAG_ps -eq 1]],
[[DX_SNIPPET_ps="## ----------------------------- ##
## Rules specific for PS output. ##
## ----------------------------- ##
DX_CLEAN_PS = \$(DX_DOCDIR)/\$(PACKAGE).ps]dnl
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).ps]])[
DX_PS_GOAL = doxygen-ps
doxygen-ps: \$(DX_CLEAN_PS)
]m4_foreach([DX_i], [DX_loop],
[[\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).ps: \$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag
\$(DX_V_LATEX)cd \$(DX_DOCDIR]DX_i[)/latex; \\
rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \\
\$(DX_LATEX) refman.tex; \\
\$(DX_MAKEINDEX) refman.idx; \\
\$(DX_LATEX) refman.tex; \\
countdown=5; \\
while \$(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \\
refman.log > /dev/null 2>&1 \\
&& test \$\$countdown -gt 0; do \\
\$(DX_LATEX) refman.tex; \\
countdown=\`expr \$\$countdown - 1\`; \\
done; \\
\$(DX_DVIPS) -o ../\$(PACKAGE).ps refman.dvi
]])["]],
[[DX_SNIPPET_ps=""]])
AS_IF([[test $DX_FLAG_pdf -eq 1]],
[[DX_SNIPPET_pdf="## ------------------------------ ##
## Rules specific for PDF output. ##
## ------------------------------ ##
DX_CLEAN_PDF = \$(DX_DOCDIR)/\$(PACKAGE).pdf]dnl
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).pdf]])[
DX_PDF_GOAL = doxygen-pdf
doxygen-pdf: \$(DX_CLEAN_PDF)
]m4_foreach([DX_i], [DX_loop],
[[\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).pdf: \$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag
\$(DX_V_LATEX)cd \$(DX_DOCDIR]DX_i[)/latex; \\
rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \\
\$(DX_PDFLATEX) refman.tex; \\
\$(DX_MAKEINDEX) refman.idx; \\
\$(DX_PDFLATEX) refman.tex; \\
countdown=5; \\
while \$(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \\
refman.log > /dev/null 2>&1 \\
&& test \$\$countdown -gt 0; do \\
\$(DX_PDFLATEX) refman.tex; \\
countdown=\`expr \$\$countdown - 1\`; \\
done; \\
mv refman.pdf ../\$(PACKAGE).pdf
]])["]],
[[DX_SNIPPET_pdf=""]])
AS_IF([[test $DX_FLAG_ps -eq 1 -o $DX_FLAG_pdf -eq 1]],
[[DX_SNIPPET_latex="## ------------------------------------------------- ##
## Rules specific for LaTeX (shared for PS and PDF). ##
## ------------------------------------------------- ##
DX_V_LATEX = \$(_DX_v_LATEX_\$(V))
_DX_v_LATEX_ = \$(_DX_v_LATEX_\$(AM_DEFAULT_VERBOSITY))
_DX_v_LATEX_0 = @echo \" LATEX \" \$][@;
DX_CLEAN_LATEX = \$(DX_DOCDIR)/latex]dnl
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
\$(DX_DOCDIR]DX_i[)/latex]])[
"]],
[[DX_SNIPPET_latex=""]])
AS_IF([[test $DX_FLAG_doc -eq 1]],
[[DX_SNIPPET_doc="## --------------------------------- ##
## Format-independent Doxygen rules. ##
## --------------------------------- ##
${DX_SNIPPET_html}\
${DX_SNIPPET_chm}\
${DX_SNIPPET_man}\
${DX_SNIPPET_rtf}\
${DX_SNIPPET_xml}\
${DX_SNIPPET_ps}\
${DX_SNIPPET_pdf}\
${DX_SNIPPET_latex}\
DX_V_DXGEN = \$(_DX_v_DXGEN_\$(V))
_DX_v_DXGEN_ = \$(_DX_v_DXGEN_\$(AM_DEFAULT_VERBOSITY))
_DX_v_DXGEN_0 = @echo \" DXGEN \" \$<;
.PHONY: doxygen-run doxygen-doc \$(DX_PS_GOAL) \$(DX_PDF_GOAL)
.INTERMEDIATE: doxygen-run \$(DX_PS_GOAL) \$(DX_PDF_GOAL)
doxygen-run:]m4_foreach([DX_i], [DX_loop],
[[ \$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag]])[
doxygen-doc: doxygen-run \$(DX_PS_GOAL) \$(DX_PDF_GOAL)
]m4_foreach([DX_i], [DX_loop],
[[\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag: \$(DX_CONFIG]DX_i[) \$(pkginclude_HEADERS)
\$(DX_V_DXGEN)\$(DX_ENV) DOCDIR=\$(DX_DOCDIR]DX_i[) \$(DX_DOXYGEN) \$(DX_CONFIG]DX_i[)
\$(A""M_V_at)echo Timestamp >\$][@
]])dnl
[DX_CLEANFILES = \\]
m4_foreach([DX_i], [DX_loop],
[[ \$(DX_DOCDIR]DX_i[)/doxygen_sqlite3.db \\
\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag \\
]])dnl
[ -r \\
\$(DX_CLEAN_HTML) \\
\$(DX_CLEAN_CHM) \\
\$(DX_CLEAN_CHI) \\
\$(DX_CLEAN_MAN) \\
\$(DX_CLEAN_RTF) \\
\$(DX_CLEAN_XML) \\
\$(DX_CLEAN_PS) \\
\$(DX_CLEAN_PDF) \\
\$(DX_CLEAN_LATEX)"]],
[[DX_SNIPPET_doc=""]])
AC_SUBST([DX_RULES],
["${DX_SNIPPET_doc}"])dnl
AM_SUBST_NOTMAKE([DX_RULES])
#For debugging:
#echo DX_FLAG_doc=$DX_FLAG_doc
#echo DX_FLAG_dot=$DX_FLAG_dot
#echo DX_FLAG_man=$DX_FLAG_man
#echo DX_FLAG_html=$DX_FLAG_html
#echo DX_FLAG_chm=$DX_FLAG_chm
#echo DX_FLAG_chi=$DX_FLAG_chi
#echo DX_FLAG_rtf=$DX_FLAG_rtf
#echo DX_FLAG_xml=$DX_FLAG_xml
#echo DX_FLAG_pdf=$DX_FLAG_pdf
#echo DX_FLAG_ps=$DX_FLAG_ps
#echo DX_ENV=$DX_ENV
])
-124
View File
@@ -1,124 +0,0 @@
/* mkpath() -- Create all components leading up to a given directory
*
* Copyright (c) 2013 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 <libgen.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
int mkpath(char *dir, mode_t mode)
{
if (!dir) {
errno = EINVAL;
return 1;
}
if (strlen(dir) == 1 && dir[0] == '/')
return 0;
mkpath(dirname(strdupa(dir)), mode);
return mkdir(dir, mode);
}
/**
* makepath - Create all components of the specified directory.
* @dir: Directory to create.
*
* Returns:
* POSIX OK (0) on success, otherwise -1 and errno set appropriately.
* This function returns EINVAL on bad argument, or ENOMEM when it
* fails allocating temporary memory. For other error codes see the
* mkdir() syscall description.
*/
int makepath(char *dir)
{
return mkpath(dir, 0777);
}
/********************************* UNIT TESTS ************************************/
#ifdef UNITTEST
#include "lite.h"
int checkpath(char *dir)
{
char tmp[256];
struct stat sb;
snprintf(tmp, sizeof(tmp), "ls -ld %s", dir);
if (system(tmp))
perror("system");
if (!stat(dir, &sb) && S_ISDIR(sb.st_mode))
return 0;
errno = ENOTDIR;
return 1;
}
int test_makepath(char *dir)
{
int ret = makepath(dir);
if (!ret)
ret = checkpath(dir);
if (ret)
perror("Failed");
return ret;
}
int main(void)
{
int i, ret = 0;
char *list[] = {
"/tmp/tok/",
"/tmp/tok2",
"/tmp/ab",
"/tmp/b",
"/tmp/a/",
"/tmp/a/b",
"/tmp/a/c/",
NULL
};
for (i = 0; list[i]; i++)
rmdir(list[i]);
printf("Testing makepath() ...\n");
for (i = 0; list[i] && !ret; i++)
ret = test_makepath(list[i]);
printf("\nCleaning up ...\n");
for (i = 0; list[i]; i++)
rmdir(list[i]);
return ret;
}
#endif /* UNITTEST */
/**
* Local Variables:
* compile-command: "make V=1 -f makepath.mk"
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
-4
View File
@@ -1,4 +0,0 @@
OBJS =
TARGET = makepath.test clean
include rules.mk
-173
View File
@@ -1,173 +0,0 @@
/* Functions for dealing with PID files (client side)
*
* Copyright (c) 2009-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 <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
extern char *chomp(char *str);
/**
* pidfile_read - Reads a PID value from a pidfile.
* @pidfile: File containing PID, usually in /var/run/<PROC>.pid
*
* This function takes a @pidfile and returns the PID found therein.
*
* Returns:
* On invalid @pidfile -1 and errno set to %EINVAL, when @pidfile does not exist -1
* and errno set to %ENOENT. When the pidfile is empty or when its contents cannot
* be translated this function returns zero (0), on success this function returns
* a PID value greater than one. PID 1 is reserved for the system init process.
*/
pid_t pidfile_read(const char *pidfile)
{
int pid = 0;
char buf[16];
FILE *fp;
if (!pidfile) {
errno = EINVAL;
return -1;
}
fp = fopen(pidfile, "r");
if (!fp)
return -1;
if (fgets(buf, sizeof(buf), fp)) {
char *ptr = chomp(buf);
if (ptr) {
errno = 0;
pid = strtoul(ptr, NULL, 0);
if (errno)
pid = 0; /* Failed conversion. */
}
}
fclose(fp);
return pid;
}
/**
* pidfile_poll - Poll for the existence of a pidfile and return PID
* @pidfile: Path to pidfile to poll for
*
* This function polls for the pidfile at @pidfile for at most 5 seconds
* before timing out. If the file is created within that time span the
* file is read and its PID contents returned.
*
* Returns:
* The PID read from @pidfile, or zero on timeout.
*/
pid_t pidfile_poll(const char *pidfile)
{
pid_t pid = 0;
int tries = 0;
/* Timeout = 100 * 50ms = 5s */
while ((pid = pidfile_read(pidfile)) <= 0 && tries++ < 100)
usleep(50000); /* Wait 50ms between retries */
if (pid < 0)
pid = 0;
return pid;
}
/**
* pidfile_signal - Send signal to a PID and cleanup pidfile afterwards
* @pidfile: File containing PID, usually in /var/run/<PROC>.pid
* @signal: Signal to send to PID found in @pidfile.
*
* If @signal is any of %SIGTERM, %SIGKILL, or if kill() returns -1 the
* @pidfile is removed.
*
* Returns:
* POSIX OK(0) on success, non-zero otherwise.
*/
int pidfile_signal(const char *pidfile, int signal)
{
int pid = -1, ret = -1;
pid = pidfile_read(pidfile);
if (pid <= 0)
return 1;
ret = kill(pid, signal);
if ((ret == -1) || (signal == SIGTERM) || (signal == SIGKILL))
(void)remove(pidfile);
return 0;
}
/********************************* UNIT TESTS ************************************/
#ifdef UNITTEST
#include <paths.h>
#include "lite.h"
extern char *__progname;
static char PIDFILE[42];
static void sigterm_handler(int signo)
{
printf("Exiting ...\n");
}
static void sigalrm_handler(int signo)
{
printf("Testing pidfile() ...\n");
pidfile(NULL);
if (!fexist(PIDFILE))
err(1, "pidfile() failed creating %s", PIDFILE);
}
int main(void)
{
snprintf(PIDFILE, sizeof(PIDFILE), "%s%s.pid", _PATH_VARRUN, __progname);
signal(SIGTERM, sigterm_handler);
signal(SIGALRM, sigalrm_handler);
alarm(1);
printf("Testing pidfile_poll() ...\n");
if (!pidfile_poll(PIDFILE))
printf("Timed out!\n");
else
printf("We got signal!\n");
printf("Reading pid file, should be %d ...\n", getpid());
printf("=> %d\n", pidfile_read(PIDFILE));
printf("Signalling ourselves ...\n");
return pidfile_signal(PIDFILE, SIGTERM);
}
#endif /* UTEST_PIDFN */
/**
* Local Variables:
* compile-command: "make V=1 -f pidfilefn.mk"
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
-5
View File
@@ -1,5 +0,0 @@
OBJS = pidfile.o chomp.o fexist.o
ASROOT = 1
TARGET = clean $(OBJS) pidfilefn.test
include rules.mk
-4
View File
@@ -1,4 +0,0 @@
OBJS =
TARGET = progress.test clean
include rules.mk
-313
View File
@@ -1,313 +0,0 @@
/* Micro "rsync" implementation.
*
* Copyright (c) 2011, 2012 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 <stdlib.h> /* NULL, free() */
#include <string.h> /* strlen() */
#include <strings.h> /* rindex() */
#include <stdio.h>
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
#include <sys/stat.h>
#include <sys/types.h>
#include "lite.h"
static int copy(char *src, char *dst);
static int mdir(char *buf, size_t buf_len, char *dir, char *name, mode_t mode);
static int prune(char *dst, char **new_files, int new_num);
/**
* rsync - Synchronize contents and optionally remove non-existing backups
* @src: Source directory
* @dst: Destination directory
* @delete: Prune files from @dst that no longer exist in @src.
* @filter: Optional filtering function for source directory.
*
* This is a miniature implementation of the famous rsync for local use only.
* In fact, it is not even a true rsync since it copies all files from @src
* to @dst. The @delete option is useful for creating backups, when set all
* files removed from src since last backup are pruned from the destination
* (backup) directory.
*
* 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:
* POSIX OK(0), or non-zero with @errno set on error.
*/
int rsync(char *src, char *dst, int delete, int (*filter) (const char *file))
{
char source[256];
char dest[256];
int i = 0, num = 0, result = 0;
char **files; /* Array of file names. */
if (!fisdir(dst))
makedir(dst, 0755);
if (!fisdir(src)) {
if (!fexist(src))
return 1;
if (copy(src, dst))
result++;
return errno;
}
/* Copy dir as well? */
if (!fisslashdir(src)) {
char *ptr = rindex(src, '/');
if (!ptr)
ptr = src;
else
ptr++;
if (mdir(dest, sizeof(dest), dst, ptr, fmode(src)))
return 1;
dst = dest;
}
num = dir(src, "", filter, &files, 0);
for (i = 0; i < num; i++) {
/* Recursively copy sub-directries */
snprintf(source, sizeof(source), "%s%s%s", src, fisslashdir(src) ? "" : "/", files[i]);
if (fisdir(source)) {
char dst2[256];
strcat(source, "/");
if (mdir (dst2, sizeof(dst2), dst, files[i], fmode(source))) {
result++;
continue;
}
rsync(source, dst2, delete, filter);
continue; /* Next file/dir in @src to copy... */
}
if (copy(source, dst))
result++;
}
/* We ignore any errors from the pruning, that phase albeit useful is only
* cosmetic. --Jocke 2011-03-24 */
if (delete)
prune(dst, files, num);
if (num) {
for (i = 0; i < num; i++)
free(files[i]);
free(files);
}
return result;
}
static int copy(char *src, char *dst)
{
errno = 0;
copyfile(src, dst, 0, 1);
if (errno) {
if (errno != EEXIST)
return 1;
errno = 0;
}
return 0;
}
/* 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)
{
snprintf(buf, buf_len, "%s%s%s/", dir, fisslashdir(dir) ? "" : "/", name);
if (mkdir(buf, mode)) {
if (EEXIST != errno)
return 1;
errno = 0;
}
return 0;
}
static int find(char *file, char **files, int num)
{
int n;
for (n = 0; n < num; n++)
if (!strncmp (files[n], file, MAX(strlen(files[n]), strlen(file))))
return 1;
return 0;
}
/* Prune old files, no longer existing on source, from destination directory. */
static int prune(char *dst, char **new_files, int new_num)
{
int num, result = 0;
char **files;
num = dir(dst, "", NULL, &files, 0);
if (num) {
int i;
for (i = 0; i < num; i++) {
if (!find(files[i], new_files, new_num)) {
char *name;
size_t len = strlen(files[i]) + 2 + strlen(dst);
name = malloc(len);
if (name) {
snprintf(name, len, "%s%s%s", dst, fisslashdir(dst) ? "" : "/", files[i]);
if (remove(name))
result++;
free(name);
}
}
free(files[i]);
}
free(files);
}
return result;
}
#ifdef UNITTEST
#define BASE "/tmp/.unittest/"
#define SRC BASE "src/"
#define DST BASE "dst/"
static int verbose = 0;
static char *files[] = {
SRC "sub1/1.tst",
SRC "sub1/2.tst",
SRC "sub1/3.tst",
SRC "sub2/4.tst",
SRC "sub2/5.tst",
SRC "sub2/6.tst",
SRC "sub3/7.tst",
SRC "sub3/8.tst",
SRC "sub3/9.tst",
NULL
};
void cleanup_test(void)
{
system("rm -rf " BASE);
}
void setup_test(void)
{
int i;
char cmd[256];
mode_t dir_modes[] = { 755, 700 };
mode_t file_modes[] = { 644, 600 };
cleanup_test();
mkdir(BASE, 0755);
mkdir(SRC, 0755);
mkdir(DST, 0755);
for (i = 0; files[i]; i++) {
snprintf(cmd, sizeof(cmd), "mkdir -m %d -p `dirname %s`",
dir_modes[i % 2], files[i]);
system(cmd);
snprintf(cmd, sizeof(cmd), "touch %s; chmod %d %s", files[i],
file_modes[i % 2], files[i]);
system(cmd);
}
}
static void check_tree(char *heading, char *dir)
{
if (verbose) {
char cmd[128];
if (heading)
puts(heading);
tree(dir, 1);
}
}
int run_test(void)
{
int result = 0;
#if 0
setup_test();
check_tree("Before:", BASE);
result += rsync(SRC, DST, 0, NULL);
check_tree("After:", BASE);
cleanup_test();
#endif
setup_test();
result += rsync(BASE "src", DST, 0, NULL);
check_tree("Only partial rsync of src <-- No slash!", BASE);
#if 0
cleanup_test();
setup_test();
result += rsync(BASE "src/sub1", BASE "dst", 0, NULL);
check_tree("Only partial rsync of src/sub1 <-- No slashes!!", BASE);
cleanup_test();
setup_test();
result += rsync(BASE "src/sub1/", DST, 0, NULL);
check_tree("Only partial rsync of src/sub1/", BASE);
cleanup_test();
setup_test();
result += rsync(BASE "src/sub1", DST, 0, NULL);
check_tree("Only partial rsync of src/sub1 <-- No slash!", BASE);
result += rsync("/etc", "/var/tmp", 0, NULL);
check_tree("Real life test:", "/var/tmp");
#endif
return result;
}
int main(int argc, char *argv[])
{
if (argc > 1)
verbose = !strncmp("-v", argv[1], 2);
atexit(cleanup_test);
return run_test();
}
#endif /* UNITTEST */
/**
* Local Variables:
* compile-command: "make V=1 -f rsync.mk"
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
-4
View File
@@ -1,4 +0,0 @@
OBJS = dir.o copyfile.o fexist.o fisdir.o fmode.o tree.o
TARGET = clean $(OBJS) rsync.test
include rules.mk
-68
View File
@@ -1,68 +0,0 @@
.PHONY: all clean distclean
# Figure out root of library, unless used as submodule
ROOTDIR ?= $(shell pwd)
CC ?= $(CROSS)gcc
AR ?= $(CROSS)ar
STRIP ?= $(CROSS)strip
INSTALL := install --backup=off
STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755
CPPFLAGS += -D_GNU_SOURCE
ARFLAGS = crus
# Default to silent build, use V=1 to get verbose mode.
ifeq ($V,1)
Q =
PRINT = @true
REDIRECT =
MAKEFLAGS =
VERBOSE = -v
else
Q = @
PRINT = @printf
REDIRECT = >/dev/null
MAKEFLAGS = --no-print-directory --silent
VERBOSE =
endif
# Some tests may need to be run as root, e.g. pidfile()
ifeq ($(ASROOT), 1)
SUDO = sudo -n
else
SUDO =
endif
# Default install paths
prefix ?= /usr/local
libdir ?= $(prefix)/lib
datadir ?= $(prefix)/share/doc/$(LIBNAME)
incdir ?= $(prefix)/include
# Pretty printing and GCC -M for auto dep files
%.o: %.c
$(PRINT) " CC $(subst $(ROOTDIR)/,,$(shell pwd)/)$@\n"
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -c -MMD -MP -o $@ $<
%: %.o
$(PRINT) " LINK $(subst $(ROOTDIR)/,,$(shell pwd)/)$@\n"
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-Map,$@.map -o $@ $^ $(LDLIBS$(LDLIBS-$(@)))
.PHONY: %.test
%.test: %.c
$(PRINT) " TEST $(subst $(ROOTDIR)/,,$(shell pwd)/)$(@:.test=)\n"
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -g -o $@ -DUNITTEST $< $(OBJS)
$(Q)$(RM) $(OBJS)
$(Q)$(SUDO) ./$@ $(VERBOSE) $(REDIRECT)
# Default build rules for both main and unit test makefiles
all:: $(TARGET)
clean::
-$(Q)$(RM) $(OBJS) $(DEPS) $(TARGET) $(SOLIB) $(STATICLIB)
distclean::
-$(Q)$(RM) $(JUNK) unittest *.o *.a *.so* *.unittest *.test
+3
View File
@@ -0,0 +1,3 @@
*.la
.libs/*
libite_la*
+45
View File
@@ -0,0 +1,45 @@
lib_LTLIBRARIES = libite.la
libite_la_CPPFLAGS = -D_GNU_SOURCE
libite_la_CFLAGS = -W -Wall -Wextra
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 9:0:4
libite_la_SOURCES = chomp.c copyfile.c \
conio.c conio.h dir.c \
erasef.c fopenf.c fremove.c \
fexist.c fisdir.c \
fparseln.c fsendfile.c \
ifconfig.c lfile.c \
makepath.c procval.c progress.c \
pidfile.c pidfilefn.c popenf.c \
reallocarray.c rsync.c runbg.c \
strlcpy.c strlcat.c strtonum.c \
strdupa.h strndupa.h strnlen.h \
strmatch.c systemf.c strtrim.c \
telnet.c tempfile.c truncatef.c \
touchf.c yorn.c which.c \
lite.h strlite.h \
queue.h tree.h
## Distribute these header files in the <libite/...> namespace
pkgincludedir = $(includedir)/libite
pkginclude_HEADERS = lite.h queue.h conio.h tree.h strlite.h strdupa.h \
strndupa.h strnlen.h
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libite.pc
## For compatibility with previous <lite/...> namespace
if COMPAT_SYMLINK
install-data-hook:
link=$(DESTDIR)$(includedir)/lite; \
if [ ! -f $$link ]; then \
$(LN_S) libite $$link; \
fi
uninstall-hook:
link=$(shell readlink $(DESTDIR)$(includedir)/lite); \
if [ "$$link" = "libite" ]; then \
$(RM) $(DESTDIR)$(includedir)/lite; \
fi
endif
+14 -19
View File
@@ -1,6 +1,6 @@
/* Perl inspired chomp() implementation.
*
* Copyright (c) 2014-2015 Joachim Nilsson <troglobit@gmail.com>
* Copyright (c) 2014-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -15,19 +15,25 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file chomp.c
* @author Joachim Wiberg
* @date 2014-2021
* @copyright ISC License
*/
#include <errno.h>
#include <string.h>
/**
* chomp - Perl like chomp function, chop off last char(s) if newline.
* @str: String to chomp
* Perl like chomp function, chop off last char(s) if newline.
* @param str String to chomp
*
* This function is like Perl chomp, but it's set to chop of all
* trailing newlines.
* trailing newlines. Useful in combination with fgets().
*
* Returns:
* If @str is a valid pointer this function returns @str, otherwise
* @errno is set to %EINVAL and this function returns %NULL.
* @returns @a str, or @c NULL with @a errno set, if @a str is not a valid pointer.
* @exception EINVAL if the input argument is not a valid pointer.
*/
char *chomp(char *str)
{
@@ -39,25 +45,14 @@ char *chomp(char *str)
}
p = str + strlen(str) - 1;
while (*p == '\n')
while (p >= str && *p == '\n')
*p-- = 0;
return str;
}
#ifdef UNITTEST
#include <stdio.h>
int main(void)
{
int i; char t[][16] = { "hej\ndej", "Slime\n\n\\n", "Tripple\n\n\n", "" };
for (i = 0; t[i][0]; i++) printf("[%02d]: '%s'\n", i, chomp(t[i])); return 0;
}
#endif
/**
* Local Variables:
* compile-command: "make V=1 -f chomp.mk"
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
+104
View File
@@ -0,0 +1,104 @@
/* A conio.h like implementation for VTANSI displays.
*
* Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file conio.c
* @author Joachim Wiberg
* @date 2009-2021
* @copyright ISC License
*/
#include <poll.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
/**
* Probe terminal size
* @param row pointer to integer to store number of rows
* @param col pointer to integer to store number of columns
*
* This function checks if stdin and stdout isatty() and then sets the
* TTY in raw mode to silently ask the size using ANSI escape sequences.
* This is achieved by trying to go to corner 999,999 followed by
* querying the cursor position. Afterwards the TTY is returned to the
* state if was before, e.g. cooked. The number of rows and columns is
* returned in the input arguments to this function.
*
* If stdio is @a not a TTY, then a default 24x80 is returned.
*/
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:
*/
+144
View File
@@ -0,0 +1,144 @@
/* A conio.h like implementation for VTANSI displays.
*
* Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file conio.h
* @author Joachim Wiberg
* @date 2009-2021
* @copyright ISC License
*
* Helper macros and functions for interacting with TTY terminals.
*/
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef LIBITE_CONIO_H_
#define LIBITE_CONIO_H_
#include <stdio.h>
/** Attributes */
#define RESETATTR 0
#define BRIGHT 1
#define DIM 2
#define UNDERSCORE 4
#define BLINK 5 /* May not work on all displays. */
#define REVERSE 7
#define HIDDEN 8
/** Colors for text and background */
#define BLACK 0x0
#define RED 0x1
#define GREEN 0x2
#define BROWN 0x3
#define BLUE 0x4
#define MAGENTA 0x5
#define CYAN 0x6
#define LIGHTGREY 0x7
#define DARKGREY 0x10
#define LIGHTRED 0x11
#define LIGHTGREEN 0x12
#define YELLOW 0x13
#define LIGHTBLUE 0x14
#define LIGHTMAGENTA 0x15
#define LIGHTCYAN 0x16
#define WHITE 0x17
#ifndef SCREEN_WIDTH
#define SCREEN_WIDTH 80 /**< Fallback screen width, possible to override. */
#endif
/** Clear screen and move cursor to 1,1 (upper left) pos. */
#define clrscr() fputs("\033[2J\033[1;1H", stdout)
/** Erases from the current cursor position to the end of the current line. */
#define clreol() fputs("\033[K", stdout)
/** Erases the entire current line. */
#define delline() fputs("\033[2K", stdout)
/** Moves the cursor to the specified position (coordinates) */
#define gotoxy(x,y) fprintf(stdout, "\033[%d;%dH", y, x)
/** Hide Cursor */
#define hidecursor() fputs("\033[?25l", stdout)
/** Show Cursor */
#define showcursor() fputs("\033[?25h", stdout)
/** Set Graphics Mode (attr, color, val) */
#define __set_gm(a,c,v) \
if (!c) \
fprintf(stdout, "\033[%dm", a); \
else \
fprintf(stdout, "\033[%d;%dm", c & 0x10 ? 1 : 0, (c & 0xF) + v)
/** Set text attribute */
#define textattr(attr) __set_gm(attr, 0, 0)
/** Set text color */
#define textcolor(color) __set_gm(RESETATTR, color, 30)
/** Set text background */
#define textbackground(color) __set_gm(RESETATTR, color, 40)
void initscr(int *row, int *col);
/**
* Print table heading, with optional leading newline.
* @param fp output stream
* @param line string to print
* @param nl leading newline or not
* @param attr attribute
*
* @verbatim
* _________________ <-- Empty line with UNDERSCORE to frame first heading
* First heading <-- In normal/RESETATTR
* SUBHEADING <-- In REVERSE and with capital letters like 'top'
* @endverbatim
*/
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), "");
}
/**
* Print reverse mode table heading, e.g. black text on white background.
* @param fp output stream
* @param line string to print
* @param nl leading newline or not
*/
static inline void printheader(FILE *fp, const char *line, int nl)
{
printhdr(fp, line, nl, REVERSE);
}
#endif /* LIBITE_CONIO_H_ */
#ifdef __cplusplus
}
#endif
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+94 -116
View File
@@ -21,26 +21,30 @@
* THE SOFTWARE.
*/
/**
* @file copyfile.c
* @author Claudio Matsuoka
* @date 2008
* @copyright MIT License
*/
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "lite.h"
/* Tests if dst is a directory, if so, reallocates dst and appends src filename returning 1 */
static int adjust_target(char *src, char **dst)
static int adjust_target(const char *src, char **dst)
{
int isdir = 0;
retry:
if (fisdir(*dst)) {
int slash = 0;
char *tmp, *ptr = strrchr(src, '/');
if (!ptr)
ptr = src;
ptr = (char *)src;
else
ptr++;
@@ -55,16 +59,25 @@ static int adjust_target(char *src, char **dst)
sprintf(tmp, "%s%s%s", *dst, slash ? "" : "/", ptr);
*dst = tmp;
} else {
struct stat st;
if (stat(*dst, &st) && fisslashdir(*dst)) {
makedir(*dst, 0755);
goto retry;
}
}
return isdir;
}
/* Actual copy loop, used by both copyfile() and fcopyfile()
* breaks loop on error and EOF */
/*
* Actual copy loop, used by both copyfile() and fcopyfile() breaks loop
* on error and EOF
*/
static ssize_t do_copy(int in, int out, size_t num, char *buffer, size_t len)
{
ssize_t ret = 0, size = 0;
ssize_t ret = 0, size = -1;
do {
size_t count = num > len ? len : num;
@@ -73,37 +86,66 @@ static ssize_t do_copy(int in, int out, size_t num, char *buffer, size_t len)
if (ret <= 0) {
if (ret == -1 && EINTR == errno)
continue;
if (ret == 0 && size == -1)
size = 0;
break;
}
if (ret > 0)
if (ret > 0) {
if (size == -1)
size = 0;
size += write(out, buffer, ret);
}
num -= count;
} while (num > 0);
return size;
}
static void set_mtime(int in, int out)
{
struct stat st;
struct timespec tv[2];
if (fstat(in, &st))
return;
tv[0] = st.st_atim;
tv[1] = st.st_mtim;
futimens(out, tv);
}
/**
* copyfile - Copy a file to another.
* @src: Full path name to source file.
* @dst: Full path name to target file.
* @len: Number of bytes to copy, zero (0) for entire file.
* @sym: Should symlinks be recreated (1) or followed (0)
* Copy a file to another.
* @param src Full path name to source file.
* @param dst Full path name to target file.
* @param len Number of bytes to copy, zero (0) for entire file.
* @param 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
* 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
* of fastinit for the Asus EeePC.
*
* Returns:
* 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
* will be set to %EISDIR since copyfile() is not recursive.
* The @a opt field replaces the @a sym argument in previous releases
* and works as follows. To maintain backwards compatibility with @a
* sym the ::LITE_FOPT_COPYFILE_SYM has a value of @c 1. Supported
* option flags are:
*
* - ::LITE_FOPT_COPYFILE_SYM Recreate symlink or follow to copy target
* - ::LITE_FOPT_KEEP_MTIME Preserve modification time
*
* @returns The number of bytes copied, or zero, which may be an error
* (check @a errno, see Exceptions below), but it may also indicate that
* @a src was empty. See exceptions, below.
*
* @exception EISDIR if @a src is a directory, 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;
size_t num;
ssize_t size = 0;
@@ -121,7 +163,7 @@ ssize_t copyfile(char *src, char *dst, int len, int sym)
}
/* Check if target is a directory, then append src filename. */
isdir = adjust_target(src, &dst);
isdir = adjust_target(src, &dest);
/* Check if the source file is a symlink ... */
if (stat(src, &st)) {
@@ -138,7 +180,7 @@ ssize_t copyfile(char *src, char *dst, int len, int sym)
size = -1;
} else {
buffer[size] = 0;
size = !symlink(buffer, dst);
size = !symlink(buffer, dest);
}
}
@@ -159,7 +201,7 @@ ssize_t copyfile(char *src, char *dst, int len, int sym)
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) {
close(in);
saved_errno = errno;
@@ -167,8 +209,10 @@ ssize_t copyfile(char *src, char *dst, int len, int sym)
}
size = do_copy(in, out, num, buffer, BUFSIZ);
if (!size && errno)
if (size < 0)
saved_errno = errno;
else if (keep_mtim)
set_mtime(in, out);
close(out);
close(in);
@@ -176,39 +220,39 @@ ssize_t copyfile(char *src, char *dst, int len, int sym)
exit:
free(buffer);
if (isdir)
free(dst);
free(dest);
errno = saved_errno;
return size;
}
/**
* movefile - Move a file to another location
* @src: Source file.
* @dst: Target file, or location.
* Move a file to another location
* @param src Source file.
* @param dst Target file, or location.
*
* This is a C implementation of the command line mv(1) utility.
* Usually the rename() API is sufficient, but not when moving across
* file system boundaries.
*
* The @src argument must include the full path to the source file,
* whereas the @dst argument may only be a directory, in which case the
* same file name from @src is used.
* The @p src argument must include the full path to the source file,
* whereas the @p dst argument may only be a directory, in which case
* the same file name from @p src is used.
*
* Returns:
* POSIX OK(0), or non-zero with errno set.
* @returns POSIX OK(0), or non-zero with @a errno set.
*/
int movefile(char *src, char *dst)
int movefile(const char *src, const char *dst)
{
char *dest = (char *)dst;
int isdir, result = 0;
/* Check if target is a directory, then append the src base filename. */
isdir = adjust_target(src, &dst);
isdir = adjust_target(src, &dest);
if (rename(src, dst)) {
if (rename(src, dest)) {
if (errno == EXDEV) {
errno = 0;
copyfile(src, dst, 0, 1);
copyfile(src, dest, 0, 1);
if (errno)
result = 1;
else
@@ -219,107 +263,41 @@ int movefile(char *src, char *dst)
}
if (isdir)
free(dst);
free(dest);
return result;
}
/**
* fcopyfile - Copy between FILE *fp.
* @src: Source FILE.
* @dst: Destination FILE.
* Copy between FILE *fp.
* @param src Source FILE.
* @param dst Destination FILE.
*
* Function takes signals into account and will restart the syscalls as
* long as error is %EINTR.
*
* Returns:
* POSIX OK(0), or non-zero with errno set on error.
* @returns POSIX OK(0), or non-zero with @a errno set on error.
*/
int fcopyfile(FILE *src, FILE *dst)
{
int ret;
char *buffer;
char *buf;
if (!src || !dst) {
errno = EINVAL;
return -1;
}
buffer = malloc(BUFSIZ);
if (!buffer)
buf = malloc(BUFSIZ);
if (!buf)
return -1;
ret = do_copy(fileno(src), fileno(dst), BUFSIZ, buffer, BUFSIZ);
if (ret > 0)
ret = 0;
else if (errno)
ret = -1;
free(buffer);
return ret;
}
#ifdef UNITTEST
#include <err.h>
int main(void)
{
int i = 0;
char *files[] = {
"/etc/passwd", "/tmp/tok", "/tmp/tok",
"/etc/passwd", "/tmp/", "/tmp/passwd",
"/etc/passwd", "/tmp", "/tmp/passwd",
NULL
};
FILE *src, *dst;
printf("=>Start testing fcopyfile()\n");
while (files[i]) {
printf("fcopyfile(%s, %s)\t", files[i], files[i + 1]);
src = fopen(files[i], "r");
dst = fopen(files[i + 1], "w");
if (fcopyfile(src, dst)) {
if (!fisdir(files[i + 1]))
err(1, "Failed fcopyfile(%s, %s)", files[i], files[i + 1]);
}
if (src)
fclose(src);
if (dst)
fclose(dst);
if (fexist(files[i + 2]))
printf("OK => %s", files[i + 2]);
printf("\n");
erase(files[i + 2]);
i += 3;
}
printf("\n=>Start testing copyfile()\n");
i = 0;
while (files[i]) {
printf("copyfile(%s, %s)\t", files[i], files[i + 1]);
if (!copyfile(files[i], files[i + 1], 0, 0))
err(1, "Failed copyfile(%s, %s)", files[i], files[i + 1]);
if (fexist(files[i + 2]))
printf("OK => %s", files[i + 2]);
printf("\n");
erase(files[i + 2]);
i += 3;
}
while (fgets(buf, BUFSIZ, src))
fputs(buf, dst);
free(buf);
return 0;
}
#endif /* UNITTEST */
/**
* Local Variables:
* compile-command: "make V=1 -f copyfile.mk"
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
+136
View File
@@ -0,0 +1,136 @@
/* Functions for operating on files in directories.
*
* Copyright (c) 2008-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file dir.c
* @author Joachim Wiberg
* @date 2008-2021
* @copyright ISC License
*/
#include <errno.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
static const char *matcher_type = NULL;
static int (*matcher_filter) (const char *file) = NULL;
static int matcher(const struct dirent *entry)
{
char *pos = strrchr(entry->d_name, '.');
if (matcher_filter && !matcher_filter(entry->d_name))
/* User matcher overrides the rest. */
return 0;
/* Skip current 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;
/* filetype == "" */
if (matcher_type[0] == 0)
return 1;
/* Entry has no "." */
if (!pos)
return 0;
return !strcmp(pos, matcher_type);
}
/**
* List all files of a certain type in the given directory.
* @param dir Base directory for dir operation.
* @param type File type suffix, e.g. ".cfg".
* @param filter Optional file name filter.
* @param list Pointer to an array of file names.
* @param strip Flag, if set dir() strips the file type.
*
* This function returns a @a list of files, matching the @a type
* suffix, in the given directory @a dir.
*
* The @a list argument is a pointer to where to store the dynamically
* allocated list of file names. This list should be free'd by first
* calling free() on each file name and then on the list itself.
*
* If @a filter is not @c NULL it will be called for each file found.
* If @a filter returns non-zero the @a file argument is included in the
* resulting @a list. If @a filter returns zero for given @a file it is
* discarded. If the @a strip flag is set the resulting @a list of
* files has their file type stripped, including the dot. So a match
* "config0.cfg" would be returned as "config0".
*
* @returns The number of files in @a list, zero if no matching files of
* @a type, or non-zero on error with @a errno set.
*/
int dir(const char *dir, const char *type, int (*filter) (const char *file), char ***list, int strip)
{
int i, n, num = 0;
char **files;
struct dirent **namelist;
if (!list) {
errno = EINVAL;
return -1;
}
if (!dir)
/* Assuming current directory */
dir = ".";
if (!type)
/* Assuming all files. */
type = "";
matcher_type = type;
matcher_filter = filter;
n = scandir(dir, &namelist, matcher, alphasort);
if (n < 0)
return -1;
if (n > 0) {
files = (char **)malloc(n * sizeof(char *));
for (i = 0; i < n; i++) {
if (files) {
char *name = namelist[i]->d_name;
char *type = strrchr(name, '.');
if (type && strip)
*type = 0;
files[i] = strdup(name);
num++;
}
free(namelist[i]);
}
if (num)
*list = files;
}
if (namelist)
free(namelist);
return num;
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+72
View File
@@ -0,0 +1,72 @@
/* Formatted erase()
*
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file erasef.c
* @author Joachim Wiberg
* @date 2021
* @copyright ISC License
*/
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include "lite.h"
/**
* Like erase() but with formatted string support.
* @param fmt Formatted string to be composed into a pathname
*
* This is a wrapper for the erase() function in lite.h, lessening the
* burden of having to compose the filename from parts in a seprate
* buffer.
*
* @returns Upon successful completion erasef() returns POSIX OK(0),
* otherwise, -1 is returned and @a errno is set to indicate the error.
*/
int erasef(const char *fmt, ...)
{
va_list ap;
char *file;
int len;
va_start(ap, fmt);
len = vsnprintf(NULL, 0, fmt, ap);
va_end(ap);
file = alloca(len + 1);
if (!file) {
errno = ENOMEM;
return -1;
}
va_start(ap, fmt);
vsnprintf(file, len + 1, fmt, ap);
va_end(ap);
return erase(file);
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+43 -28
View File
@@ -21,17 +21,28 @@
* THE SOFTWARE.
*/
/**
* @file fexist.c
* @author Claudio Matsuoka
* @date 2008
* @copyright MIT License
*/
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include "lite.h"
/**
* fexist - Check if a file exists in the file system.
* @file: File to look for, with full path.
* Check if a file exists in the file system.
* @param file File to look for, with full path.
*
* Returns:
* %TRUE(1) if the file exists, otherwise %FALSE(0).
* @returns @c TRUE(1) if the @a file exists, otherwise @c FALSE(0).
*/
int fexist(char *file)
int fexist(const char *file)
{
if (!file) {
errno = EINVAL;
@@ -44,37 +55,41 @@ int fexist(char *file)
return 1;
}
#ifdef UNITTEST
#include "lite.h"
int main(void)
/**
* Like fexist() but with formatted string support
* @param fmt Formatted string to be composed into the file to look for.
*
* This is a wrapper for the fexist() function in lite.h, lessening the
* burden of having to compose the filename from parts in a seprate
* buffer.
*
* @returns @c TRUE(1) if the @a file exists, otherwise @c FALSE(0).
*/
int fexistf(const char *fmt, ...)
{
int i = 0;
struct { char *file; int exist; } arr[] = {
{ "/etc/passwd", 1 },
{ "/etc/kalle", 0 },
{ "/sbin/init", 1 },
{ "/dev/null", 1 },
{ NULL, 0 },
};
FILE *src, *dst;
va_list ap;
char *file;
int len;
for (i = 0; i < NELEMS(arr); i++) {
if (fexist(arr[i].file) != arr[i].exist)
err(1, "Failed fexist(%s)", arr[i].file ?: "NULL");
else
printf("File %-11s %-14s => OK!\n", arr[i].file ?: "NULL",
arr[i].exist ? "does exist" : "does not exist");
va_start(ap, fmt);
len = vsnprintf(NULL, 0, fmt, ap);
va_end(ap);
file = alloca(len + 1);
if (!file) {
errno = ENOMEM;
return -1;
}
return 0;
va_start(ap, fmt);
vsnprintf(file, len + 1, fmt, ap);
va_end(ap);
return fexist(file);
}
#endif /* UNITTEST */
/**
* Local Variables:
* compile-command: "make V=1 -f fexist.mk"
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
+14 -16
View File
@@ -1,4 +1,4 @@
/* File mode bit operations
/* Check if directory exists
*
* Copyright (c) 2008 Claudio Matsuoka <http://helllabs.org/finit/>
*
@@ -21,36 +21,34 @@
* THE SOFTWARE.
*/
#include <errno.h>
#include <sys/types.h>
/**
* @file fisdir.c
* @author Claudio Matsuoka
* @date 2008
* @copyright MIT License
*/
#include <sys/stat.h>
#include <unistd.h>
/**
* fmode - Return a file's mode bits.
* @file: File to look for, with full path.
* Check if a path exists and is a directory.
* @param path Path to file or directory
*
* Returns:
* The mode bits or zero when @file does not exist and errno set to %ENOENT.
* @returns @c TRUE(1) if @p path exists and is a directory, otherwise @c FALSE(0).
*/
mode_t fmode(char *file)
int fisdir(const char *path)
{
struct stat sb;
if (!file) {
errno = EINVAL;
return 0;
}
if (!stat(file, &sb))
return sb.st_mode;
if (path && !stat(path, &sb) && S_ISDIR(sb.st_mode))
return 1;
return 0;
}
/**
* Local Variables:
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
+94
View File
@@ -0,0 +1,94 @@
/* Formatted fopen()
*
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file fopenf.c
* @author Joachim Wiberg
* @date 2021
* @copyright ISC License
*/
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
/**
* Similar to fopenf() except it takes a @a va_list argument
* @param mode An fopen() mode string, e.g. "w+".
* @param fmt Formatted string to be composed into a pathname.
* @param ap List of variable arguemnts from va_start().
*
* See fopenf() for details.
*
* @returns a FILE pointer, or @c NULL on error.
*/
FILE *vfopenf(const char *mode, const char *fmt, va_list ap)
{
va_list apc;
char *file;
int len;
va_copy(apc, ap);
len = vsnprintf(NULL, 0, fmt, apc);
va_end(apc);
file = alloca(len + 1);
if (!file) {
errno = ENOMEM;
return NULL;
}
va_copy(apc, ap);
vsnprintf(file, len + 1, fmt, apc);
va_end(apc);
return fopen(file, mode);
}
/**
* Open a file based on the formatted string and optional arguments
* @param mode An fopen() mode string, e.g. "w+".
* @param fmt Formatted string to be composed into a pathname.
*
* This function is an extension to the fopen() family, lessening the burden
* of first having to compose the filename from parts in a seprate buffer.
*
* @returns Upon successful completion, fopenf() returns a FILE pointer.
* Otherwise, @c NULL is returned and @a errno is set to indicate the
* error.
*/
FILE *fopenf(const char *mode, const char *fmt, ...)
{
va_list ap;
FILE *fp;
va_start(ap, fmt);
fp = vfopenf(mode, fmt, ap);
va_end(ap);
if (!fp)
return NULL;
return fp;
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+221
View File
@@ -0,0 +1,221 @@
/* $NetBSD: fparseln.c,v 1.10 2009/10/21 01:07:45 snj Exp $ */
/*
* Copyright (c) 1997 Christos Zoulas. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file fparseln.c
* @author Christos Zoulas
* @date 1997
* @copyright 2-clause BSD License
*/
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "lite.h"
#ifndef _DIAGASSERT
#define _DIAGASSERT(t)
#endif
static int isescaped(const char *, const char *, int);
/* isescaped():
* Return true if the character in *p that belongs to a string
* that starts in *sp, is escaped by the escape character esc.
*/
static int
isescaped(const char *sp, const char *p, int esc)
{
const char *cp;
size_t ne;
_DIAGASSERT(sp != NULL);
_DIAGASSERT(p != NULL);
/* No escape character */
if (esc == '\0')
return 0;
/* Count the number of escape characters that precede ours */
for (ne = 0, cp = p; --cp >= sp && *cp == esc; ne++)
continue;
/* Return true if odd number of escape characters */
return (ne & 1) != 0;
}
/**
* Read a line from a file parsing continuations and trailing newlines
* @param fp FILE pointer to read from
* @param size The resulting length of the string, unused if @c NULL
* @param lineno Incremented with number of lines read, unused if @c NULL
* @param str Characters to look for, escape character, continuation, and comment
* @param flags ::FPARSELN_UNESCCOMM, ::FPARSELN_UNESCCONT, ::FPARSELN_UNESCESC, ::FPARSELN_UNESCREST, ::FPARSELN_UNESCALL
*
* This function reads a line from a file, parsing continuations ending
* in '\' and eliminating trailing newlines, or comments starting with
* the comment char '#'.
*
* If @a size is not @c NULL, the resulting length of the returned string
* is stored in @a size.
*
* If @a lineno is not @c NULL, it is incremented for each actual line
* read from @a fp.
*
* @returns the line read from @a fp, or @c NULL on EOF or error.
*/
char *
fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
{
static const char dstr[3] = { '\\', '\\', '#' };
ssize_t s;
size_t len, ptrlen;
char *buf;
char *ptr, *cp;
int cnt;
char esc, con, nl, com;
_DIAGASSERT(fp != NULL);
len = 0;
buf = NULL;
ptrlen = 0;
ptr = NULL;
cnt = 1;
if (str == NULL)
str = dstr;
esc = str[0];
con = str[1];
com = str[2];
/*
* XXX: it would be cool to be able to specify the newline character,
* getdelim(3) does let us, but supporting it would diverge from BSDs.
*/
nl = '\n';
flockfile(fp);
while (cnt) {
cnt = 0;
if (lineno)
(*lineno)++;
s = getline(&ptr, &ptrlen, fp);
if (s < 0)
break;
if (s && com) { /* Check and eliminate comments */
for (cp = ptr; cp < ptr + s; cp++)
if (*cp == com && !isescaped(ptr, cp, esc)) {
s = cp - ptr;
cnt = s == 0 && buf == NULL;
break;
}
}
if (s && nl) { /* Check and eliminate newlines */
cp = &ptr[s - 1];
if (*cp == nl)
s--; /* forget newline */
}
if (s && con) { /* Check and eliminate continuations */
cp = &ptr[s - 1];
if (*cp == con && !isescaped(ptr, cp, esc)) {
s--; /* forget continuation char */
cnt = 1;
}
}
if (s == 0) {
/*
* nothing to add, skip realloc except in case
* we need a minimal buf to return an empty line
*/
if (cnt || buf != NULL)
continue;
}
if ((cp = realloc(buf, len + s + 1)) == NULL) {
funlockfile(fp);
free(buf);
free(ptr);
return NULL;
}
buf = cp;
(void) memcpy(buf + len, ptr, s);
len += s;
buf[len] = '\0';
}
funlockfile(fp);
free(ptr);
if ((flags & FPARSELN_UNESCALL) != 0 && esc && buf != NULL &&
strchr(buf, esc) != NULL) {
ptr = cp = buf;
while (cp[0] != '\0') {
int skipesc;
while (cp[0] != '\0' && cp[0] != esc)
*ptr++ = *cp++;
if (cp[0] == '\0' || cp[1] == '\0')
break;
skipesc = 0;
if (cp[1] == com)
skipesc += (flags & FPARSELN_UNESCCOMM);
if (cp[1] == con)
skipesc += (flags & FPARSELN_UNESCCONT);
if (cp[1] == esc)
skipesc += (flags & FPARSELN_UNESCESC);
if (cp[1] != com && cp[1] != con && cp[1] != esc)
skipesc = (flags & FPARSELN_UNESCREST);
if (skipesc)
cp++;
else
*ptr++ = *cp++;
*ptr++ = *cp++;
}
*ptr = '\0';
len = strlen(buf);
}
if (size)
*size = len;
return buf;
}
+68
View File
@@ -0,0 +1,68 @@
/* Formatted fremove()
*
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file fremove.c
* @author Joachim Wiberg
* @date 2021
* @copyright ISC License
*/
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
/**
* Remove a file based on the formatted string and optional arguments
* @param fmt Formatted string to be composed into a pathname
*
* This function is an extension to remove(), lessening the burden of
* first having to compose the filename from parts in a seprate buffer.
*
* @returns same as remove(3), with an extra @a errno, @c ENOBUFS if
* alloca() fails to get a temporary buffer for composing the file name.
*/
int fremove(const char *fmt, ...)
{
va_list ap;
char *file;
int len;
va_start(ap, fmt);
len = vsnprintf(NULL, 0, fmt, ap);
va_end(ap);
file = alloca(len + 1);
if (!file) {
errno = ENOBUFS;
return -1;
}
va_start(ap, fmt);
vsnprintf(file, len + 1, fmt, ap);
va_end(ap);
return remove(file);
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+24 -51
View File
@@ -21,37 +21,45 @@
* THE SOFTWARE.
*/
/**
* @file fsendfile.c
* @author Tobias Waldekranz
* @date 2013
* @copyright MIT License
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
/**
* fsendfile - copy data between file streams
* @src: Source stream
* @dst: Destination stream
* @len: Number of bytes to copy
* Copy data between file streams.
* @param src Source stream
* @param dst Destination stream
* @param len Number of bytes to copy
*
* @dst may be %NULL, in which case @len bytes are read and discarded
* from @src. This can be useful for streams where seeking is not
* permitted. Additionally, @len may be the special value zero (0), in
* which case fsendfile() will copy until %EOF is seen on @src.
* The @p dst argument may be @c NULL, in which case @a len bytes are
* read and discarded from @a src. This can be useful for streams where
* seeking is not permitted. Additionally, @a len may be the special
* value zero (0), in which case fsendfile() copies until @c EOF is seen
* on @a src.
*
* Returns:
* The number of bytes copied. If an error is detected -1 is returned
* and @errno will be set accordingly.
* @returns The number of bytes copied. If an error is detected -1 is
* returned and @a errno will be set accordingly.
*/
size_t fsendfile(FILE *src, FILE *dst, size_t len)
ssize_t fsendfile(FILE *src, FILE *dst, size_t len)
{
char *buf;
size_t blk = BUFSIZ, num = 0, tot = 0;
size_t tot = 0;
ssize_t blk = BUFSIZ, num = 0;
if (!src) {
errno = EINVAL;
return -1;
}
buf = (char *)malloc(BUFSIZ);
buf = malloc(BUFSIZ);
if (!buf)
return -1;
@@ -73,46 +81,11 @@ size_t fsendfile(FILE *src, FILE *dst, size_t len)
free(buf);
return (num == (size_t)-1) ? (size_t)-1 : tot;
return (num == -1) ? -1 : (ssize_t)tot;
}
#ifdef UNITTEST
#include <err.h>
#include <unistd.h>
int main(void)
{
int i = 0;
char *files[] = {
"/etc/passwd", "/tmp/tok",
"/etc/passwd", "/tmp/passwd",
"/etc/passwd", "/tmp/passwd",
NULL
};
FILE *src, *dst;
while (files[i]) {
src = fopen(files[i], "r");
dst = fopen(files[i + 1], "w");
printf("fsendfile(%s, %s, 512)\t", files[i], files[i + 1]);
if (-1 == fsendfile(src, dst, 512))
err(1, "Failed fsendfile(%s, %s)", files[i], files[i + 1]);
if (!access(files[i + 1], F_OK))
printf("OK => %s\n", files[i + 1]);
remove(files[i + 1]);
i += 2;
}
return 0;
}
#endif /* UNITTEST */
/**
* Local Variables:
* compile-command: "make V=1 -f fsendfile.mk"
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
+17 -11
View File
@@ -1,7 +1,7 @@
/* Fastinit (finit) ifconfig() implementation.
*
* Copyright (c) 2008 Claudio Matsuoka <http://helllabs.org/finit/>
* Copyright (C) 2009-2014 Joachim Nilsson <joachim.nilsson@westermo.se>
* Copyright (c) 2008-2010 Claudio Matsuoka <http://helllabs.org/finit/>
* Copyright (C) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -22,6 +22,14 @@
* THE SOFTWARE.
*/
/**
* @file ifconfig.c
* @author Claudio Matsuoka
* @author Joachim Wiberg
* @date 2008-2021
* @copyright MIT License
*/
#include <arpa/inet.h>
#include <errno.h>
#include <net/if.h>
@@ -34,16 +42,15 @@
extern size_t strlcpy(char *dst, const char *src, size_t siz);
/**
* ifconfig - Basic ifconfig like operations on an interface
* @ifname: Name of interface to operate on
* @addr: If @up then set this optional IPv4 address
* @mask: If @up and @addr, and @addr is not INADDR_ANY, then set netmask
* @up: Control %IFF_UP flag on interface
* Basic ifconfig like operations on an interface
* @param ifname Name of interface to operate on
* @param addr If @p up then set this optional IPv4 address
* @param mask If @p up and @p addr, and @p addr is not @c INADDR_ANY, then set netmask
* @param up Control @c IFF_UP flag on interface
*
* Returns:
* POSIX OK(0) on success, or non-zero on error.
* @returns POSIX OK(0) on success, or non-zero on error.
*/
int ifconfig(char *ifname, char *addr, char *mask, int up)
int ifconfig(const char *ifname, const char *addr, const char *mask, int up)
{
int sd, ret = -1;
struct ifreq ifr;
@@ -85,7 +92,6 @@ int ifconfig(char *ifname, char *addr, char *mask, int up)
/**
* Local Variables:
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
+196
View File
@@ -0,0 +1,196 @@
/* Parse UNIX /etc configuration files like /etc/protocols and /etc/services
*
* Copyright (c) 2015-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file lfile.c
* @author Joachim Wiberg
* @date 2015-2021
* @copyright ISC License
*/
#include <errno.h>
#include <stdio.h> /* FILE */
#include <stdlib.h> /* atoi() */
#include <string.h> /* strlen(), strncmp(), strtok_r() */
#include <sys/param.h> /* MAX() */
/** @private for internal use only */
typedef struct lfile {
FILE *fp; /**< FILE pointer to current stream */
char buf[256]; /**< Internal buffer, limted to 256 bytes per line */
char *save; /**< Internal save pointer */
const char *sep; /**< Record separator, from lfopen() */
} lfile_t;
/**
* Open file and return parsing context.
* @param file File to parse
* @param sep Separator(s) to use in lftok()
*
* @returns Pointer to an @a lfile_t parser context, or @c NULL on error.
*/
lfile_t *lfopen(const char *file, const char *sep)
{
lfile_t *lf;
if (!file || !sep) {
errno = EINVAL;
return NULL;
}
/* Use calloc for clearing buf on behalf of lftok() */
lf = calloc(sizeof(*lf), sizeof(char));
if (lf) {
lf->fp = fopen(file, "r");
lf->sep = sep;
lf->save = lf->buf;
if (!lf->fp) {
free(lf);
return NULL;
}
}
return lf;
}
/**
* Close a parser context.
* @param lf: Pointer to @a lfile_t parser context from lfopen()
*/
void lfclose(lfile_t *lf)
{
if (!lf)
return;
if (lf->fp)
fclose(lf->fp);
free(lf);
}
/**
* Get next token in file
* @param lf: Pointer to @a lfile_t parser context from lfopen()
*
* @returns Next token, read from file previously opened with lfopen(),
* or @c NULL if EOF.
*/
char *lftok(lfile_t *lf)
{
char *token;
if (!lf || !lf->fp || !lf->sep) {
errno = EINVAL;
return NULL;
}
token = strtok_r(NULL, lf->sep, &lf->save);
if (token)
return token;
while (fgets(lf->buf, sizeof(lf->buf), lf->fp)) {
if (lf->buf[0] == '#')
continue;
token = strtok_r(lf->buf, lf->sep, &lf->save);
if (token)
return token;
}
errno = ENOENT;
return NULL;
}
/**
* Find key in file
* @param lf Pointer to @a lfile_t parser context from lfopen()
* @param key Key to look for
*
* Locate @a key from the current position in the file parser context
* returned from lfopen(). Please note, the search for @a key does not
* start from the beginning of the file, it searches from the current
* position. To restart search from the beginning use rewind() on the
* lf->fp.
*
* @returns The value to @a key, or @c NULL if not found.
*/
char *lfgetkey(lfile_t *lf, const char *key)
{
char *token;
while ((token = lftok(lf))) {
if (token[0] == '#')
continue;
if (!strncmp(token, key, MAX(strlen(token), strlen(key))))
return lftok(lf);
}
return NULL;
}
/**
* Same as lfgetkey() but returns an integer.
* @param lf Pointer to @a lfile_t parser context from lfopen()
* @param key Key to look for
*
* This function is the same as lfgetkey() but returns the positive
* integer value for the matching @a key, if found.
*
* @returns The positive integer value for @a key, or -1 if not found.
*/
int lfgetint(lfile_t *lf, const char *key)
{
char *token = lfgetkey(lf, key);
if (token)
return atoi(token);
return -1;
}
/**
* Find the integer value for key in a file.
* @param file File to search for @a key
* @param sep Separator for tokens in @a file
* @param key Key to look for in @a file
*
* This is a convenience wrapper for lfopen(), lfgetint(), and
* lfclose().
*
* @returns The positive integer value for @a key, or -1 if not found.
*/
int fgetint(const char *file, const char *sep, const char *key)
{
int val = -1;
lfile_t *lf;
lf = lfopen(file, sep);
if (lf) {
val = lfgetint(lf, key);
lfclose(lf);
}
return val;
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+11
View File
@@ -0,0 +1,11 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: @PACKAGE@
Description: Frog DNA, basically
Version: @VERSION@
Requires:
Libs: -L${libdir} -lite
Cflags: -I${includedir} -D_LIBITE_LITE
+281
View File
@@ -0,0 +1,281 @@
/* Collection of frog DNA
*
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* 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.
*/
/**
* Collection of frog DNA
* @file lite.h
* @author Claudio Matsuoka (2008-2010)
* @author Joachim Wiberg (2008-2023)
* @copyright MIT License
*
* The latest version of this manual and the libite (-lite) software
* library are available at https://github.com/troglobit/libite/
*/
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef LIBITE_LITE_H_
#define LIBITE_LITE_H_
#include <errno.h>
#include <fcntl.h> /* Definition of AT_* constants for utimensat() */
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, INT32_MAX, etc. */
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
#include <unistd.h>
#include "strlite.h"
/*
* fparseln() specific operation flags.
*/
#define FPARSELN_UNESCESC 0x01 /**< Remove escape preceding an escaped comment. */
#define FPARSELN_UNESCCONT 0x02 /**< Remove escape preceding an escaped continuation. */
#define FPARSELN_UNESCCOMM 0x04 /**< Remove escape preceding an escaped escape. */
#define FPARSELN_UNESCREST 0x08 /**< Remove escape preceding any other character. */
#define FPARSELN_UNESCALL 0x0f /**< All of the above. */
/*
* copyfile() and rsync() option flags
*/
#define LITE_FOPT_RSYNC_DELETE 0x01 /**< Prune files from destination that are not in source */
#define LITE_FOPT_COPYFILE_SYM 0x01 /**< Recreate symlink or follow to copy target */
#define LITE_FOPT_KEEP_MTIME 0x02 /**< Preserve modification time */
typedef struct lfile lfile_t; /**< Opqaue context struct for lfile APIs */
typedef struct sdbuf sdbuf_t; /**< Opqaue context struct for telnet APIs */
char *chomp (char *str);
int erasef (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
int fexist (const char *file);
int fexistf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));;
int fisdir (const char *path);
FILE *vfopenf (const char *mode, const char *fmt, va_list ap);
FILE *fopenf (const char *mode, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
int fremove (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
FILE *tempfile (void);
ssize_t copyfile (const char *src, const char *dst, int len, int opt);
int movefile (const char *src, const char *dst);
int fcopyfile (FILE *src, FILE *dst);
ssize_t fsendfile (FILE *src, FILE *dst, size_t len);
int truncatef (off_t length, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
char *vreadsnf (char *line, size_t len, const char *fmt, va_list ap);
char *readsnf (char *line, size_t len, const char *fmt, ...);
int writesf (const char *str, const char *mode, const char *fmt, ...);
int vreadllf (long long *value, const char *fmt, va_list ap);
int readllf (long long *value, const char *fmt, ...);
int readdf (int *value, const char *fmt, ...);
int writellf (long long value, const char *mode, const char *fmt, ...);
int writedf (int value, const char *mode, const char *fmt, ...);
int ifconfig (const char *ifname, const char *addr, const char *mask, int up);
lfile_t*lfopen (const char *file, const char *sep);
void lfclose (lfile_t *lf);
char *lftok (lfile_t *lf);
char *lfgetkey (lfile_t *lf, const char *key);
int lfgetint (lfile_t *lf, const char *key);
int fgetint (const char *file, const char *sep, const char *key);
int fmkpath (mode_t mode, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
int mkpath (const char *dir, mode_t mode);
int makepath (const char *dir);
int dir (const char *dir, const char *type, int (*filter) (const char *file), char ***list, int strip);
int rsync (char *src, char *dst, int opt, int (*filter) (const char *file));
FILE *popenf (const char *type, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
int pidfile (const char *basename);
int pidfile_signal(const char *pidfile, int signal);
pid_t pidfile_read (const char *pidfile);
pid_t pidfile_poll (const char *pidfile);
void *reallocarray(void *optr, size_t nmemb, size_t size);
void progress (int percent, int max_width);
void progress_simple(int percent);
int runbg (char *const cmd[], int delay);
int systemf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
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 touchf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
int yorn (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
char *which (const char *cmd);
int whichp (const char *cmd);
#ifndef touch
#include <sys/stat.h> /* utimensat() */
#include <sys/time.h> /* utimensat() on *BSD */
/**
* Create a file, ignoring errors for already existing files
* @param path Path to file to create.
*
* @returns POSIX OK(0), or non-zero on error.
*/
static inline int touch(const char *path)
{
int fd;
if (utimensat(AT_FDCWD, path, NULL, 0)) {
if (errno != ENOENT)
return -1;
fd = creat(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if (fd < 0)
return -1;
close(fd);
}
return 0;
}
#endif
#ifndef makedir
/**
* Create a directory, ignoring errors for already existing files
* @param path Path to directory to create.
*
* @returns POSIX OK(0), or non-zero on error.
*/
static inline int makedir(const char *path, mode_t mode)
{
if (mkdir(path, mode) && errno != EEXIST)
return -1;
return 0;
}
#endif
#ifndef makefifo
/**
* Create a FIFO, ignoring errors for already existing files
* @param path Path to FIFO to create.
*
* @returns POSIX OK(0), or non-zero on error.
*/
static inline int makefifo(const char *path, mode_t mode)
{
if (mkfifo(path, mode) && errno != EEXIST)
return -1;
return 0;
}
#endif
#ifndef erase
/**
* Remove a file, ignoring errors for missing files
* @param path Path to file to remove.
*
* @returns POSIX OK(0), or non-zero on error.
*/
static inline int erase(const char *path)
{
if (remove(path) && errno != ENOENT)
return -1;
return 0;
}
#endif
#ifndef chardev
# define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min)))
#endif
#ifndef blkdev
# define blkdev(x,m,maj,min) mknod((x), S_IFBLK|(m), makedev((maj),(min)))
#endif
#ifndef S_ISEXEC
# define S_ISEXEC(m) (((m) & S_IXUSR) == S_IXUSR)
#endif
/* Unline isset(), setbit() et al, these work with integers/shorts/longwords/etc. */
#ifndef ISCLR
#define ISCLR(word,bit) ((word & (1 << (bit)) ? 0 : 1)) /**< Is bit cleared in word? */
#endif
#ifndef ISSET
#define ISSET(word,bit) ((word & (1 << (bit)) ? 1 : 0)) /**< Is bit set in word? */
#endif
#ifndef ISOTHER
#define ISOTHER(word,bit) ((word & ~(1 << (bit)) ? 1 : 0)) /**< Is any other bit set? */
#endif
#ifndef SETBIT
#define SETBIT(word,bit) (word |= (1 << (bit))) /**< Set bit in word. */
#endif
#ifndef CLRBIT
#define CLRBIT(word,bit) (word &= ~(1 << (bit))) /**< Clear bit in word. */
#endif
/* From The Practice of Programming, by Kernighan and Pike */
#ifndef NELEMS
#define NELEMS(array) (sizeof(array) / sizeof(array[0])) /**< Number of elements in array. */
#endif
/**
* Does directory end with a slash?
* @param dir Path string to check.
*
* @returns @c TRUE(1) or @c FALSE(0)
*/
static inline int fisslashdir(const char *dir)
{
if (!dir)
return 0;
if (strlen(dir) > 0)
return dir[strlen(dir) - 1] == '/';
return 0;
}
/* Compat */
#define copy_filep(src, dst) fcopyfile(src, dst)
#define pidfile_read_pid(file) pidfile_read(file)
#define signal_pidfile(file, signo) pidfile_signal(file, signo)
#endif /* LIBITE_LITE_H_ */
#ifdef __cplusplus
}
#endif
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+115
View File
@@ -0,0 +1,115 @@
/* mkpath() -- Create all components leading up to a given directory
*
* Copyright (c) 2013-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file makepath.c
* @author Joachim Wiberg
* @date 2013-2021
* @copyright ISC License
*/
#include <errno.h>
#include <libgen.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "lite.h"
/**
* makepath() but takes a mode_t argument.
* @param dir Directory to created, relative or absolute
* @param mode A &mode_t mode to create @a dir with
*
* @returns POSIX OK(0) on success, otherwise -1 with @a errno set.
*/
int mkpath(const char *dir, mode_t mode)
{
struct stat sb;
if (!dir) {
errno = EINVAL;
return -1;
}
if (!stat(dir, &sb))
return 0;
mkpath(dirname(strdupa(dir)), mode);
return mkdir(dir, mode);
}
/**
* Formatted version of mkpath().
* @param mode A mode_t mode to create directories with
* @param fmt Formatted string to be composed into a pathname
*
* @note Notice the swapped arguments, compared to mkpath()!
*
* @returns POSIX OK(0) on success, otherwise -1 with @a errno set.
*/
int fmkpath(mode_t mode, const char *fmt, ...)
{
va_list ap;
char *path;
int len;
va_start(ap, fmt);
len = vsnprintf(NULL, 0, fmt, ap);
va_end(ap);
path = alloca(len + 1);
if (!path) {
errno = ENOMEM;
return -1;
}
va_start(ap, fmt);
len = vsnprintf(path, len + 1, fmt, ap);
va_end(ap);
return mkpath(path, mode);
}
/**
* Create all components of the specified directory.
* @param dir Directory to create.
*
* @note It is strongly recommended to use mkpath() over this function
* since it has the @a mode argument while this function default to
* 0777, which in most cases is insecure.
*
* @returns POSIX OK (0) on success, otherwise -1 and @a errno set
* appropriately.
*
* @exception EINVAL on bad argument, or
* @exception ENOMEM when it fails allocating temporary memory.
*
* For other error codes see the mkdir(2) syscall description.
*/
int makepath(const char *dir)
{
return mkpath(dir, 0777);
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+61 -10
View File
@@ -1,3 +1,4 @@
/* Updated by troglobit for libite/finit/uftpd projects 2016/07/04 */
/* $OpenBSD: pidfile.c,v 1.11 2015/06/03 02:24:36 millert Exp $ */
/* $NetBSD: pidfile.c,v 1.4 2001/02/19 22:43:42 cgd Exp $ */
@@ -30,38 +31,78 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file pidfile.c
* @author NetBSD Foundation Inc.
* @date 1999
* @copyright 2-clause BSD License
*/
#include <sys/stat.h> /* utimensat() */
#include <sys/time.h> /* utimensat() on *BSD */
#include <sys/types.h>
#include <errno.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static char *pidfile_path;
static pid_t pidfile_pid;
#ifndef pidfile
static char *pidfile_path = NULL;
static pid_t pidfile_pid = 0;
static void pidfile_cleanup(void);
const char *__pidfile_path = _PATH_VARRUN; /* Note: includes trailing slash '/' */
const char *__pidfile_name = NULL;
extern char *__progname;
int
pidfile(const char *basename)
/**
* Create or update mtime of process PID file.
* @param basename Program name, or @c NULL, may start with '/'
*
* This function is intended to be used by UNIX daemons to save the PID of the main process
* responsible for handling signals. If @p basename is @c NULL the implicit @a __progname
* variable from the C-library is used. The @p basename may also start with '/', in which
* case it is interpreted as the absolute path to the PID file.
*
* @returns POSIX OK(0) on success, otherwise non-zero on error.
*/
int pidfile(const char *basename)
{
int save_errno;
int atexit_already;
pid_t pid;
FILE *f;
if (basename == NULL)
basename = __progname;
pid = getpid();
atexit_already = 0;
if (pidfile_path != NULL) {
if (!access(pidfile_path, R_OK) && pid == pidfile_pid) {
utimensat(0, pidfile_path, NULL, 0);
return (0);
}
free(pidfile_path);
pidfile_path = NULL;
__pidfile_name = NULL;
atexit_already = 1;
}
/* _PATH_VARRUN includes trailing / */
if (asprintf(&pidfile_path, "%s%s.pid", _PATH_VARRUN, basename) == -1)
return (-1);
if (basename[0] != '/') {
size_t len = strlen(__pidfile_path);
int slash = __pidfile_path[len > 0 ? len - 1 : 0] != '/';
if (asprintf(&pidfile_path, "%s%s%s.pid", __pidfile_path, slash ? "/" : "", basename) == -1)
return (-1);
} else {
if (asprintf(&pidfile_path, "%s", basename) == -1)
return (-1);
}
if ((f = fopen(pidfile_path, "w")) == NULL) {
save_errno = errno;
@@ -71,7 +112,6 @@ pidfile(const char *basename)
return (-1);
}
pid = getpid();
if (fprintf(f, "%ld\n", (long)pid) <= 0 || fflush(f) != 0) {
save_errno = errno;
(void) fclose(f);
@@ -82,6 +122,14 @@ pidfile(const char *basename)
return (-1);
}
(void) fclose(f);
__pidfile_name = pidfile_path;
/*
* LITE extension, no need to set up another atexit() handler
* if user only called us to update the mtime of the PID file
*/
if (atexit_already)
return (0);
pidfile_pid = pid;
if (atexit(pidfile_cleanup) < 0) {
@@ -100,7 +148,10 @@ pidfile(const char *basename)
static void
pidfile_cleanup(void)
{
if (pidfile_path != NULL && pidfile_pid == getpid())
if (pidfile_path != NULL && pidfile_pid == getpid()) {
(void) unlink(pidfile_path);
free(pidfile_path);
pidfile_path = NULL;
}
}
#endif
+135
View File
@@ -0,0 +1,135 @@
/* Functions for dealing with PID files (client side)
*
* Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file pidfilefn.c
* @author Joachim Wiberg
* @date 2009-2021
* @copyright ISC License
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
extern char *chomp(char *str);
/**
* Reads a PID value from a pidfile.
* @param pidfile File containing PID, usually in @c /var/run/PROCNAME.pid
*
* This function takes a @p pidfile and returns the PID found therein.
*
* @returns On invalid @p pidfile, -1 with @a errno set. If the @p
* pidfile is empty, or when its contents cannot be translated, this
* function returns zero (0), on success this function returns a PID
* value greater than one.
*
* @note PID 1 is reserved for the system init process.
*
* @exception EINVAL on invalid @p pidfile, or
* @exception ENOENT when @p pidfile does not exist.
*/
pid_t pidfile_read(const char *pidfile)
{
int pid = 0;
char buf[16];
FILE *fp;
if (!pidfile) {
errno = EINVAL;
return -1;
}
fp = fopen(pidfile, "r");
if (!fp)
return -1;
if (fgets(buf, sizeof(buf), fp)) {
char *ptr = chomp(buf);
if (ptr) {
errno = 0;
pid = strtoul(ptr, NULL, 0);
if (errno)
pid = 0; /* Failed conversion. */
}
}
fclose(fp);
return pid;
}
/**
* Poll for the existence of a pidfile and return PID.
* @param pidfile Path to pidfile to poll for
*
* This function polls for the pidfile at @p pidfile for at most 5
* seconds before timing out. If the file is created within that time
* span the file is read and its PID contents returned.
*
* @returns The PID read from @p pidfile, or zero on timeout.
*/
pid_t pidfile_poll(const char *pidfile)
{
pid_t pid = 0;
int tries = 0;
/* Timeout = 100 * 50ms = 5s */
while ((pid = pidfile_read(pidfile)) <= 0 && tries++ < 100)
usleep(50000); /* Wait 50ms between retries */
if (pid < 0)
pid = 0;
return pid;
}
/**
* Send signal to a PID and cleanup pidfile afterwards.
* @param pidfile File containing PID, usually in @c /var/run/PROCNAME.pid
* @param signal Signal to send to PID found in @p pidfile.
*
* If @p signal is any of @c SIGTERM or @c SIGKILL, or if kill(2)
* returns -1, the @p pidfile is removed.
*
* @returns POSIX OK(0) on success, non-zero otherwise.
*/
int pidfile_signal(const char *pidfile, int signal)
{
int pid = -1, ret = -1;
pid = pidfile_read(pidfile);
if (pid <= 0)
return 1;
ret = kill(pid, signal);
if (!ret && signal == SIGKILL)
ret = remove(pidfile);
return ret;
}
/**
* Local Variables:
* compile-command: "make V=1 -f pidfilefn.mk"
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+63
View File
@@ -0,0 +1,63 @@
/* Formatted popen()
*
* Copyright (c) 2023 Tobias Waldekranz <tobias@waldekranz.com>
* Copyright (c) 2023 Joachim Wiberg <troglobit@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* 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 <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
/**
* Formatted pipe stream to or from a process
* @param type A popen() type, "r" or "w", can also include "e" for @c O_CLOEXEC.
* @param fmt Formatted string to be composed into a shell command line.
*
* This function is an extension to popen(), lessening the burden of
* first having to compose the filename from parts in a seprate buffer.
*
* @returns Upon successful completion, popenf() returns a FILE pointer.
* Otherwise, @c NULL is returned and @a errno is set to indicate the
* error.
*/
FILE *popenf(const char *type, const char *fmt, ...)
{
va_list ap;
char *cmd;
int len;
va_start(ap, fmt);
len = vsnprintf(NULL, 0, fmt, ap);
va_end(ap);
cmd = alloca(len + 1);
if (!cmd) {
errno = ENOMEM;
return NULL;
}
va_start(ap, fmt);
vsnprintf(cmd, len + 1, fmt, ap);
va_end(ap);
return popen(cmd, type);
}
+229
View File
@@ -0,0 +1,229 @@
/* Reading and writing values/strings to/from /proc and /sys style files
*
* Copyright (c) 2023 Tobias Waldekranz <tobias@waldekranz.com>
* Copyright (c) 2023 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file procval.c
* @author Joachim Wiberg
* @date 2023
* @copyright ISC License
*/
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include "lite.h"
/**
* Similar to readsnf() except it takes a @a va_list argument
* @param line Pointer to line buffer.
* @param len Size of line buffer.
* @param fmt Formatted string to be composed into a pathname.
* @param ap List of variable arguemnts from va_start().
*
* For details, see readsnf().
*
* @returns same as readsnf().
*/
char *vreadsnf(char *line, size_t len, const char *fmt, va_list ap)
{
va_list apc;
FILE *fp;
va_copy(apc, ap);
fp = vfopenf("r", fmt, apc);
va_end(apc);
if (!fp)
return NULL;
if (!fgets(line, len, fp)) {
fclose(fp);
return NULL;
}
fclose(fp);
return chomp(line);
}
/**
* Read first line from a file composed from fmt and optional args.
* @param line Pointer to line buffer.
* @param len Size of line buffer.
* @param fmt Formatted string to be composed into a pathname.
*
* @returns On success, this function returns the @p line read from the
* file, with any trailing '\n' chomp()ed out. On error, @c NULL.
*/
char *readsnf(char *line, size_t len, const char *fmt, ...)
{
va_list ap;
char *ln;
va_start(ap, fmt);
ln = vreadsnf(line, len, fmt, ap);
va_end(ap);
return ln;
}
/**
* Write a string buffer to a file composed from fmt and optional args.
* @param str Pointer to string buffer, may be multiple lines.
* @param mode An fopen() mode string, e.g. "w+".
* @param fmt Formatted string to be composed into a pathname.
*
* @returns result of operation, with @a errno set on error.
*/
int writesf(const char *str, const char *mode, const char *fmt, ...)
{
va_list ap;
FILE *fp;
va_start(ap, fmt);
fp = vfopenf(mode, fmt, ap);
va_end(ap);
if (!fp)
return -1;
fprintf(fp, "%s\n", str);
return fclose(fp);
}
/**
* Same as readllf() except it takes a @a va_list argument.
*/
int vreadllf(long long *value, const char *fmt, va_list ap)
{
char line[0x100];
if (!vreadsnf(line, sizeof(line), fmt, ap))
return -1;
errno = 0;
*value = strtoll(line, NULL, 0);
return errno ? -1 : 0;
}
/**
* Read 64-bit integer value from a file composed from fmt and optional args.
* @param value Pointer to where to store read 64-bit integer value.
* @param mode An fopen() mode string, e.g. "w+".
* @param fmt Formatted string to be composed into a pathname.
*
* @returns result of operation, with @a errno set on error.
*/
int readllf(long long *value, const char *fmt, ...)
{
va_list ap;
int rc;
va_start(ap, fmt);
rc = vreadllf(value, fmt, ap);
va_end(ap);
return rc;
}
/**
* Read integer value from a file composed from fmt and optional args.
* @param value Pointer to where to store read integer value.
* @param mode An fopen() mode string, e.g. "w+".
* @param fmt Formatted string to be composed into a pathname.
*
* @returns result of operation, with @a errno set on error.
*/
int readdf(int *value, const char *fmt, ...)
{
long long tmp;
va_list ap;
int rc;
va_start(ap, fmt);
rc = vreadllf(&tmp, fmt, ap);
va_end(ap);
if (rc)
return rc;
if (tmp < INT_MIN || tmp > INT_MAX) {
errno = ERANGE;
return -1;
}
*value = tmp;
return 0;
}
/**
* Write 64-bit integer value to a file composed from fmt and optional args.
* @param value 64-bit integer value to write.
* @param mode An fopen() mode string, e.g. "w+".
* @param fmt Formatted string to be composed into a pathname.
*
* @returns result of operation, with @a errno set on error.
*/
int writellf(long long value, const char *mode, const char *fmt, ...)
{
va_list ap;
FILE *fp;
va_start(ap, fmt);
fp = vfopenf(mode, fmt, ap);
va_end(ap);
if (!fp)
return -1;
fprintf(fp, "%lld\n", value);
return fclose(fp);
}
/**
* Write integer value to a file composed from fmt and optional args.
* @param value Integer value to write.
* @param mode An fopen() mode string, e.g. "w+".
* @param fmt Formatted string to be composed into a pathname.
*
* @returns result of operation, with @a errno set on error.
*/
int writedf(int value, const char *mode, const char *fmt, ...)
{
va_list ap;
FILE *fp;
va_start(ap, fmt);
fp = vfopenf(mode, fmt, ap);
va_end(ap);
if (!fp)
return -1;
fprintf(fp, "%d\n", value);
return fclose(fp);
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+19 -61
View File
@@ -1,6 +1,6 @@
/* Simple termios based progress bar
*
* Copyright (c) 2012-2015 Joachim Nilsson <troglobit@gmail.com>
* Copyright (c) 2012-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -15,6 +15,13 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file progress.c
* @author Joachim Wiberg
* @date 2012-2021
* @copyright ISC License
*/
#include <limits.h> /* INT_MAX */
#include <stdio.h>
#include <string.h>
@@ -40,21 +47,21 @@ static char spinner(char *style)
}
/**
* progress - Advanced ASCII progress bar with spinner
* @percent: Start first call with this set to 0, end with 100
* @max_width: Max width of progress bar, in total characters.
* Advanced ASCII progress bar with spinner
* @param percent Start first call with this set to 0, end with 100
* @param max_width Max width of progress bar, in total characters.
*
* This function draws an advanced ASCII progressbar at the current
* line. It always start from the first column.
*
* The progress bar will hide the cursor if started with @percent 0 and
* show it again at the end, when called with @percent 100.
* The progress bar will hide the cursor if started with @p percent 0
* and show it again at the end, when called with @p percent 100.
*
* While being called with the same percentage the spinner will spin,
* to show the user the process hasn't frozen.
*
* If the output TTY cannot interpret control characters, like \r, it is
* advised to instead used the progress_simple() function.
* If the output TTY cannot interpret control characters, like `\r`, it
* is advised to instead used the progress_simple() function.
*/
void progress(int percent, int max_width)
{
@@ -85,6 +92,10 @@ void progress(int percent, int max_width)
}
}
/**
* Alternative progress bar on systems where progress() doesn't work
* @param percent Start first call with this set to 0, end with 100
*/
void progress_simple(int percent)
{
static int last = 1;
@@ -114,61 +125,8 @@ void progress_simple(int percent)
}
}
#ifdef UNITTEST
#include <stdlib.h> /* atexit() */
#include <unistd.h> /* usleep() */
#define MAX_WIDTH 80
#define msleep(msec) usleep(msec * 1000)
static void bye(void)
{
showcursor();
}
static void testit(int fn, int percent)
{
if (fn)
progress(percent, MAX_WIDTH);
else
progress_simple(percent);
}
static void test(int fn)
{
int i, percent, block = 0, num = 85;
while (block < num) {
percent = block * 100 / num;
for (i = 0; i < 10; i++) {
testit(fn, percent);
msleep(5);
}
block++;
msleep(10);
}
testit(fn, 100);
}
int main(void)
{
atexit(bye);
hidecursor();
printf("\nAdvanced:\n");
test(1);
printf("\nSimple:\n");
test(0);
printf("\n");
return 0;
}
#endif /* UNITTEST */
/**
* Local Variables:
* compile-command: "make V=1 -f progress.mk"
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
+46 -147
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: queue.h,v 1.38 2013/07/03 15:05:21 fgsch Exp $ */
/* $OpenBSD: queue.h,v 1.43 2015/12/28 19:38:40 millert Exp $ */
/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
/*
@@ -32,12 +32,22 @@
* @(#)queue.h 8.5 (Berkeley) 8/20/94
*/
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef _SYS_QUEUE_H_
#define _SYS_QUEUE_H_
/*
* This file defines five types of data structures: singly-linked lists,
* lists, simple queues, tail queues, and circular queues.
/**
* @file queue.h
* @author The Regents of the University of California
* @date 1991, 1993
* @copyright 3-clause BSD License
*
* This file defines five types of data structures: singly-linked lists,
* lists, simple queues, tail queues and XOR simple queues.
*
*
* A singly-linked list is headed by a single forward pointer. The elements
@@ -57,7 +67,7 @@
* or after an existing element or at the head of the list. A list
* may only be traversed in the forward direction.
*
* A simple queue is headed by a pair of pointers, one the head of the
* A simple queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are singly
* linked to save space, so elements can only be removed from the
* head of the list. New elements can be added to the list before or after
@@ -71,13 +81,10 @@
* after an existing element, at the head of the list, or at the end of
* the list. A tail queue may be traversed in either direction.
*
* A circle queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or after
* an existing element, at the head of the list, or at the end of the list.
* A circle queue may be traversed in either direction, but has a more
* complex end of list detection.
* An XOR simple queue is used in the same way as a regular simple queue.
* The difference is that the head structure also includes a "cookie" that
* is XOR'd with the queue pointer (first, last or next) to generate the
* real pointer value.
*
* For details on the use of these macros, see the queue(3) manual page.
*/
@@ -95,15 +102,15 @@
struct name { \
struct type *slh_first; /* first element */ \
}
#define SLIST_HEAD_INITIALIZER(head) \
{ NULL }
#define SLIST_ENTRY(type) \
struct { \
struct type *sle_next; /* next element */ \
}
/*
* Singly-linked List access methods.
*/
@@ -157,8 +164,8 @@ struct { \
curelm = curelm->field.sle_next; \
curelm->field.sle_next = \
curelm->field.sle_next->field.sle_next; \
_Q_INVALIDATE((elm)->field.sle_next); \
} \
_Q_INVALIDATE((elm)->field.sle_next); \
} while (0)
/*
@@ -179,7 +186,7 @@ struct { \
}
/*
* List access methods
* List access methods.
*/
#define LIST_FIRST(head) ((head)->lh_first)
#define LIST_END(head) NULL
@@ -316,6 +323,14 @@ struct { \
(head)->sqh_last = &(elm)->field.sqe_next; \
} while (0)
#define SIMPLEQ_CONCAT(head1, head2) do { \
if (!SIMPLEQ_EMPTY((head2))) { \
*(head1)->sqh_last = (head2)->sqh_first; \
(head1)->sqh_last = (head2)->sqh_last; \
SIMPLEQ_INIT((head2)); \
} \
} while (0)
/*
* XOR Simple queue definitions.
*/
@@ -395,7 +410,7 @@ struct { \
XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \
} while (0)
/*
* Tail queue definitions.
*/
@@ -414,8 +429,8 @@ struct { \
struct type **tqe_prev; /* address of previous next element */ \
}
/*
* tail queue access methods
/*
* Tail queue access methods.
*/
#define TAILQ_FIRST(head) ((head)->tqh_first)
#define TAILQ_END(head) NULL
@@ -516,133 +531,17 @@ struct { \
_Q_INVALIDATE((elm)->field.tqe_next); \
} while (0)
/*
* Circular queue definitions.
*/
#define CIRCLEQ_HEAD(name, type) \
struct name { \
struct type *cqh_first; /* first element */ \
struct type *cqh_last; /* last element */ \
}
#define CIRCLEQ_HEAD_INITIALIZER(head) \
{ CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
#define CIRCLEQ_ENTRY(type) \
struct { \
struct type *cqe_next; /* next element */ \
struct type *cqe_prev; /* previous element */ \
}
/*
* Circular queue access methods
*/
#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
#define CIRCLEQ_LAST(head) ((head)->cqh_last)
#define CIRCLEQ_END(head) ((void *)(head))
#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
#define CIRCLEQ_EMPTY(head) \
(CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))
#define CIRCLEQ_FOREACH(var, head, field) \
for((var) = CIRCLEQ_FIRST(head); \
(var) != CIRCLEQ_END(head); \
(var) = CIRCLEQ_NEXT(var, field))
#define CIRCLEQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = CIRCLEQ_FIRST(head); \
(var) != CIRCLEQ_END(head) && \
((tvar) = CIRCLEQ_NEXT(var, field), 1); \
(var) = (tvar))
#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
for((var) = CIRCLEQ_LAST(head); \
(var) != CIRCLEQ_END(head); \
(var) = CIRCLEQ_PREV(var, field))
#define CIRCLEQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
for ((var) = CIRCLEQ_LAST(head, headname); \
(var) != CIRCLEQ_END(head) && \
((tvar) = CIRCLEQ_PREV(var, headname, field), 1); \
(var) = (tvar))
/*
* Circular queue functions.
*/
#define CIRCLEQ_INIT(head) do { \
(head)->cqh_first = CIRCLEQ_END(head); \
(head)->cqh_last = CIRCLEQ_END(head); \
} while (0)
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
(elm)->field.cqe_prev = (listelm); \
if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \
(head)->cqh_last = (elm); \
else \
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
(listelm)->field.cqe_next = (elm); \
} while (0)
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
(elm)->field.cqe_next = (listelm); \
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \
(head)->cqh_first = (elm); \
else \
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
(listelm)->field.cqe_prev = (elm); \
} while (0)
#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
(elm)->field.cqe_next = (head)->cqh_first; \
(elm)->field.cqe_prev = CIRCLEQ_END(head); \
if ((head)->cqh_last == CIRCLEQ_END(head)) \
(head)->cqh_last = (elm); \
else \
(head)->cqh_first->field.cqe_prev = (elm); \
(head)->cqh_first = (elm); \
} while (0)
#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.cqe_next = CIRCLEQ_END(head); \
(elm)->field.cqe_prev = (head)->cqh_last; \
if ((head)->cqh_first == CIRCLEQ_END(head)) \
(head)->cqh_first = (elm); \
else \
(head)->cqh_last->field.cqe_next = (elm); \
(head)->cqh_last = (elm); \
} while (0)
#define CIRCLEQ_REMOVE(head, elm, field) do { \
if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \
(head)->cqh_last = (elm)->field.cqe_prev; \
else \
(elm)->field.cqe_next->field.cqe_prev = \
(elm)->field.cqe_prev; \
if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \
(head)->cqh_first = (elm)->field.cqe_next; \
else \
(elm)->field.cqe_prev->field.cqe_next = \
(elm)->field.cqe_next; \
_Q_INVALIDATE((elm)->field.cqe_prev); \
_Q_INVALIDATE((elm)->field.cqe_next); \
} while (0)
#define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
CIRCLEQ_END(head)) \
(head)->cqh_last = (elm2); \
else \
(elm2)->field.cqe_next->field.cqe_prev = (elm2); \
if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
CIRCLEQ_END(head)) \
(head)->cqh_first = (elm2); \
else \
(elm2)->field.cqe_prev->field.cqe_next = (elm2); \
_Q_INVALIDATE((elm)->field.cqe_prev); \
_Q_INVALIDATE((elm)->field.cqe_next); \
#define TAILQ_CONCAT(head1, head2, field) do { \
if (!TAILQ_EMPTY(head2)) { \
*(head1)->tqh_last = (head2)->tqh_first; \
(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
(head1)->tqh_last = (head2)->tqh_last; \
TAILQ_INIT((head2)); \
} \
} while (0)
#endif /* !_SYS_QUEUE_H_ */
#ifdef __cplusplus
}
#endif
+52
View File
@@ -0,0 +1,52 @@
/* $OpenBSD: reallocarray.c,v 1.2 2014/12/08 03:45:00 bcook Exp $ */
/*
* Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
*
* Permission to use, copy, modify, and 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.
*/
/**
* @file reallocarray.c
* @author Otto Moerbeek
* @date 2008
* @copyright ISC License
*/
#include <sys/types.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
/*
* This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
* if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
*/
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
/**
* Similar to realloc() but for an array of items, like calloc()
* @param optr Pointer to old (current) array
* @param nmemb Number of elements
* @param size Size of each element, in bytes
*
* @returns A pointer to the new array, or @c NULL on error.
*/
void *reallocarray(void *optr, size_t nmemb, size_t size)
{
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
nmemb > 0 && SIZE_MAX / nmemb < size) {
errno = ENOMEM;
return NULL;
}
return realloc(optr, size * nmemb);
}
+246
View File
@@ -0,0 +1,246 @@
/* Micro "rsync" implementation.
*
* Copyright (c) 2011-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file rsync.c
* @author Joachim Wiberg
* @date 2011-2021
* @copyright ISC License
*/
#include <errno.h>
#include <fcntl.h> /* AT_* macros */
#include <stdlib.h> /* NULL, free() */
#include <string.h> /* strlen() */
#include <strings.h> /* rindex() */
#include <stdio.h>
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
#include <sys/stat.h>
#include <sys/types.h>
#include "lite.h"
static int copy(char *src, char *dst, int opt);
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 set_mtime(char *fn, struct stat *st);
/**
* Synchronize contents and optionally remove non-existing backups
* @param src Source directory
* @param dst Destination directory
* @param opt An option mask of ::LITE_FOPT_RSYNC_DELETE, ::LITE_FOPT_KEEP_MTIME
* @param filter Optional filtering function for source directory.
*
* This is a miniature implementation of the famous rsync for local use
* only. In fact, it is not even a true rsync since it copies all files
* from @p src to @p dst. The ::LITE_FOPT_RSYNC_DELETE @p opt flag is
* useful for creating backups, when set all files removed from src
* since last backup are pruned from the destination (backup) directory.
*
* The @p opt parameter to rsync() is an option mask for the most common
* rsync(1) options. Previously this argument was called @p delete and
* to maintain backwards compatibility the value 1 is reserved:
*
* %LITE_FOPT_RSYNC_DELETE: Prune files from @p dst that no longer exist in @p src.
* %LITE_FOPT_KEEP_MTIME: Preserve modification time
*
* The filter callback, @p 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:
* POSIX OK(0), or non-zero with @a errno set on error.
*/
int rsync(char *src, char *dst, int opt, int (*filter)(const char *file))
{
char source[256];
char dest[256];
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. */
struct stat st;
errno = 0;
if (stat(dst, &st) && fisslashdir(dst))
makedir(dst, 0755);
if (!fisdir(src)) {
if (!fexist(src))
return 1;
if (copy(src, dst, keep_mtim))
return 1;
return 0;
}
/* Copy dir as well? */
if (!fisslashdir(src)) {
char *ptr = rindex(src, '/');
if (!ptr)
ptr = src;
else
ptr++;
if (stat(src, &st))
return 1;
if (mdir(dest, sizeof(dest), dst, ptr, &st))
return 1;
dst = dest;
do_mtim = keep_mtim;
}
num = dir(src, "", filter, &files, 0);
for (i = 0; i < num; i++) {
/* Recursively copy sub-directries */
snprintf(source, sizeof(source), "%s%s%s", src, fisslashdir(src) ? "" : "/", files[i]);
if (fisdir(source)) {
char dst2[256];
struct stat sb;
strcat(source, "/");
if (stat(source, &sb)) {
result++;
continue;
}
if (mdir(dst2, sizeof(dst2), dst, files[i], &sb)) {
result++;
continue;
}
rsync(source, dst2, opt, filter);
if (keep_mtim)
set_mtime(dst2, &sb);
continue; /* Next file/dir in @src to copy... */
}
if (copy(source, dst, keep_mtim))
result++;
}
if (do_mtim)
set_mtime(dest, &st);
/* We ignore any errors from the pruning, that phase albeit useful is only
* cosmetic. --Jocke 2011-03-24 */
if (delete)
prune(dst, files, num);
if (num) {
for (i = 0; i < num; i++)
free(files[i]);
free(files);
}
return result;
}
static int copy(char *src, char *dst, int opt)
{
copyfile(src, dst, 0, opt | LITE_FOPT_COPYFILE_SYM);
if (errno) {
if (errno != EEXIST)
return 1;
errno = 0;
}
return 0;
}
/* Creates dir/name @mode ... skipping / if dir already ends so. */
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);
if (mkdir(buf, st->st_mode)) {
if (EEXIST != errno)
return 1;
errno = 0;
}
return 0;
}
static int find(char *file, char **files, int num)
{
int n;
for (n = 0; n < num; n++)
if (!strncmp (files[n], file, MAX(strlen(files[n]), strlen(file))))
return 1;
return 0;
}
/* Prune old files, no longer existing on source, from destination directory. */
static int prune(char *dst, char **new_files, int new_num)
{
int num, result = 0;
char **files;
num = dir(dst, "", NULL, &files, 0);
if (num) {
int i;
for (i = 0; i < num; i++) {
if (!find(files[i], new_files, new_num)) {
char *name;
size_t len = strlen(files[i]) + 2 + strlen(dst);
name = malloc(len);
if (name) {
snprintf(name, len, "%s%s%s", dst, fisslashdir(dst) ? "" : "/", files[i]);
if (remove(name))
result++;
free(name);
}
}
free(files[i]);
}
free(files);
}
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:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+93
View File
@@ -0,0 +1,93 @@
/* Run a command in the background: fork() + usleep() + execvp()
*
* Copyright (c) 2023 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file runbg.c
* @author Joachim Wiberg
* @date 2023
* @copyright ISC License
*/
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
/**
* Run command in the background
* @param cmd NULL terminated list of command and optional arguments
* @param delay Microseconds after fork() to wait before calling cmd
*
* This function forks to run the given command @p cmd in the background.
* To ensure there are no lingering zombies the function actuall forks
* twice, and also calls setsid(), before it calls usleep() with the @p
* delay argument. The command @p cmd is handed over to execvp().
*
* Since it runs in the background it is not possible to get the return
* code of the command.
*
* @returns on successful (first) fork(), this function returns POSIX
* OK(0), otherwise -1 and @a errno is set to indicate the error.
*/
int runbg(char *const cmd[], int delay)
{
int pid = fork();
int rc;
if (!pid) {
int fd, maxfd;
if (setsid() == -1)
_exit(errno);
/* reparent to init */
pid = fork();
if (pid == -1)
_exit(errno);
if (pid > 0)
_exit(0);
maxfd = sysconf(_SC_OPEN_MAX);
if (maxfd == -1)
maxfd = 8192;
for (fd = 0; fd < maxfd; fd++)
close(fd);
usleep(delay);
_exit(execvp(cmd[0], cmd));
}
if (pid == -1)
return -1;
if (waitpid(pid, &rc, 0) == -1)
return -1;
if (WIFEXITED(rc)) {
errno = WEXITSTATUS(rc);
if (errno)
rc = -1;
else
rc = 0;
} else if (WIFSIGNALED(rc)) {
errno = EINTR;
rc = -1;
} else
rc = -1;
return rc;
}
+74
View File
@@ -0,0 +1,74 @@
/* ==========================================================================
* strdupa.h - Re-implementation of glibc strdupa.
* --------------------------------------------------------------------------
* Copyright (c) 2009 William Ahern
*
* 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.
* ==========================================================================
*/
/**
* @file strdupa.h
* @author William Ahern
* @date 2009
* @copyright MIT License
*/
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef LIBITE_STRDUPA_H
#define LIBITE_STRDUPA_H
#if !defined(HAVE_STRDUPA)
#if defined(strdupa)
#define HAVE_STRDUPA 1
#endif
#endif
#if !HAVE_STRDUPA
#if defined(__GNUC__)
#include <stddef.h> /* size_t */
#include <string.h> /* memcpy(3) strlen(3) */
/**
* Duplicate string on stack.
* @param src string to duplicate
* @returns the result of memcpy(3)
*/
#define strdupa(src) (__extension__ ({ \
size_t len_ = strlen(src); \
char *dst_ = __builtin_alloca(len_ + 1); \
dst_[len_] = '\0'; \
(char *)memcpy(dst_, src, len_); \
}))
#else /* If not GCC, e.g. Clang */
#error strdupa() may use an unsupported GNU C API, please forward any fix to maintainer, cheers!
#endif /* __GNUC__ */
#endif /* !HAVE_STRDUPA */
#endif /* LIBITE_STRDUPA_H */
#ifdef __cplusplus
}
#endif
+71
View File
@@ -0,0 +1,71 @@
/* $OpenBSD: strlcat.c,v 1.15 2015/03/02 21:41:08 millert Exp $ */
/*
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and 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.
*/
/**
* @file strlcat.c
* @author Todd C. Miller
* @date 1998, 2015
* @copyright ISC License
*/
#include <sys/types.h>
#include <string.h>
#ifndef strlcat
/**
* Safe version of strncat() from OpenBSD
* @param dst Destination string
* @param src Source string
* @param dsize Total maximum size of @p dst
*
* Appends @p src to string @p dst of size @p dsize (unlike strncat(),
* @p dsize is the full size of @p dst, not space left). At most
* dsize-1 characters will be copied. Always NUL terminates (unless
* dsize <= strlen(dst)).
*
* @returns strlen(src) + MIN(dsize, strlen(initial dst)).
* If retval >= dsize, truncation occurred.
*/
size_t
strlcat(char *dst, const char *src, size_t dsize)
{
const char *odst = dst;
const char *osrc = src;
size_t n = dsize;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end. */
while (n-- != 0 && *dst != '\0')
dst++;
dlen = dst - odst;
n = dsize - dlen;
if (n-- == 0)
return(dlen + strlen(src));
while (*src != '\0') {
if (n != 0) {
*dst++ = *src;
n--;
}
src++;
}
*dst = '\0';
return(dlen + (src - osrc)); /* count does not include NUL */
}
#endif
+67
View File
@@ -0,0 +1,67 @@
/* $OpenBSD: strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */
/*
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and 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.
*/
/**
* @file strlcpy.c
* @author Todd C. Miller
* @date 1998, 2015
* @copyright ISC License
*/
#include <sys/types.h>
#include <string.h>
#ifndef strlcpy
/**
* Safe version of strncpy() from OpenBSD
* @param dst Destination string
* @param src Source string
* @param dsize Total maximum size of @p dst
*
* This function copies string @p src to buffer @p dst of size @p dsize
* bytes. At most dsize-1 chars will be copied. Always NUL terminates
* (unless dsize==0).
*
* @returns strlen(src); if retval >= dsize, truncation occurred.
*/
size_t
strlcpy(char *dst, const char *src, size_t dsize)
{
const char *osrc = src;
size_t nleft = dsize;
/* Copy as many bytes as will fit. */
if (nleft != 0) {
while (--nleft != 0) {
if ((*dst++ = *src++) == '\0')
break;
}
}
/* Not enough room in dst, add NUL and traverse rest of src. */
if (nleft == 0) {
if (dsize != 0)
*dst = '\0'; /* NUL-terminate dst */
while (*src++)
;
}
return(src - osrc - 1); /* count does not include NUL */
}
#endif
+150
View File
@@ -0,0 +1,150 @@
/* Collection of frog DNA
*
* Copyright (c) 2008-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* 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.
*/
/**
* @file strlite.h
* @author Joachim Wiberg
* @date 2008-2021
* @copyright MIT License
*/
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef LIBITE_STRING_H_
#define LIBITE_STRING_H_
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, INT32_MAX, etc. */
#include <string.h>
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
#include "strdupa.h"
#include "strndupa.h"
#include "strnlen.h"
#ifndef min
/** Geneirc min() macro, if a < b => a, else b */
#define min(a,b) \
({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; \
})
#endif
#ifndef max
/** Geneirc max() macro, if a > b => a, else b */
#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
size_t strlcpy (char *dst, const char *src, size_t siz);
#endif
#ifndef strlcat
size_t strlcat (char *dst, const char *src, size_t siz);
#endif
#ifndef strtonum
long long strtonum (const char *numstr, long long minval, long long maxval, const char **errstrp);
#endif
char *strtrim (char *str);
/**
* Convert string to natural number (0-2147483647)
* @param str string to convert to number.
* @returns -1 on error.
*/
static inline int atonum(const char *str)
{
int val = -1;
const char *errstr;
if (str) {
val = strtonum(str, 0, INT32_MAX, &errstr);
if (errstr)
return -1;
}
return val;
}
/**
* Validate string, non NULL and not zero length
* @param str string to validate
* @returns @c TRUE(1) or @c FALSE(0).
*/
static inline int string_valid(const char *str)
{
return str && strlen(str);
}
/**
* Relaxed comparison, e.g., sys_string_match("small", "smaller") => TRUE
* @param a first string
* @param b second string
* @returns @c TRUE(1) or @c FALSE(0).
*/
static inline int string_match(const char *a, const char *b)
{
size_t min = MIN(strlen(a), strlen(b));
return !strncasecmp(a, b, min);
}
/**
* Strict comparison, e.g., sys_string_match("small", "smaller") => FALSE
* @param a first string
* @param b second string
* @returns @c TRUE(1) or @c FALSE(0).
*/
static inline int string_compare(const char *a, const char *b)
{
return strlen(a) == strlen(b) && !strcmp(a, b);
}
/**
* Strict comparison, like sys_string_compare(), but case insensitive,
* e.g., sys_string_match("small", "SmAlL") => TRUE
* @param a first string
* @param b second string
* @returns @c TRUE(1) or @c FALSE(0).
*/
static inline int string_case_compare(const char *a, const char *b)
{
return strlen(a) == strlen(b) && !strcasecmp(a, b);
}
#endif /* LIBITE_STRING_H_ */
#ifdef __cplusplus
}
#endif
+94
View File
@@ -0,0 +1,94 @@
/* Simple string matcher function, finds partial matches.
*
* Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file strmatch.c
* @author Joachim Wiberg
* @date 2009-2021
* @copyright ISC License
*/
#include <errno.h>
#include <string.h>
/**
* Finds matching strings from a finite list
* @param str String to look for
* @param list List of strings to search.
* @param num Number of entries in @p list.
*
* This function searches the @p list of strings for @p str. If a
* (partial) match is found it returns the index in the @p list.
*
* Very similar in function to strmatch(), but works for sets of strings
* that are not @c NUL 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;
}
/**
* Finds matching strings from a list
* @param str String to look for.
* @param list NUL terminated list of strings to search.
*
* This function searches the @p list of strings for @p str. If a
* (partial) match is found it returns the index in the @p list.
*
* Please note, the @p list MUST be terminated by a NUL element. If
* that is not possible, 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:
*/
+76
View File
@@ -0,0 +1,76 @@
/* ==========================================================================
* strndupa.h - Re-implementation of glibc strndupa.
* --------------------------------------------------------------------------
* Copyright (c) 2009 William Ahern
*
* 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.
* ==========================================================================
*/
/**
* @file strndupa.h
* @author William Ahern
* @date 2009
* @copyright MIT License
*/
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef LIBITE_STRNDUPA_H_
#define LIBITE_STRNDUPA_H_
#if !defined(HAVE_STRNDUPA)
#if defined(strndupa)
#define HAVE_STRNDUPA 1
#endif
#endif
#if !HAVE_STRNDUPA
#if defined(__GNUC__)
#include <stddef.h> /* size_t */
#include <string.h> /* memcpy(3) */
#include "strnlen.h"
/**
* Duplicate part of string on stack
* @param src string to duplicate
* @param lim number of bytes to dupliate
* @returns the result of memcpy(3)
*/
#define strndupa(src, lim) (__extension__ ({ \
size_t len_ = strnlen(src, lim); \
char *dst_ = __builtin_alloca(len_ + 1); \
dst_[len_] = '\0'; \
(char *)memcpy(dst_, src, len_); \
}))
#else /* If not GCC, e.g. Clang */
+#error strndupa() may use an unsupported GNU C API, please forward any fix to maintainer, cheers!
#endif /* __GNUC__ */
#endif /* !HAVE_STRNDUPA */
#endif /* LIBITE_STRNDUPA_H */
#ifdef __cplusplus
}
#endif
+65
View File
@@ -0,0 +1,65 @@
/* strnlen.h - Re-implementation of GLIBC strnlen()
*
* Copyright (c) 2016-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file strnlen.h
* @author Joachim Wiberg
* @date 2016-2021
* @copyright ISC License
*/
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef LIBITE_STRNLEN_H_
#define LIBITE_STRNLEN_H_
#if !defined(HAVE_STRNLEN)
#if defined(strnlen)
#define HAVE_STRNLEN 1
#endif
#endif
#if !HAVE_STRNLEN
#include <stddef.h> /* size_t */
#define strnlen(str, lim) xstrnlen(str, lim) /**< Wrapper for xstrnlen() */
/**
* Reimplementation of GLIBC strnlen()
* @param str string to return length of
* @param lim max number of bytes to read
* @returns length of @p str in bytes, but at most @lim bytes.
*/
static inline size_t xstrnlen(const char *str, size_t lim)
{
size_t i = 0;
while (i < lim && str[i])
i++;
return i;
}
#endif
#endif /* LIBITE_STRNLEN_H_ */
#ifdef __cplusplus
}
#endif
+112
View File
@@ -0,0 +1,112 @@
/* $OpenBSD: strtonum.c,v 1.7 2013/04/17 18:40:58 tedu Exp $ */
/*
* Copyright (c) 2004 Ted Unangst and Todd Miller
* All rights reserved.
*
* Permission to use, copy, modify, and 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.
*/
/**
* @file strtonum.c
* @author Ted Unangst
* @author Todd Miller
* @date 2004
* @copyright ISC License
*/
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#ifndef strtonum
#define INVALID 1 /**< internal */
#define TOOSMALL 2 /**< internal */
#define TOOLARGE 3 /**< internal */
#ifndef LLONG_MAX
# define LLONG_MAX 0x7fffffffffffffffLL /**< internal */
#endif
#ifndef LLONG_MIN
# define LLONG_MIN (-0x7fffffffffffffffLL - 1) /**< internal */
#endif
/**
* Reliably convert string value to an integer
* @param numstr String to convert to a number
* @param minval Lower bound to check number against
* @param maxval Upper bound to check number against
* @param errstrp Pointer to error string
*
* This function converts the string in @p numstr to a long long value.
* The function was designed to facilitate safe, robust programming and
* overcome the shortcomings of the atoi(3) and strtol(3) family of
* interfaces.
*
* The string may begin with an arbitrary amount of whitespace (as
* determined by isspace(3)) followed by a single optional ‘+’ or ‘-’
* sign.
*
* The remainder of the string is converted to a long long value
* according to base 10.
*
* The value obtained is then checked against the provided @p minval and
* @p maxval bounds. If @p errstrp is non-NULL, strtonum() stores an
* error string in @p *errstrp indicating the failure.
*
* @returns The result of the conversion, unless the value would exceed
* the provided bounds or is invalid. On error, 0 is returned, @a errno
* is set, and @p errstrp points to an error message. @p *errstr* is set
* to @c NULL on success; this fact can be used to differentiate a
* successful return of 0 from an error.
*/
long long
strtonum(const char *numstr, long long minval, long long maxval,
const char **errstrp)
{
long long ll = 0;
int error = 0;
char *ep;
struct errval {
const char *errstr;
int err;
} ev[4] = {
{ NULL, 0 },
{ "invalid", EINVAL },
{ "too small", ERANGE },
{ "too large", ERANGE },
};
ev[0].err = errno;
errno = 0;
if (minval > maxval) {
error = INVALID;
} else {
ll = strtoll(numstr, &ep, 10);
if (errno == EINVAL || numstr == ep || *ep != '\0')
error = INVALID;
else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
error = TOOSMALL;
else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
error = TOOLARGE;
}
if (errstrp != NULL)
*errstrp = ev[error].errstr;
errno = ev[error].err;
if (error)
ll = 0;
return (ll);
}
#endif
+77
View File
@@ -0,0 +1,77 @@
/* Trim a string from whitespace
*
* Copyright (c) 2014 Mattias Walström <lazzer@gmail.com>
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file strtrim.c
* @author Mattias Walström
* @author Joachim Wiberg
* @date 2014,2021
* @copyright ISC License
*/
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include "lite.h"
/**
* Strip leading and trailing whitespace from a string
* @param str The string to trim
*
* Trims a string from any leading and trailing white-space, returns the
* trimmed result in the same buffer.
*
* @returns If @p str is a valid, non-NULL string this function returns
* the same string stripped from whitespace. This function only returns
* @c NULL if @p str itself is @c NULL.
*/
char *strtrim(char *str)
{
char *start, *end;
if (!str) {
errno = EINVAL;
return NULL;
}
start = str;
while (isspace(*start))
start++;
if (*start == 0) {
str[0] = 0;
return str;
}
end = start + strlen(start) - 1;
while (end > start && isspace(*end))
end--;
*(++end) = 0;
memmove(str, start, end - start + 1);
return str;
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+85
View File
@@ -0,0 +1,85 @@
/* Formatted system() which returns actual return status of command
*
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file systemf.c
* @author Joachim Wiberg
* @date 2021
* @copyright ISC License
*/
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
/**
* Like system(), but takes a formatted string as argument.
* @param fmt printf style format list to command to run
*
* This system() wrapper greatly simplifies operations that usually
* consist of composing a command from parts into a dynamic buffer
* before calling it. The return value from system() is also parsed,
* checking for proper exit and signals.
*
* @returns If the command exits normally, the return code of the command
* is returned. Otherwise, if the command is signalled, the return code
* is -1 and @a errno is set to @c EINTR.
*/
int systemf(const char *fmt, ...)
{
va_list ap;
char *cmd;
int len;
int rc;
va_start(ap, fmt);
len = vsnprintf(NULL, 0, fmt, ap);
va_end(ap);
cmd = alloca(++len);
if (!cmd) {
errno = ENOMEM;
return -1;
}
va_start(ap, fmt);
vsnprintf(cmd, len, fmt, ap);
va_end(ap);
rc = system(cmd);
if (rc == -1)
return -1;
if (WIFEXITED(rc)) {
errno = 0;
rc = WEXITSTATUS(rc);
} else if (WIFSIGNALED(rc)) {
errno = EINTR;
rc = -1;
}
return rc;
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+317
View File
@@ -0,0 +1,317 @@
/* Poor mans telnet expect in C.
*
* Copyright (c) 2010-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file telnet.c
* @author Joachim Wiberg
* @date 2010-2021
* @copyright ISC License
*/
#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
/** @private for internal use only */
struct sdbuf {
int sd;
char *buf;
};
/**
* Open telnet connection to addr:port and connect.
* @param addr Integer encoded IPv4 address in network byte order
* @param port Internet port number in network byte order
*
* @returns An @ref sdbuf_t socket buffer context.
*/
sdbuf_t *telnet_open(int addr, short port)
{
struct sockaddr_in *sin;
struct sockaddr s;
sdbuf_t *ctx;
int saved;
int retries = 10;
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;
// perror ("Failed creating socket");
free(ctx->buf);
free(ctx);
errno = saved;
return NULL;
}
retry:
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))) {
if (ETIMEDOUT == errno && retries-- > 0) {
sleep(1);
goto retry;
}
saved = errno;
// perror ("Cannot connect to telnet daemon");
telnet_close(ctx);
errno = saved;
return NULL;
}
return ctx;
}
/**
* Close a telnet session previously opened with telnet_open()
* @param ctx An @ref sdbuf_t socket buffer context
*
* @returns Always returns POSIX OK(0).
*/
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;
}
}
/**
* Poor man's telnet expect
* @param ctx Telnet session context from telnet_open()
* @param script @c NULL terminated list of expect and response strings
* @param output Optional output from session
*
* Issues @p script sequence on telnet session specified in @p ctx, with
* optional @p output from session.
*
* The @p 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 @c 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;
}
/**
* Very simple expect-like implementation for telnet.
* @param addr Integer encoded IPv4 address, in network byte order, use htonl().
* @param port Internet port to connect to, in network byte order, use htons().
* @param script Expect like script of paired 'expect', 'response' strings.
* @param output A FILE pointer to a tempfile() for output from the last command.
*
* This is a very simple expect-like implementation for querying and
* operating daemons remotely over telnet.
*
* The @p script is a query-response type of list of strings leading up
* to a final command, which output is then written to the given @p
* output file.
*
* @returns POSIX OK(0), or non-zero with @a 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:
*/
+38 -29
View File
@@ -1,6 +1,6 @@
/* A secure tmpfile() replacement.
*
* Copyright (c) 2015 Joachim Nilsson <troglobit@gmail.com>
* Copyright (c) 2015-2021 Joachim Wiberg <troglobit@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -15,62 +15,71 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* @file tempfile.c
* @author Joachim Wiberg
* @date 2015-2021
* @copyright ISC License
*/
#include <errno.h>
#include <paths.h>
#include <fcntl.h> /* O_TMPFILE requires -D_GNU_SOURCE */
#include <linux/version.h>
#include <stdlib.h> /* mkstemp() */
#include <stdio.h> /* fdopen() */
#include <stdlib.h> /* mkostemp() */
#include <sys/stat.h> /* umask() */
#ifndef O_TMPFILE /* Too old GLIBC or kernel */
#warning O_TMPFILE missing on your system, tempfile() may not work!
#define O_TMPFILE 020200000 /* Define and let it fail at runtime */
#endif
static FILE *fallback(void)
{
char nm[15] = _PATH_TMP "XXXXXXXX";
int fd;
fd = mkostemp(nm, O_CLOEXEC);
if (-1 == fd)
return NULL;
return fdopen(fd, "w+");
}
/**
* tempfile - A secure tmpfile() replacement
* A secure tmpfile() replacement
*
* This is the secure replacement for tmpfile() that does not exist in
* GLIBC. The function uses the Linux specific %O_TMPFILE and %O_EXCL
* for security. When the %FILE is fclose()'ed the file contents is
* lost. The file is hidden in the %_PATH_TMP directory on the system.
* GLIBC. It uses the Linux specific @c O_TMPFILE and @c O_EXCL to hide
* the filename. When the @c FILE is fclose()'ed, the file contents is
* lost. The file is hidden in the @c _PATH_TMP ("/tmp") directory in
* the system.
*
* This function requires Linux 3.11, or later, due to %O_TMPFILE.
* This function requires Linux 3.11, or later, due to @c O_TMPFILE.
* Not all file systems support hidden inodes, in which case this
* function defaults to call tmpfile() as a fallback.
*
* Returns:
* An open %FILE pointer, or %NULL on error.
* @returns An open @c FILE pointer, or @c NULL on error.
*/
FILE *tempfile(void)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)
#ifdef O_TMPFILE /* Only on Linux, with fairly recent (G)LIBC */
int fd;
mode_t oldmask;
oldmask = umask(0077);
fd = open(_PATH_TMP, O_TMPFILE | O_RDWR | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR);
umask(oldmask);
if (-1 == fd)
if (-1 == fd) {
if (errno == EOPNOTSUPP)
return fallback();
return NULL;
}
return fdopen(fd, "rw");
return fdopen(fd, "w+");
#else
#warning Too old kernel, reverting to wrap unsafe tmpfile() ...
return tmpfile();
return fallback();
#endif
}
#ifdef UNITTEST
int main(void)
{
FILE *fp = tempfile(); system("ls -lrt "
_PATH_TMP " | tail -10"); return fclose(fp);
}
#endif
/**
* Local Variables:
* compile-command: "make V=1 -f tempfile.mk"
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
Loaded 100 of 148 files, more files were not shown because too many files have changed in this diff. Show more