Compare commits

..
22 Commits
Author SHA1 Message Date
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
38 changed files with 423 additions and 84 deletions

No files matched your search

+5 -5
View File
@@ -25,15 +25,15 @@ addons:
name: "troglobit/libite" name: "troglobit/libite"
description: "That missing frog DNA you've been looking for" description: "That missing frog DNA you've been looking for"
notification_email: troglobit@gmail.com notification_email: troglobit@gmail.com
build_command_prepend: "./autogen.sh && ./configure --prefix=/tmp --disable-silent-rules" build_command_prepend: "./autogen.sh && ./configure --prefix= --disable-silent-rules"
build_command: "make clean all" build_command: "make clean all"
branch_pattern: dev branch_pattern: dev
script: script:
- ./autogen.sh - ./autogen.sh
- ./configure --prefix=/tmp --disable-silent-rules - ./configure --prefix= --disable-silent-rules
- make clean - make clean
- make -j5 - make -j5
- make install-strip - make install-strip DESTDIR=/tmp/foo
- ls -lR /tmp - ls -lR /tmp/foo
- make check - make distcheck
+33 -1
View File
@@ -3,6 +3,36 @@ Change Log
All notable changes to the project are documented in this file. All notable changes to the project are documented in this file.
[v2.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 [v2.3.0][] - 2021-02-12
----------------------- -----------------------
@@ -383,7 +413,9 @@ problems this may cause!
Initial extraction of frog DNA from [Finit][]. See [README][] for API details. Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
[UNRELEASED]: https://github.com/troglobit/libite/compare/v2.3.0...HEAD [UNRELEASED]: https://github.com/troglobit/libite/compare/v2.4.0...HEAD
[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.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.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.2.0]: https://github.com/troglobit/libite/compare/v2.1.2...v2.2.0
+1 -1
View File
@@ -1,5 +1,5 @@
Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
Copyright (c) 2008-2020 Joachim Nilsson <troglobit@gmail.com> Copyright (c) 2008-2021 Joachim Wiberg <troglobit@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
+6 -6
View File
@@ -24,15 +24,15 @@ release-hook:
echo; \ echo; \
fi fi
# lintian --profile debian -i -I --show-overrides ../$PKG.changes ## Generate .deb package
package build-deb: package:
@dpkg-buildpackage -uc -us -B @debuild -uc -us -B --lintian-opts --profile debian -i -I --show-overrides
## Target to run when building a release ## Target to run when building a release
release: release-hook distcheck package release: release-hook distcheck package
@for file in $(DIST_ARCHIVES); do \ @for file in $(DIST_ARCHIVES); do \
md5sum $$file > ../$$file.md5; \ md5sum $$file > ../$$file.md5; \
sha256sum $$file > ../$$file.sha256; \ sha256sum $$file > ../$$file.sha256; \
done done
@mv $(DIST_ARCHIVES) ../ @mv $(DIST_ARCHIVES) ../
@echo @echo
+16 -2
View File
@@ -94,6 +94,10 @@ Helper Macros
Erase file/directory with `remove()`. Errors on `stderr` Erase file/directory with `remove()`. Errors on `stderr`
- `erasef(fmt, ...)`
Like `erase()` but takes a formatted printf-like string as argument.
- `makedir(path)` - `makedir(path)`
Create directory, like `mkdir()`. Errors on `stderr` Create directory, like `mkdir()`. Errors on `stderr`
@@ -110,6 +114,10 @@ Helper Macros
Create a file, or update mtime. Errors on `stderr` 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)` - `S_ISEXEC(mode_t m)`
Mysteriously missing from GLIBC Mysteriously missing from GLIBC
@@ -311,6 +319,11 @@ Generic Functions
match, or `-1` on error or not found. `strnmatch()` takes an extra arg match, or `-1` on error or not found. `strnmatch()` takes an extra arg
to compare only `len` number of characters from `str`. 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, ...)` - `systemf(fmt, ...)`
Like `system()`, but takes a formatted string as argument. This Like `system()`, but takes a formatted string as argument. This
@@ -442,12 +455,13 @@ as a light weight utility library, these days NetBSD should also work.
to generate a `configure` script. It is a generated file and otherwise to generate a `configure` script. It is a generated file and otherwise
only included in released tarballs. only included in released tarballs.
Origin & References Origin & References
------------------- -------------------
Much of the code in libite (-lite) is written by [Claudio Matsuoka][] Much of the code in libite (-lite) is written by [Claudio Matsuoka][]
for [Finit][original finit] and released under the MIT/X11 license. for [Finit][original finit] and released under the MIT/X11 license.
Joachim Nilsson later improved on the [Finit][] code base and included Joachim Wiberg later improved on the [Finit][] code base and included
pieces of software released under the ISC and BSD licenses. See each pieces of software released under the ISC and BSD licenses. See each
respective file for license details. respective file for license details.
@@ -461,7 +475,7 @@ respective file for license details.
[ISC]: https://en.wikipedia.org/wiki/ISC_license [ISC]: https://en.wikipedia.org/wiki/ISC_license
[BSD]: https://en.wikipedia.org/wiki/BSD_licenses [BSD]: https://en.wikipedia.org/wiki/BSD_licenses
[Travis]: https://travis-ci.org/troglobit/libite [Travis]: https://travis-ci.org/troglobit/libite
[Travis Status]: https://travis-ci.org/troglobit/libite.png?branch=master [Travis Status]: https://travis-ci.org/troglobit/libite.svg?branch=master
[Coverity Scan]: https://scan.coverity.com/projects/20602 [Coverity Scan]: https://scan.coverity.com/projects/20602
[Coverity Status]: https://img.shields.io/coverity/scan/20602.svg [Coverity Status]: https://img.shields.io/coverity/scan/20602.svg
[Claudio Matsuoka]: https://github.com/cmatsuoka [Claudio Matsuoka]: https://github.com/cmatsuoka
+1 -1
View File
@@ -1,4 +1,4 @@
AC_INIT(libite, 2.3.0, https://github.com/troglobit/libite/issues) AC_INIT(libite, 2.4.0, https://github.com/troglobit/libite/issues)
AC_CONFIG_AUX_DIR(aux) AC_CONFIG_AUX_DIR(aux)
AM_INIT_AUTOMAKE([1.11 foreign dist-xz]) AM_INIT_AUTOMAKE([1.11 foreign dist-xz])
AM_SILENT_RULES([yes]) AM_SILENT_RULES([yes])
+21
View File
@@ -1,3 +1,24 @@
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 libite (2.3.0) stable; urgency=medium
* New functions: * New functions:
+1 -1
View File
@@ -1,6 +1,6 @@
Source: libite Source: libite
Priority: optional Priority: optional
Maintainer: Joachim Nilsson <troglobit@gmail.com> Maintainer: Joachim Wiberg <troglobit@gmail.com>
Build-Depends: debhelper (>= 10), libtool Build-Depends: debhelper (>= 10), libtool
Standards-Version: 4.3.0 Standards-Version: 4.3.0
Section: libs Section: libs
+44 -12
View File
@@ -4,7 +4,7 @@ Source: https.//github.com/troglobit/libite/
Files: * Files: *
Copyright: Copyright:
2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
2008-2020 Joachim Nilsson <troglobit@gmail.com> 2008-2021 Joachim Wiberg <troglobit@gmail.com>
License: MIT License: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@@ -25,25 +25,49 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
Files: chomp.c Files: chomp.c
Copyright: 2014-2020 Joachim Nilsson <troglobit@gmail.com> Copyright: 2014-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC License: ISC
Files: conio.h Files: conio.?
Copyright: 2009-2020 Joachim Nilsson <troglobit@gmail.com> Copyright: 2009-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC License: ISC
Files: dir.c Files: dir.c
Copyright: 2008-2020 Joachim Nilsson <troglobit@gmail.com> Copyright: 2008-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC 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 Files: lfile.c
Copyright: 2015-2020 Joachim Nilsson <troglobit@gmail.com> Copyright: 2015-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: makepath.c
Copyright: 2016-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC License: ISC
Files: pidfile.c Files: pidfile.c
Copyright: 1999 The NetBSD Foundation, Inc. Copyright: 1999 The NetBSD Foundation, Inc.
License: BSD-2-clause 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 Files: queue.h
Copyright: 1991, 1993 The Regents of the University of California. Copyright: 1991, 1993 The Regents of the University of California.
License: BSD-3-clause License: BSD-3-clause
@@ -53,7 +77,7 @@ Copyright: 2008 Otto Moerbeek <otto@drijf.net>
License: ISC License: ISC
Files: rsync.c Files: rsync.c
Copyright: 2011-2020 Joachim Nilsson <troglobit@gmail.com> Copyright: 2011-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC License: ISC
Files: strdupa.h strndupa.h Files: strdupa.h strndupa.h
@@ -64,12 +88,16 @@ Files: strlcat.c strlcpy.c
Copyright: 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> Copyright: 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
License: MIT License: MIT
Files: strlite.h
Copyright: 2008-2021 Joachim Wiberg <troglobit@gmail.com>
License: MIT
Files: strmatch.c Files: strmatch.c
Copyright: 2009-2020 Joachim Nilsson <troglobit@gmail.com> Copyright: 2009-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC License: ISC
Files: strnlen.c Files: strnlen.c
Copyright: 2016-2020 Joachim Nilsson <troglobit@gmail.com> Copyright: 2016-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC License: ISC
Files: strtonum.c Files: strtonum.c
@@ -77,19 +105,23 @@ Copyright: 2004 Ted Unangst and Todd Miller
License: ISC License: ISC
Files: telnet.c Files: telnet.c
Copyright: 2010-2020 Joachim Nilsson <troglobit@gmail.com> Copyright: 2010-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC License: ISC
Files: tempfile.c Files: tempfile.c
Copyright: 2015-2020 Joachim Nilsson <troglobit@gmail.com> Copyright: 2015-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC License: ISC
Files: tree.h Files: tree.h
Copyright: 2002 Niels Provos <provos@citi.umich.edu> Copyright: 2002 Niels Provos <provos@citi.umich.edu>
License: BSD-2-clause License: BSD-2-clause
Files: which.c
Copyright: 2017-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC
Files: yorn.c Files: yorn.c
Copyright: 2009-2020 Joachim Nilsson <troglobit@gmail.com> Copyright: 2009-2021 Joachim Wiberg <troglobit@gmail.com>
License: ISC License: ISC
Files: tests/*.c Files: tests/*.c
+3
View File
@@ -5,6 +5,7 @@ libite.so.5 libite5 #MINVER#
chomp@Base 2.0.0 chomp@Base 2.0.0
copyfile@Base 2.0.0 copyfile@Base 2.0.0
dir@Base 2.0.0 dir@Base 2.0.0
erasef@Base 2.4.0
fcopyfile@Base 2.0.0 fcopyfile@Base 2.0.0
fexist@Base 2.0.0 fexist@Base 2.0.0
fgetint@Base 2.0.0 fgetint@Base 2.0.0
@@ -38,12 +39,14 @@ libite.so.5 libite5 #MINVER#
strmatch@Base 2.1.0 strmatch@Base 2.1.0
strnmatch@Base 2.1.0 strnmatch@Base 2.1.0
strtonum@Base 2.1.0 strtonum@Base 2.1.0
strtrim@Base 2.4.0
systemf@Base 2.2.0 systemf@Base 2.2.0
telnet_close@Base 2.1.0 telnet_close@Base 2.1.0
telnet_expect@Base 2.1.0 telnet_expect@Base 2.1.0
telnet_open@Base 2.1.0 telnet_open@Base 2.1.0
telnet_session@Base 2.1.0 telnet_session@Base 2.1.0
tempfile@Base 2.0.0 tempfile@Base 2.0.0
touchf@Base 2.4.0
truncatef@Base 2.3.0 truncatef@Base 2.3.0
which@Base 2.0.0 which@Base 2.0.0
whichp@Base 2.0.0 whichp@Base 2.0.0
+5 -5
View File
@@ -2,19 +2,19 @@ lib_LTLIBRARIES = libite.la
libite_la_CPPFLAGS = -D_GNU_SOURCE libite_la_CPPFLAGS = -D_GNU_SOURCE
libite_la_CFLAGS = -W -Wall -Wextra libite_la_CFLAGS = -W -Wall -Wextra
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 7:0:2 libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 8:0:3
libite_la_SOURCES = chomp.c copyfile.c \ libite_la_SOURCES = chomp.c copyfile.c \
conio.c conio.h \ conio.c conio.h dir.c \
dir.c fopenf.c fremove.c \ erasef.c fopenf.c fremove.c \
fexist.c fisdir.c \ fexist.c fisdir.c \
fparseln.c fsendfile.c \ fparseln.c fsendfile.c \
ifconfig.c lfile.c \ ifconfig.c lfile.c \
makepath.c progress.c \ makepath.c progress.c \
pidfile.c pidfilefn.c \ pidfile.c pidfilefn.c \
reallocarray.c rsync.c \ reallocarray.c rsync.c strtrim.c \
strlcpy.c strlcat.c strtonum.c \ strlcpy.c strlcat.c strtonum.c \
strdupa.h strndupa.h strnlen.h \ strdupa.h strndupa.h strnlen.h \
strmatch.c systemf.c \ strmatch.c systemf.c touchf.c \
telnet.c tempfile.c truncatef.c \ telnet.c tempfile.c truncatef.c \
yorn.c which.c \ yorn.c which.c \
lite.h strlite.h \ lite.h strlite.h \
+1 -1
View File
@@ -1,6 +1,6 @@
/* Perl inspired chomp() implementation. /* Perl inspired chomp() implementation.
* *
* Copyright (c) 2014-2020 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 * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+1 -1
View File
@@ -1,6 +1,6 @@
/* A conio.h like implementation for VTANSI displays. /* A conio.h like implementation for VTANSI displays.
* *
* Copyright (c) 2009-2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+1 -1
View File
@@ -1,6 +1,6 @@
/* A conio.h like implementation for VTANSI displays. /* A conio.h like implementation for VTANSI displays.
* *
* Copyright (c) 2009-2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+1 -1
View File
@@ -1,6 +1,6 @@
/* Functions for operating on files in directories. /* Functions for operating on files in directories.
* *
* Copyright (c) 2008-2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2008-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+66
View File
@@ -0,0 +1,66 @@
/* 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.
*/
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include "lite.h"
/**
* erasef - Like erase() but with formatted string support
* @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 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:
*/
+1 -1
View File
@@ -1,6 +1,6 @@
/* Formatted fopen() /* Formatted fopen()
* *
* Copyright (c) 2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+1 -1
View File
@@ -1,6 +1,6 @@
/* Formatted fremove() /* Formatted fremove()
* *
* Copyright (c) 2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+1 -1
View File
@@ -1,7 +1,7 @@
/* Fastinit (finit) ifconfig() implementation. /* Fastinit (finit) ifconfig() implementation.
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <http://helllabs.org/finit/> * Copyright (c) 2008-2010 Claudio Matsuoka <http://helllabs.org/finit/>
* Copyright (C) 2009-2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (C) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,6 +1,6 @@
/* Parse UNIX /etc configuration files like /etc/protocols and /etc/services /* Parse UNIX /etc configuration files like /etc/protocols and /etc/services
* *
* Copyright (c) 2015-2020 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 * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+9 -4
View File
@@ -1,7 +1,7 @@
/* Collection of frog DNA /* Collection of frog DNA
* *
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com> * Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
* Copyright (c) 2008-2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2008-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -60,6 +60,9 @@ typedef struct lfile lfile_t;
typedef struct sdbuf sdbuf_t; typedef struct sdbuf sdbuf_t;
char *chomp (char *str); char *chomp (char *str);
int erasef (const char *fmt, ...);
char *fparseln (FILE *, size_t *, size_t *, const char[3], int); char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
int fexist (const char *file); int fexist (const char *file);
@@ -107,6 +110,8 @@ int telnet_close (sdbuf_t *ctx);
int telnet_expect (sdbuf_t *ctx, char *script[], FILE *output); int telnet_expect (sdbuf_t *ctx, char *script[], FILE *output);
int telnet_session (int addr, short port, char *script[], FILE *output); int telnet_session (int addr, short port, char *script[], FILE *output);
int touchf (const char *fmt, ...);
int yorn (const char *fmt, ...); int yorn (const char *fmt, ...);
char *which (const char *cmd); char *which (const char *cmd);
@@ -117,9 +122,9 @@ int whichp (const char *cmd);
#include <sys/time.h> /* utimensat() on *BSD */ #include <sys/time.h> /* utimensat() on *BSD */
static inline int touch(const char *path) static inline int touch(const char *path)
{ {
if (mknod((path), S_IFREG|0644, 0)) { if (utimensat(AT_FDCWD, path, NULL, 0)) {
if (errno == EEXIST) if (errno == ENOENT)
return utimensat(AT_FDCWD, path, NULL, 0); return mknod((path), S_IFREG|0644, 0);
return -1; return -1;
} }
return 0; return 0;
+1 -1
View File
@@ -1,6 +1,6 @@
/* mkpath() -- Create all components leading up to a given directory /* mkpath() -- Create all components leading up to a given directory
* *
* Copyright (c) 2013-2016 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2013-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+1 -1
View File
@@ -1,6 +1,6 @@
/* Functions for dealing with PID files (client side) /* Functions for dealing with PID files (client side)
* *
* Copyright (c) 2009-2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+1 -1
View File
@@ -1,6 +1,6 @@
/* Simple termios based progress bar /* Simple termios based progress bar
* *
* Copyright (c) 2012-2020 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 * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+1 -1
View File
@@ -1,6 +1,6 @@
/* Micro "rsync" implementation. /* Micro "rsync" implementation.
* *
* Copyright (c) 2011-2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2011-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+4 -2
View File
@@ -1,6 +1,6 @@
/* Collection of frog DNA /* Collection of frog DNA
* *
* Copyright (c) 2008-2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2008-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@@ -67,6 +67,8 @@ size_t strlcat (char *dst, const char *src, size_t siz);
long long strtonum (const char *numstr, long long minval, long long maxval, const char **errstrp); long long strtonum (const char *numstr, long long minval, long long maxval, const char **errstrp);
#endif #endif
char *strtrim (char *str);
/* Convert string to natural number (0-2147483647), returns -1 on error. */ /* Convert string to natural number (0-2147483647), returns -1 on error. */
static inline int atonum(const char *str) static inline int atonum(const char *str)
{ {
@@ -107,7 +109,7 @@ static inline int string_compare(const char *a, const char *b)
*/ */
static inline int string_case_compare(const char *a, const char *b) static inline int string_case_compare(const char *a, const char *b)
{ {
return strlen (a) == strlen (b) && !strcasecmp (a, b); return strlen(a) == strlen(b) && !strcasecmp(a, b);
} }
#endif /* LITE_STRING_H_ */ #endif /* LITE_STRING_H_ */
+1 -1
View File
@@ -1,6 +1,6 @@
/* Simple string matcher function, finds partial matches. /* Simple string matcher function, finds partial matches.
* *
* Copyright (c) 2009-2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+1 -1
View File
@@ -1,6 +1,6 @@
/* strnlen.h - Re-implementation of GLIBC strnlen() /* strnlen.h - Re-implementation of GLIBC strnlen()
* *
* Copyright (c) 2016-2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2016-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+70
View File
@@ -0,0 +1,70 @@
/* 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.
*/
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include "lite.h"
/**
* strtrim - Strip leading and trailing whitespace from a string
* @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 @str is a valid, non-NULL, string this function returns the same
* string stripped from whitespace. This function only returns %NULL
* if @str itself is %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:
*/
+12 -19
View File
@@ -1,6 +1,6 @@
/* Formatted system() which returns actual return status of command /* Formatted system() which returns actual return status of command
* *
* Copyright (c) 2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@@ -25,8 +25,8 @@ int systemf(const char *fmt, ...)
{ {
va_list ap; va_list ap;
char *cmd; char *cmd;
int len, status; int len;
int rc = -1; int rc;
va_start(ap, fmt); va_start(ap, fmt);
len = vsnprintf(NULL, 0, fmt, ap); len = vsnprintf(NULL, 0, fmt, ap);
@@ -42,23 +42,16 @@ int systemf(const char *fmt, ...)
vsnprintf(cmd, len, fmt, ap); vsnprintf(cmd, len, fmt, ap);
va_end(ap); va_end(ap);
status = system(cmd); rc = system(cmd);
if (rc == -1)
return -1;
rc = WEXITSTATUS(status); if (WIFEXITED(rc)) {
if (!WIFEXITED(status)) { errno = 0;
if (WIFSIGNALED(status) && rc = WEXITSTATUS(rc);
(WTERMSIG(status) == SIGINT || } else if (WIFSIGNALED(rc)) {
WTERMSIG(status) == SIGQUIT)) { errno = EINTR;
errno = EINTR; rc = -1;
rc = -1;
} else if (!rc) {
/*
* Alert callee that command didn't complete
* successfully. Some programs don't change
* their exit code when signaled.
*/
rc = 1;
}
} }
return rc; return rc;
+1 -1
View File
@@ -1,6 +1,6 @@
/* Poor mans telnet expect in C. /* Poor mans telnet expect in C.
* *
* Copyright (c) 2010-2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2010-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+1 -1
View File
@@ -1,6 +1,6 @@
/* A secure tmpfile() replacement. /* A secure tmpfile() replacement.
* *
* Copyright (c) 2015-2020 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 * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+66
View File
@@ -0,0 +1,66 @@
/* Formatted touch()
*
* 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.
*/
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include "lite.h"
/**
* touchf - Like touch() but with formatted string support
* @fmt: Formatted string to be composed into a pathname
*
* This is a wrapper for the touch() function in lite.h, lessening the
* burden of having to compose the filename from parts in a seprate
* buffer.
*
* Returns:
* Upon successful completion touchf() returns POSIX OK(0), otherwise,
* -1 is returned and errno is set to indicate the error.
*/
int touchf(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 touch(file);
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+1 -2
View File
@@ -1,6 +1,6 @@
/* Formatted truncate() /* Formatted truncate()
* *
* Copyright (c) 2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@@ -30,7 +30,6 @@
* of having to compose the filename from parts in a seprate buffer. * of having to compose the filename from parts in a seprate buffer.
* *
* Returns: * Returns:
* Upon successful completion truncate() returns POSIX OK(0), otherwise, * Upon successful completion truncate() returns POSIX OK(0), otherwise,
* -1 is returned and errno is set to indicate the error. * -1 is returned and errno is set to indicate the error.
*/ */
+1 -1
View File
@@ -1,6 +1,6 @@
/* C implementation of UNIX which(1) /* C implementation of UNIX which(1)
* *
* Copyright (c) 2017-2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2017-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+1 -1
View File
@@ -1,6 +1,6 @@
/* Safe yes-or-no with prompt /* Safe yes-or-no with prompt
* *
* Copyright (c) 2009-2020 Joachim Nilsson <troglobit@gmail.com> * Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
+8 -3
View File
@@ -4,9 +4,10 @@
int main(void) int main(void)
{ {
struct { char *cmd; int rc; } list[] = { struct { char *cmd; int rc; } list[] = {
{ "/app/enoent", 127 },
{ "false", 1 }, { "false", 1 },
{ "true", 0 }, { "true", 0 },
{ "kill -9 $$", 1 }, { "kill -9 $$", -1 },
{ "kill -QUIT $$", -1 }, { "kill -QUIT $$", -1 },
{ "kill -INT $$", -1 } { "kill -INT $$", -1 }
}; };
@@ -15,8 +16,12 @@ int main(void)
int rc; int rc;
rc = systemf("%s", list[i].cmd); rc = systemf("%s", list[i].cmd);
if (rc != list[i].rc) if (rc != list[i].rc) {
err(rc, "Failed command %s", list[i].cmd); if (rc == -1)
err(rc, "Failed %s", list[i].cmd);
else
errx(rc, "Failed %s, rc %d vs %d", list[i].cmd, rc, list[i].rc);
}
} }
return 0; return 0;
+33 -2
View File
@@ -1,3 +1,4 @@
/* test of touch(), touchf(), erase(), and erasef() */
#include <err.h> #include <err.h>
#include <paths.h> #include <paths.h>
#include <signal.h> #include <signal.h>
@@ -6,6 +7,8 @@
#include "check.h" #include "check.h"
#define FMT "%s-bar"
int verbose = 0; int verbose = 0;
@@ -32,10 +35,38 @@ static int mtime(char *file)
ret = timespec_newer(&after.st_mtim, &before.st_mtim); ret = timespec_newer(&after.st_mtim, &before.st_mtim);
PRINT("Before: %s\n", timespec2str(&before.st_mtim, buf, sizeof(buf))); PRINT("Before: %s\n", timespec2str(&before.st_mtim, buf, sizeof(buf)));
PRINT("After : %s\n", timespec2str(&after.st_mtim, buf, sizeof(buf))); PRINT("After : %s\n", timespec2str(&after.st_mtim, buf, sizeof(buf)));
erase(file);
return !ret; return !ret;
} }
static int formatted(char *file)
{
char vrfy[80];
if (touchf(FMT, file))
err(1, "Failed creating " FMT, file);
PRINT("Created " FMT "\n", file);
snprintf(vrfy, sizeof(vrfy), FMT, file);
if (!fexist(vrfy))
errx(1, "touchf() does not detect failure to create file " FMT, file);
PRINT("File " FMT " really does exist!\n", file);
erasef(FMT, file);
if (fexist(vrfy)) {
int saved = errno;
erase(vrfy);
errno = saved;
errx(1, "erasef() failed removing the created file " FMT, file);
}
return 0;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int fd; int fd;
@@ -49,13 +80,13 @@ int main(int argc, char *argv[])
err(1, "Failed creating tempfile, %s", file); err(1, "Failed creating tempfile, %s", file);
close(fd); close(fd);
return mtime(file); return mtime(file) || formatted(file);
} }
/** /**
* Local Variables: * Local Variables:
* indent-tabs-mode: t * indent-tabs-mode: t
* c-file-style: "linux" * c-file-style: "linux"
* compile-command: "make pidfile && ./pidfile -v" * compile-command: "make touch && ./touch -v"
* End: * End:
*/ */