Commit Graph
64 Commits
Author SHA1 Message Date
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 59d1f0d60c Update .gitignore files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-22 13:57:39 +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 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 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 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 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 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 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 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 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