mirror of
https://github.com/troglobit/libite.git
synced 2026-10-14 10:19:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c9c038c06 | ||
|
|
e5b79443b8 | ||
|
|
589465f48b | ||
|
|
1f745ff9a0 | ||
|
|
71a0c53029 | ||
|
|
6608d2e8c9 | ||
|
|
62334c80fd | ||
|
|
626d5456f7 | ||
|
|
e3dff8e5be | ||
|
|
bbb951dc23 | ||
|
|
94800e7d5c | ||
|
|
3442d8e12b | ||
|
|
75f57283bd | ||
|
|
daf41d326b | ||
|
|
3179be4348 | ||
|
|
56530a8c78 | ||
|
|
abd6e3abd6 | ||
|
|
b078a8676f | ||
|
|
c2b92a38ef | ||
|
|
98b2e9d426 | ||
|
|
96d3e5dd8b | ||
|
|
ff626acb73 | ||
|
|
ba3f7c89fb | ||
|
|
714ea88cc9 | ||
|
|
add4d5d325 | ||
|
|
be6f276557 | ||
|
|
6daebf4ea4 | ||
|
|
4d6e3e060e | ||
|
|
86eef8e38d | ||
|
|
d5d3dafc78 | ||
|
|
2534c398ea | ||
|
|
3691044007 | ||
|
|
6770dad0cc | ||
|
|
ef0db5e766 | ||
|
|
485463c70e | ||
|
|
4b77eb1423 | ||
|
|
0b54dc6015 | ||
|
|
9d6df87d0d | ||
|
|
5b2eee6aff | ||
|
|
6904f6e0fe | ||
|
|
877ba02d13 | ||
|
|
25dfded835 | ||
|
|
1323a88e94 | ||
|
|
018e607290 | ||
|
|
e48c9c5589 | ||
|
|
2c875afe06 | ||
|
|
10e4a1d057 | ||
|
|
3dde2922c3 | ||
|
|
4dd9459f65 | ||
|
|
7172f487d5 | ||
|
|
4c0967405d | ||
|
|
fd65af31db | ||
|
|
e55976d137 | ||
|
|
1b1ffb33f1 | ||
|
|
d018a5215f | ||
|
|
0d70c116d7 | ||
|
|
32c774deef | ||
|
|
441d5f58d7 | ||
|
|
2a59289d53 | ||
|
|
f89c3c88de | ||
|
|
705b402344 | ||
|
|
fe82ab953c | ||
|
|
6ec2a31042 | ||
|
|
9f5e852084 | ||
|
|
628c5597b9 | ||
|
|
b7b635a3f4 | ||
|
|
dd53c3ae9e | ||
|
|
16a30a293c | ||
|
|
325fcbe149 | ||
|
|
cbb1604ea0 | ||
|
|
8587971fb9 | ||
|
|
6545ac8fd4 | ||
|
|
9105e8d3d8 | ||
|
|
3555af6a6a | ||
|
|
42715eab8a | ||
|
|
497d58dbf0 | ||
|
|
9ab70ebbcd | ||
|
|
bad363883d | ||
|
|
7f3215b3e6 | ||
|
|
729cc5307f | ||
|
|
66290d132f | ||
|
|
59f7a78441 | ||
|
|
b716776863 | ||
|
|
018ecaca15 | ||
|
|
a293c37777 | ||
|
|
a4937a93e2 | ||
|
|
94d547c9ec | ||
|
|
68cf8b6576 | ||
|
|
b6a55fcc46 | ||
|
|
5f29ef6413 | ||
|
|
627c47caff | ||
|
|
7c2ed556b9 | ||
|
|
6dec4e3858 | ||
|
|
dff92356b3 | ||
|
|
883c90112d | ||
|
|
a2c8dddaad | ||
|
|
14f547b638 | ||
|
|
6f2a03bba7 | ||
|
|
cdfffa312b | ||
|
|
50cb72018f | ||
|
|
e8a3117158 |
No files matched your search
@@ -6,6 +6,10 @@
|
|||||||
*.a
|
*.a
|
||||||
.deps
|
.deps
|
||||||
.libs
|
.libs
|
||||||
|
ID
|
||||||
|
GPATH
|
||||||
|
GRTAGS
|
||||||
|
GTAGS
|
||||||
tmp/
|
tmp/
|
||||||
compile
|
compile
|
||||||
config.*
|
config.*
|
||||||
@@ -22,3 +26,4 @@ aclocal.m4
|
|||||||
ar-lib
|
ar-lib
|
||||||
autom4te.cache
|
autom4te.cache
|
||||||
libite*
|
libite*
|
||||||
|
test-driver
|
||||||
+106
-1
@@ -4,6 +4,103 @@ 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.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
|
[v1.8.0][] - 2016-06-06
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
@@ -195,7 +292,15 @@ problems this may cause!
|
|||||||
Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
|
Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
|
||||||
|
|
||||||
|
|
||||||
[UNRELEASED]: https://github.com/troglobit/libite/compare/v1.8.0...HEAD
|
[UNRELEASED]: https://github.com/troglobit/libite/compare/v2.0.0...HEAD
|
||||||
|
[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.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.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.6.0]: https://github.com/troglobit/libite/compare/v1.5.1...v1.6.0
|
||||||
|
|||||||
+24
-5
@@ -4,9 +4,10 @@ Maintenance and Release Checklist
|
|||||||
Maintenance
|
Maintenance
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
* Encourage contributors to write tests, in particular for new features
|
||||||
|
* Run tests regularly, use Travis-CI to do this automatically
|
||||||
* Leverage GitHub issues for milestone planning
|
* Leverage GitHub issues for milestone planning
|
||||||
* Reference issues from GitHub pull requests to alert issue subscribers
|
* Reference issues from GitHub pull requests to alert issue subscribers
|
||||||
* Encourage contributors to write unit tests
|
|
||||||
* Bump library ABI version just before release!
|
* Bump library ABI version just before release!
|
||||||
|
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ Release Checklist
|
|||||||
- Inform users in a plain language of changes and bug fixes
|
- Inform users in a plain language of changes and bug fixes
|
||||||
- Do *not* copy-paste GIT commit logs!
|
- Do *not* copy-paste GIT commit logs!
|
||||||
- Order entrys according to importance, most relevant first
|
- Order entrys according to importance, most relevant first
|
||||||
|
* Run unit tests: `make check`
|
||||||
* Do we need to bump the ABI version? (Probably, see below)
|
* Do we need to bump the ABI version? (Probably, see below)
|
||||||
* Tag
|
* Tag
|
||||||
* Push last commit(s) *and* tags to GitHub
|
* Push last commit(s) *and* tags to GitHub
|
||||||
@@ -25,7 +27,7 @@ Release Checklist
|
|||||||
make distclean
|
make distclean
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
./configure
|
./configure
|
||||||
make release
|
make release
|
||||||
|
|
||||||
* Create new release in GitHub releases page
|
* Create new release in GitHub releases page
|
||||||
* Copy and paste ChangeLog entry, check any stale links!
|
* Copy and paste ChangeLog entry, check any stale links!
|
||||||
@@ -54,14 +56,31 @@ It must be updated according to the [GNU Libtool recommendations][1]:
|
|||||||
release of your software. More frequent updates are unnecessary, and
|
release of your software. More frequent updates are unnecessary, and
|
||||||
only guarantee that the current interface number gets larger faster.
|
only guarantee that the current interface number gets larger faster.
|
||||||
3. If the library *source code has changed at all* since the last update,
|
3. If the library *source code has changed at all* since the last update,
|
||||||
then increment revision (`c:r:a` --> `c:r+1:a`)
|
then increment revision (`c:r:a` becomes `c:r+1:a`).
|
||||||
4. If any *interfaces have been added, removed, or changed* since last
|
4. If any *interfaces have been added, removed, or changed* since the
|
||||||
update, increment current, and zero revision (`c:r:a` --> `c+1:0:0`)
|
last update, increment current, and set revision to 0.
|
||||||
5. If any *interfaces have been added* since the last public release,
|
5. If any *interfaces have been added* since the last public release,
|
||||||
then increment age.
|
then increment age.
|
||||||
6. If any *interfaces have been removed or changed* since the last
|
6. If any *interfaces have been removed or changed* since the last
|
||||||
public release, then set age to 0.
|
public release, then set age to 0.
|
||||||
|
|
||||||
|
The libtool ABI versioning logic is very confusing but works if you just
|
||||||
|
disable your brain and follow the rules, one by one.
|
||||||
|
|
||||||
|
**Example #1:** a new function has been added, none of the existing ones
|
||||||
|
have changed. The initial version is 1:0:0, we follow the rules above to
|
||||||
|
the letter: increase revision, increase current and set revision to zero,
|
||||||
|
and finally increase age. This, rather confusingly, gives us 2:0:1 which
|
||||||
|
libtool then translates to `libconfuse.so.1.1.0`.
|
||||||
|
|
||||||
|
**Example #2:** some existing functions are changed, they now return an
|
||||||
|
`int` instead of `void`. The initial version is 0:0:0, and we follow the
|
||||||
|
rules again: increment revision, increment current and set revision to
|
||||||
|
zero, set age to zero. This gives us 1:0:0, which is then translated to
|
||||||
|
`libconfuse.so.1.0.0`.
|
||||||
|
|
||||||
|
### Note
|
||||||
|
|
||||||
Usually, non-developers have no interest in running development versions
|
Usually, non-developers have no interest in running development versions
|
||||||
(releases are frequent enough), and developers are expected to know how
|
(releases are frequent enough), and developers are expected to know how
|
||||||
to juggle versions. In such an ideal world, it is good enough to bump
|
to juggle versions. In such an ideal world, it is good enough to bump
|
||||||
|
|||||||
+28
-36
@@ -1,52 +1,44 @@
|
|||||||
ACLOCAL_AMFLAGS = -I m4
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
|
|
||||||
lib_LTLIBRARIES = libite.la
|
|
||||||
pkgincludedir = $(includedir)/lite
|
|
||||||
pkginclude_HEADERS = lite.h queue.h conio.h tree.h strlite.h strdupa.h strndupa.h strnlen.h
|
|
||||||
libite_la_SOURCES = chomp.c copyfile.c dir.c fexist.c fisdir.c fmode.c fparseln.c \
|
|
||||||
fsendfile.c ifconfig.c lfile.c makepath.c pidfile.c pidfilefn.c \
|
|
||||||
progress.c reallocarray.c rsync.c strlcpy.c strlcat.c strtonum.c \
|
|
||||||
tempfile.c tree.c
|
|
||||||
|
|
||||||
libite_la_CPPFLAGS = -D_GNU_SOURCE
|
|
||||||
libite_la_CFLAGS = -W -Wall -Wextra
|
|
||||||
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 3:0:0
|
|
||||||
|
|
||||||
pkgconfigdir = $(libdir)/pkgconfig
|
|
||||||
pkgconfig_DATA = libite.pc
|
|
||||||
doc_DATA = README.md LICENSE
|
doc_DATA = README.md LICENSE
|
||||||
EXTRA_DIST = README.md LICENSE ChangeLog.md
|
EXTRA_DIST = README.md LICENSE ChangeLog.md
|
||||||
SUBDIRS = tests
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
|
pkgconfig_DATA = libite.pc
|
||||||
|
SUBDIRS = src tests
|
||||||
|
|
||||||
|
## Generate .deb package
|
||||||
|
package:
|
||||||
|
@dpkg-buildpackage -uc -us -B
|
||||||
|
|
||||||
## Generate MD5 checksum file
|
## Generate MD5 checksum file
|
||||||
MD5 = md5sum
|
MD5 = md5sum
|
||||||
md5-dist:
|
md5-dist:
|
||||||
@for file in $(DIST_ARCHIVES); do \
|
@for file in $(DIST_ARCHIVES); do \
|
||||||
$(MD5) $$file > $$file.md5; \
|
$(MD5) $$file > $$file.md5; \
|
||||||
done
|
done
|
||||||
|
|
||||||
## Check if tagged in git
|
## Check if tagged in git
|
||||||
release-hook:
|
release-hook:
|
||||||
if [ ! `git tag | grep $(PACKAGE_VERSION)` ]; then \
|
if [ ! `git tag | grep $(PACKAGE_VERSION)` ]; then \
|
||||||
echo; \
|
echo; \
|
||||||
printf "\e[1m\e[41mCannot find release tag $(PACKAGE_VERSION)\e[0m\n"; \
|
printf "\033[1m\033[41mCannot find release tag $(PACKAGE_VERSION)\033[0m\n"; \
|
||||||
printf "\e[1m\e[5mDo release anyway?\e[0m "; read yorn; \
|
printf "\033[1m\033[5mDo release anyway?\033[0m "; read yorn; \
|
||||||
if [ "$$yorn" != "y" -a "$$yorn" != "Y" ]; then \
|
if [ "$$yorn" != "y" -a "$$yorn" != "Y" ]; then \
|
||||||
printf "OK, aborting release.\n"; \
|
printf "OK, aborting release.\n"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi; \
|
fi; \
|
||||||
echo; \
|
echo; \
|
||||||
else \
|
else \
|
||||||
echo; \
|
echo; \
|
||||||
printf "\e[1m\e[42mFound GIT release tag $(PACKAGE_VERSION)\e[0m\n"; \
|
printf "\033[1m\033[42mFound GIT release tag $(PACKAGE_VERSION)\033[0m\n"; \
|
||||||
printf "\e[1m\e[44m>>Remember to push tags!\e[0m\n"; \
|
printf "\033[1m\033[44m>>Remember to push tags!\033[0m\n"; \
|
||||||
echo; \
|
echo; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Target to run when building a release
|
## Target to run when building a release
|
||||||
release: dist release-hook md5-dist
|
release: distcheck release-hook md5-dist
|
||||||
@for file in $(DIST_ARCHIVES); do \
|
@for file in $(DIST_ARCHIVES); do \
|
||||||
printf "$$file \tDistribution tarball\n"; \
|
printf "$$file \tDistribution tarball\n"; \
|
||||||
printf "$$file.md5\t"; cat $$file.md5 | cut -f1 -d' '; \
|
printf "$$file.md5\t"; cat $$file.md5 | cut -f1 -d' '; \
|
||||||
mv $$file* ../; \
|
mv $$file* ../; \
|
||||||
done
|
done
|
||||||
@@ -15,6 +15,8 @@ Table of Contents
|
|||||||
* [TODO](#todo)
|
* [TODO](#todo)
|
||||||
|
|
||||||
|
|
||||||
|
> **NOTE:** Incompatible changes in v2.0 compared to v1.x!
|
||||||
|
|
||||||
Introduction
|
Introduction
|
||||||
------------
|
------------
|
||||||
|
|
||||||
@@ -70,6 +72,14 @@ and in your `Makefile.am`:
|
|||||||
proggy_LDADD = $(lite_LIBS)
|
proggy_LDADD = $(lite_LIBS)
|
||||||
|
|
||||||
|
|
||||||
|
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
|
Helper Macros
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
@@ -135,10 +145,6 @@ Helper Macros
|
|||||||
Returns the number of elements in an array. From the great book, The
|
Returns the number of elements in an array. From the great book, The
|
||||||
Practice of Programming, by Kernighan and Pike.
|
Practice of Programming, by Kernighan and Pike.
|
||||||
|
|
||||||
- `UNUSED(var)`
|
|
||||||
|
|
||||||
Shorter and more readable version of `var __attribute__ ((unused))`
|
|
||||||
|
|
||||||
|
|
||||||
Generic Functions
|
Generic Functions
|
||||||
-----------------
|
-----------------
|
||||||
@@ -147,9 +153,18 @@ Generic Functions
|
|||||||
|
|
||||||
Perl like chomp function, chop off last char if newline.
|
Perl like chomp function, chop off last char if newline.
|
||||||
|
|
||||||
- `copyfile(src, dst, len, symlink)`
|
- `copyfile(src, dst, len, opt)`
|
||||||
|
|
||||||
Like the shell `cp(1)` and `dd(1),` can also create symlinks.
|
Like the shell `cp(1)` and `dd(1),`, can also copy symlinks and
|
||||||
|
preserve the mtime of the source file. The opt argument can be
|
||||||
|
a mask of:
|
||||||
|
|
||||||
|
- `LITE_FOPT_COPYFILE_SYM (0x01)`
|
||||||
|
- `LITE_FOPT_KEEP_MTIME (0x02)`
|
||||||
|
|
||||||
|
In releases prior to v2.0 the opt argument was called `symlink`.
|
||||||
|
The APIs are 100% compatible if the value `1` was used to enable
|
||||||
|
the symlink option.
|
||||||
|
|
||||||
- `dir(dir, ext, filter, list, strip)`
|
- `dir(dir, ext, filter, list, strip)`
|
||||||
|
|
||||||
@@ -171,10 +186,6 @@ Generic Functions
|
|||||||
|
|
||||||
Check for the existence of a directory, returns True(1) or False(0).
|
Check for the existence of a directory, returns True(1) or False(0).
|
||||||
|
|
||||||
- `fmode(file)`
|
|
||||||
|
|
||||||
Returns the `mode_t` bits of a file or directory.
|
|
||||||
|
|
||||||
- `fsendfile(src, dst, len)`
|
- `fsendfile(src, dst, len)`
|
||||||
|
|
||||||
Copy data between file streams, very similar to `fcopyfile()`, but
|
Copy data between file streams, very similar to `fcopyfile()`, but
|
||||||
@@ -223,11 +234,13 @@ Generic Functions
|
|||||||
with the `dst` name. On successful operation the source is removed
|
with the `dst` name. On successful operation the source is removed
|
||||||
and the function returns POSIX OK (0).
|
and the function returns POSIX OK (0).
|
||||||
|
|
||||||
- `pidfile(basename)`
|
- `pidfile(name)`
|
||||||
|
|
||||||
Create a daemon PID file in `_PATH_VARRUN` using either `basename` or,
|
Create a daemon PID file using either the `name` as a full path, if
|
||||||
if `basename` is `NULL`, `__progname`. The resulting file name is
|
`name` starts with `/`, or in `_PATH_VARRUN` using `name` as the
|
||||||
available to the user as a read-only pointer:
|
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;
|
extern char *__pidfile_name;
|
||||||
|
|
||||||
@@ -238,14 +251,14 @@ Generic Functions
|
|||||||
|
|
||||||
The PID file is removed when the program exits, using an `atexit()`
|
The PID file is removed when the program exits, using an `atexit()`
|
||||||
handler. However, depending on how the program terminates the file
|
handler. However, depending on how the program terminates the file
|
||||||
may still exist even though the program is no longer running. This
|
may still exist even though the program is no longer running.
|
||||||
is only a problem for clients.
|
|
||||||
|
|
||||||
Calling this function multiple times updates the mtime of the file.
|
Calling this function multiple times updates the mtime of the file.
|
||||||
Only one `atexit()` handler is created, regardless of the amount of
|
Only one `atexit()` handler is created, regardless of the amount of
|
||||||
times the function is called.
|
times the function is called. If the file is removed, subsequent
|
||||||
|
calls to this function will recreate the file.
|
||||||
|
|
||||||
See below for link to OpenBSD man page.
|
See below for a link to OpenBSD man page.
|
||||||
|
|
||||||
- `pidfile_read(pidfile)`
|
- `pidfile_read(pidfile)`
|
||||||
|
|
||||||
@@ -262,10 +275,19 @@ Generic Functions
|
|||||||
Called multiple times with the same percentage value cause spinner to
|
Called multiple times with the same percentage value cause spinner to
|
||||||
spin.
|
spin.
|
||||||
|
|
||||||
- `rsync(src, dst, delete, *filter())`
|
- `rsync(src, dst, opt, *filter())`
|
||||||
|
|
||||||
Very simple `rsync()` to copy files files and directories
|
Very simple `rsync()` to copy files and directories recursively. It
|
||||||
recursively.
|
supports pruning files from the destination tree that do not exist in
|
||||||
|
the source tree and preserving the mtime of the source files. The opt
|
||||||
|
argument can be a mask of:
|
||||||
|
|
||||||
|
- `LITE_FOPT_RSYNC_DELETE (0x01)`
|
||||||
|
- `LITE_FOPT_KEEP_MTIME (0x02)`
|
||||||
|
|
||||||
|
In releases prior to v2.0 the argument controlling pruning was called
|
||||||
|
`delete`, it is now called `opt`. The APIs are 100% compatible if the
|
||||||
|
value `1` was used.
|
||||||
|
|
||||||
- `tempfile()`
|
- `tempfile()`
|
||||||
|
|
||||||
@@ -276,11 +298,15 @@ Generic Functions
|
|||||||
**Note:** Requires Linux v3.11, or later, will fall back to the old
|
**Note:** Requires Linux v3.11, or later, will fall back to the old
|
||||||
and unsafe `tmpfile()` on older systems.
|
and unsafe `tmpfile()` on older systems.
|
||||||
|
|
||||||
- `tree(path, show_perms)`
|
- `which(cmd)`, `whichp(cmd)`
|
||||||
|
|
||||||
Very simple `/bin/tree` replacement. Draw ASCII tree of `path`, with
|
C implementation of UNIX which(1). Returns a malloc'ed string with the
|
||||||
optional listing of file and directory permissions if `show_perms` is
|
full path to `cmd` on success, otherwise `NULL`.
|
||||||
set. The `path` argument should be a directory.
|
|
||||||
|
`whichp()` is a predicate function, returns `TRUE` or `FALSE`.
|
||||||
|
|
||||||
|
**Note:** `which("/bin/ps aux")` will return `/bin/ps`, or `TRUE`,
|
||||||
|
provided of course `/bin/ps` exists.
|
||||||
|
|
||||||
|
|
||||||
GNU Functions
|
GNU Functions
|
||||||
@@ -316,9 +342,9 @@ The following are popular functions and highly useful macros from the
|
|||||||
|
|
||||||
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/pidfile.3
|
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/pidfile.3
|
||||||
|
|
||||||
**Note:** this version of `pidfile()` has been extended to handle it
|
**Note:** the version of `pidfile()` in -lite has been extended to
|
||||||
being called multiple times, i.e. to not create multiple `atexit()`
|
handle it being called multiple times, i.e. to not create multiple
|
||||||
handlers, and also to export a few internal paths:
|
`atexit()` handlers, and also to export a few internal paths:
|
||||||
|
|
||||||
- `__pidfile_path`: prefix path, default `_PATH_VARRUN`. Notice the
|
- `__pidfile_path`: prefix path, default `_PATH_VARRUN`. Notice the
|
||||||
trailing slash requirement if you want to override it!
|
trailing slash requirement if you want to override it!
|
||||||
@@ -362,7 +388,8 @@ system:
|
|||||||
|
|
||||||
./configure
|
./configure
|
||||||
make -j5
|
make -j5
|
||||||
make install-strip
|
sudo make install-strip
|
||||||
|
sudo ldconfig
|
||||||
|
|
||||||
**Note:** When checking code from GitHub, use <kbd>./autogen.sh</kbd> to
|
**Note:** When checking code from GitHub, use <kbd>./autogen.sh</kbd> to
|
||||||
generate a `configure` script. It is a generated file and otherwise only
|
generate a `configure` script. It is a generated file and otherwise only
|
||||||
|
|||||||
+3
-3
@@ -1,10 +1,10 @@
|
|||||||
AC_INIT(libite, 1.8.0, https://github.com/troglobit/libite/issues)
|
AC_INIT(libite, 2.0.0, https://github.com/troglobit/libite/issues)
|
||||||
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz])
|
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz])
|
||||||
AM_SILENT_RULES([yes])
|
AM_SILENT_RULES([yes])
|
||||||
|
|
||||||
AC_CONFIG_SRCDIR(lite.h)
|
AC_CONFIG_SRCDIR(src/lite.h)
|
||||||
AM_CONFIG_HEADER(config.h)
|
AM_CONFIG_HEADER(config.h)
|
||||||
AC_CONFIG_FILES([Makefile tests/Makefile libite.pc])
|
AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile libite.pc])
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
|
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
tmp/*
|
||||||
|
libuev/*
|
||||||
|
libuev*
|
||||||
|
autoreconf*
|
||||||
|
debhelper*
|
||||||
|
files
|
||||||
|
!*.dirs
|
||||||
|
!*.install
|
||||||
Vendored
+47
@@ -0,0 +1,47 @@
|
|||||||
|
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
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
config.log
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
9
|
||||||
Vendored
+51
@@ -0,0 +1,51 @@
|
|||||||
|
Source: libite
|
||||||
|
Priority: optional
|
||||||
|
Maintainer: Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
Build-Depends: dpkg-dev (>= 1.14.9), debhelper (>= 9), dh-autoreconf
|
||||||
|
Standards-Version: 3.9.6
|
||||||
|
Section: libs
|
||||||
|
Homepage: https://github.com/troglobit/libite/
|
||||||
|
Vcs-Git: https://github.com/troglobit/libite.git
|
||||||
|
Vcs-Browser: https://github.com/troglobit/libite/
|
||||||
|
|
||||||
|
Package: libite-dev
|
||||||
|
Priority: extra
|
||||||
|
Section: libdevel
|
||||||
|
Architecture: any
|
||||||
|
Depends: ${misc:Depends}, libite (= ${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: libite
|
||||||
|
Architecture: any
|
||||||
|
Depends: ${misc:Depends}, ${shlibs:Depends}
|
||||||
|
Description: That missing frog DNA you've been looking for. MIT/X11/ISC/BSD License.
|
||||||
|
Libite is a lightweight library of frog DNA. It can be used to fill the
|
||||||
|
gaps in any dinosaur project. It holds useful functions and macros
|
||||||
|
developed by both Finit and the OpenBSD project. Most notably the
|
||||||
|
string functions: strlcpy(3), strlcat(3) and the highly useful *BSD
|
||||||
|
sys/queue.h and sys/tree.h API's.
|
||||||
|
.
|
||||||
|
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.
|
||||||
Vendored
+84
@@ -0,0 +1,84 @@
|
|||||||
|
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-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: MIT
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
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-2015 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: conio.h
|
||||||
|
Copyright: 2009-2013 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: dir.c
|
||||||
|
Copyright: 2008-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: lfile.c
|
||||||
|
Copyright: 2015-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: pidfile.c
|
||||||
|
Copyright: 1999 The NetBSD Foundation, Inc.
|
||||||
|
License: BSD-2-clause
|
||||||
|
|
||||||
|
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, 2012 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: strdupa.h strndupa.h
|
||||||
|
Copyright: 2009 William Ahern
|
||||||
|
License: MIT
|
||||||
|
|
||||||
|
Files: strlcat.c strlcpy.c
|
||||||
|
Copyright: 998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
License: MIT
|
||||||
|
|
||||||
|
Files: strnlen.c
|
||||||
|
Copyright: 2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: strtonum.c
|
||||||
|
Copyright: 2004 Ted Unangst and Todd Miller
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: tempfile.c
|
||||||
|
Copyright: 2015-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: tree.c
|
||||||
|
Copyright: 2015 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: tests/*.c
|
||||||
|
License: public-domain
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
README.md
|
||||||
Vendored
+2
@@ -0,0 +1,2 @@
|
|||||||
|
usr/lib
|
||||||
|
usr/include
|
||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
usr/include/lite/*.h
|
||||||
|
usr/lib/*/lib*.a
|
||||||
|
usr/lib/*/lib*.so
|
||||||
|
usr/lib/*/pkgconfig/lib*.pc
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
usr/lib
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
usr/lib/*/lib*.so.*
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/make -f
|
||||||
|
|
||||||
|
# Uncomment this to turn on verbose mode.
|
||||||
|
#export DH_VERBOSE=1
|
||||||
|
|
||||||
|
%:
|
||||||
|
dh $@ --with autoreconf
|
||||||
|
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
3.0 (native)
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
/* File mode bit operations
|
|
||||||
*
|
|
||||||
* Copyright (c) 2008 Claudio Matsuoka <http://helllabs.org/finit/>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fmode - Return a file's mode bits.
|
|
||||||
* @file: File to look for, with full path.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* The mode bits or zero when @file does not exist and errno set to %ENOENT.
|
|
||||||
*/
|
|
||||||
mode_t fmode(char *file)
|
|
||||||
{
|
|
||||||
struct stat sb;
|
|
||||||
|
|
||||||
if (!file) {
|
|
||||||
errno = EINVAL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!stat(file, &sb))
|
|
||||||
return sb.st_mode;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Local Variables:
|
|
||||||
* indent-tabs-mode: t
|
|
||||||
* c-file-style: "linux"
|
|
||||||
* End:
|
|
||||||
*/
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
lib_LTLIBRARIES = libite.la
|
||||||
|
|
||||||
|
libite_la_CPPFLAGS = -D_GNU_SOURCE
|
||||||
|
libite_la_CFLAGS = -W -Wall -Wextra
|
||||||
|
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 5:0:0
|
||||||
|
libite_la_SOURCES = chomp.c copyfile.c \
|
||||||
|
conio.c conio.h \
|
||||||
|
dir.c \
|
||||||
|
fexist.c fisdir.c \
|
||||||
|
fparseln.c fsendfile.c \
|
||||||
|
ifconfig.c lfile.c \
|
||||||
|
makepath.c progress.c \
|
||||||
|
pidfile.c pidfilefn.c \
|
||||||
|
reallocarray.c rsync.c \
|
||||||
|
strlcpy.c strlcat.c strtonum.c \
|
||||||
|
strdupa.h strndupa.h strnlen.h \
|
||||||
|
tempfile.c which.c \
|
||||||
|
lite.h strlite.h \
|
||||||
|
queue.h tree.h
|
||||||
|
|
||||||
|
|
||||||
|
## Distribute these header files in the <lite/...> name space
|
||||||
|
pkgincludedir = $(includedir)/lite
|
||||||
|
pkginclude_HEADERS = lite.h queue.h conio.h tree.h strlite.h strdupa.h strndupa.h strnlen.h
|
||||||
File renamed without changes.
+83
@@ -0,0 +1,83 @@
|
|||||||
|
/* A conio.h like implementation for VTANSI displays.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2009-2017 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <poll.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void initscr(int *row, int *col)
|
||||||
|
{
|
||||||
|
if (!row || !col)
|
||||||
|
return;
|
||||||
|
|
||||||
|
#if defined(TCSANOW) && defined(POLLIN)
|
||||||
|
struct termios tc, saved;
|
||||||
|
struct pollfd fd = { STDIN_FILENO, POLLIN, 0 };
|
||||||
|
|
||||||
|
if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) {
|
||||||
|
*row = 24;
|
||||||
|
*col = 80;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Disable echo to terminal while probing */
|
||||||
|
tcgetattr(STDOUT_FILENO, &tc);
|
||||||
|
saved = tc;
|
||||||
|
tc.c_cflag |= (CLOCAL | CREAD);
|
||||||
|
tc.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||||
|
tcsetattr(STDOUT_FILENO, TCSANOW, &tc);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Save cursor pos+attr
|
||||||
|
* Diable top+bottom margins
|
||||||
|
* Set cursor at the far bottom,right pos
|
||||||
|
* Query term for resulting pos
|
||||||
|
*/
|
||||||
|
fprintf(stdout, "\e7" "\e[r" "\e[999;999H" "\e[6n");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wait here for terminal to echo back \e[row,lineR ...
|
||||||
|
*/
|
||||||
|
if (poll(&fd, 1, 300) <= 0 || scanf("\e[%d;%dR", row, col) != 2) {
|
||||||
|
*row = 24;
|
||||||
|
*col = 80;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Restore above saved cursor pos+attr
|
||||||
|
*/
|
||||||
|
fprintf(stdout, "\e8");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
/* Restore terminal */
|
||||||
|
tcsetattr(STDOUT_FILENO, TCSANOW, &saved);
|
||||||
|
|
||||||
|
return;
|
||||||
|
#else
|
||||||
|
*row = 24;
|
||||||
|
*col = 80;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
+31
-18
@@ -1,6 +1,6 @@
|
|||||||
/* A conio.h like implementation for VTANSI displays.
|
/* A conio.h like implementation for VTANSI displays.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009-2013 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2009-2017 Joachim Nilsson <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -48,29 +48,42 @@
|
|||||||
#define LIGHTCYAN 0x16
|
#define LIGHTCYAN 0x16
|
||||||
#define WHITE 0x17
|
#define WHITE 0x17
|
||||||
|
|
||||||
/* Esc[2JEsc[1;1H - Clear screen and move cursor to 1,1 (upper left) pos. */
|
#ifndef SCREEN_WIDTH
|
||||||
#define clrscr() fputs ("\e[2J\e[1;1H", stdout)
|
#define SCREEN_WIDTH 80 /* Override using, e.g. #define SCREEN_WIDTH tty_width() */
|
||||||
/* Esc[K - Erases from the current cursor position to the end of the current line. */
|
#endif
|
||||||
#define clreol() fputs ("\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 */
|
/* Esc[2JEsc[1;1H - Clear screen and move cursor to 1,1 (upper left) pos. */
|
||||||
#define __set_gm(attr,color,val) \
|
#define clrscr() fputs("\033[2J\033[1;1H", stdout)
|
||||||
if (!color) \
|
/* Esc[K - Erases from the current cursor position to the end of the current line. */
|
||||||
printf("\e[%dm", attr); \
|
#define clreol() fputs("\033[K", stdout)
|
||||||
|
/* Esc[2K - Erases the entire current line. */
|
||||||
|
#define delline() fputs("\033[2K", stdout)
|
||||||
|
/* Esc[Line;ColumnH - Moves the cursor to the specified position (coordinates) */
|
||||||
|
#define gotoxy(x,y) fprintf(stdout, "\033[%d;%dH", y, x)
|
||||||
|
/* Esc[?25l (lower case L) - Hide Cursor */
|
||||||
|
#define hidecursor() fputs("\033[?25l", stdout)
|
||||||
|
/* Esc[?25h (lower case H) - Show Cursor */
|
||||||
|
#define showcursor() fputs("\033[?25h", stdout)
|
||||||
|
|
||||||
|
/* Esc[Value;...;Valuem - Set Graphics Mode (attr, color, val) */
|
||||||
|
#define __set_gm(a,c,v) \
|
||||||
|
if (!c) \
|
||||||
|
fprintf(stdout, "\033[%dm", a); \
|
||||||
else \
|
else \
|
||||||
printf("\e[%d;%dm", color & 0x10 ? 1 : 0, (color & 0xF) + val)
|
fprintf(stdout, "\033[%d;%dm", c & 0x10 ? 1 : 0, (c & 0xF) + v)
|
||||||
#define textattr(attr) __set_gm(attr, 0, 0)
|
#define textattr(attr) __set_gm(attr, 0, 0)
|
||||||
#define textcolor(color) __set_gm(RESETATTR, color, 30)
|
#define textcolor(color) __set_gm(RESETATTR, color, 30)
|
||||||
#define textbackground(color) __set_gm(RESETATTR, color, 40)
|
#define textbackground(color) __set_gm(RESETATTR, color, 40)
|
||||||
|
|
||||||
|
/* Print table heading @line to @fp, with optional leading newline */
|
||||||
|
static inline void printheader(FILE *fp, const char *line, int nl)
|
||||||
|
{
|
||||||
|
fprintf(fp ?: stdout,
|
||||||
|
"%s\033[7m%s%*s\033[0m\n",
|
||||||
|
nl ? "\n" : "",
|
||||||
|
line, SCREEN_WIDTH - (int)strlen(line), "");
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* CONIO_H_ */
|
#endif /* CONIO_H_ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,26 +80,46 @@ static ssize_t do_copy(int in, int out, size_t num, char *buffer, size_t len)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_mtime(int in, int out)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
struct timespec tv[2];
|
||||||
|
|
||||||
|
fstat(in, &st);
|
||||||
|
tv[0] = st.st_atim;
|
||||||
|
tv[1] = st.st_mtim;
|
||||||
|
futimens(out, tv);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* copyfile - Copy a file to another.
|
* copyfile - Copy a file to another.
|
||||||
* @src: Full path name to source file.
|
* @src: Full path name to source file.
|
||||||
* @dst: Full path name to target file.
|
* @dst: Full path name to target file.
|
||||||
* @len: Number of bytes to copy, zero (0) for entire file.
|
* @len: Number of bytes to copy, zero (0) for entire file.
|
||||||
* @sym: Should symlinks be recreated (1) or followed (0)
|
* @opt: An option mask of %LITE_FOPT_COPYFILE_SYM, %LITE_FOPT_KEEP_MTIME
|
||||||
*
|
*
|
||||||
* This is a C implementation of the command line cp(1) utility. It is one
|
* This is a C implementation of the command line cp(1) utility. It is one
|
||||||
* of the classic missing links in the UNIX C library. This version is from
|
* of the classic missing links in the UNIX C library. This version is from
|
||||||
* the finit project, http://helllabs.org/finit/, which is a reimplementation
|
* the finit project, http://helllabs.org/finit/, which is a reimplementation
|
||||||
* of fastinit for the Asus EeePC.
|
* of fastinit for the Asus EeePC.
|
||||||
*
|
*
|
||||||
|
* The @opt field replaces the @sym argument in previous releases and
|
||||||
|
* works as follows. To maintain backwards compatibility with @sym
|
||||||
|
* the %LITE_FOPT_COPYFILE_SYM maintains a value of 1:
|
||||||
|
*
|
||||||
|
* %LITE_FOPT_COPYFILE_SYM: Recreate symlink or follow to copy target
|
||||||
|
* %LITE_FOPT_KEEP_MTIME: Preserve modification time
|
||||||
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* The number of bytes copied, zero may be error (check errno!), but it
|
* The number of bytes copied, zero may be error (check errno!), but it
|
||||||
* may also indicate that @src was empty. If @src is a directory @errno
|
* may also indicate that @src was empty. If @src is a directory @errno
|
||||||
* will be set to %EISDIR since copyfile() is not recursive.
|
* will be set to %EISDIR since copyfile() is not recursive.
|
||||||
*/
|
*/
|
||||||
ssize_t copyfile(char *src, char *dst, int len, int sym)
|
ssize_t copyfile(char *src, char *dst, int len, int opt)
|
||||||
{
|
{
|
||||||
char *buffer;
|
char *buffer;
|
||||||
|
int sym = (opt & LITE_FOPT_COPYFILE_SYM) != 0;
|
||||||
|
int keep_mtim = (opt & LITE_FOPT_KEEP_MTIME) != 0;
|
||||||
int in, out, isdir = 0, saved_errno = 0;
|
int in, out, isdir = 0, saved_errno = 0;
|
||||||
size_t num;
|
size_t num;
|
||||||
ssize_t size = 0;
|
ssize_t size = 0;
|
||||||
@@ -155,7 +175,7 @@ ssize_t copyfile(char *src, char *dst, int len, int sym)
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
out = open(dst, O_WRONLY | O_CREAT | O_TRUNC, fmode(src));
|
out = open(dst, O_WRONLY | O_CREAT | O_TRUNC, st.st_mode);
|
||||||
if (out < 0) {
|
if (out < 0) {
|
||||||
close(in);
|
close(in);
|
||||||
saved_errno = errno;
|
saved_errno = errno;
|
||||||
@@ -165,6 +185,8 @@ ssize_t copyfile(char *src, char *dst, int len, int sym)
|
|||||||
size = do_copy(in, out, num, buffer, BUFSIZ);
|
size = do_copy(in, out, num, buffer, BUFSIZ);
|
||||||
if (!size && errno)
|
if (!size && errno)
|
||||||
saved_errno = errno;
|
saved_errno = errno;
|
||||||
|
else if (keep_mtim)
|
||||||
|
set_mtime(in, out);
|
||||||
|
|
||||||
close(out);
|
close(out);
|
||||||
close(in);
|
close(in);
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -24,11 +24,6 @@
|
|||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
|
||||||
__RCSID("$NetBSD: fparseln.c,v 1.10 2009/10/21 01:07:45 snj Exp $");
|
|
||||||
#endif /* LIBC_SCCS and not lint */
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -36,7 +31,9 @@ __RCSID("$NetBSD: fparseln.c,v 1.10 2009/10/21 01:07:45 snj Exp $");
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "lite.h"
|
#include "lite.h"
|
||||||
|
|
||||||
|
#ifndef _DIAGASSERT
|
||||||
#define _DIAGASSERT(t)
|
#define _DIAGASSERT(t)
|
||||||
|
#endif
|
||||||
|
|
||||||
static int isescaped(const char *, const char *, int);
|
static int isescaped(const char *, const char *, int);
|
||||||
|
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
+48
-20
@@ -25,7 +25,7 @@
|
|||||||
#ifndef LITE_H_
|
#ifndef LITE_H_
|
||||||
#define LITE_H_
|
#define LITE_H_
|
||||||
|
|
||||||
#include <err.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, INT32_MAX, etc. */
|
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, INT32_MAX, etc. */
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -43,6 +43,13 @@
|
|||||||
#define FPARSELN_UNESCREST 0x08
|
#define FPARSELN_UNESCREST 0x08
|
||||||
#define FPARSELN_UNESCALL 0x0f
|
#define FPARSELN_UNESCALL 0x0f
|
||||||
|
|
||||||
|
/*
|
||||||
|
* copyfile() and rsync() option flags
|
||||||
|
*/
|
||||||
|
#define LITE_FOPT_RSYNC_DELETE 0x01
|
||||||
|
#define LITE_FOPT_COPYFILE_SYM 0x01
|
||||||
|
#define LITE_FOPT_KEEP_MTIME 0x02
|
||||||
|
|
||||||
typedef struct lfile lfile_t;
|
typedef struct lfile lfile_t;
|
||||||
|
|
||||||
char *chomp (char *str);
|
char *chomp (char *str);
|
||||||
@@ -50,10 +57,9 @@ char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
|
|||||||
|
|
||||||
int fexist (char *file);
|
int fexist (char *file);
|
||||||
int fisdir (const char *file);
|
int fisdir (const char *file);
|
||||||
mode_t fmode (char *file);
|
|
||||||
|
|
||||||
FILE *tempfile (void);
|
FILE *tempfile (void);
|
||||||
ssize_t copyfile (char *src, char *dst, int len, int sym);
|
ssize_t copyfile (char *src, char *dst, int len, int opt);
|
||||||
int movefile (char *src, char *dst);
|
int movefile (char *src, char *dst);
|
||||||
int fcopyfile (FILE *src, FILE *dst);
|
int fcopyfile (FILE *src, FILE *dst);
|
||||||
ssize_t fsendfile (FILE *src, FILE *dst, size_t len);
|
ssize_t fsendfile (FILE *src, FILE *dst, size_t len);
|
||||||
@@ -67,11 +73,11 @@ char *lfgetkey (lfile_t *lf, char *key);
|
|||||||
int lfgetint (lfile_t *lf, char *key);
|
int lfgetint (lfile_t *lf, char *key);
|
||||||
int fgetint (char *file, char *sep, char *key);
|
int fgetint (char *file, char *sep, char *key);
|
||||||
|
|
||||||
int mkpath (char *dir, mode_t mode);
|
int mkpath (const char *dir, mode_t mode);
|
||||||
int makepath (char *dir);
|
int makepath (const char *dir);
|
||||||
|
|
||||||
int dir (const char *dir, const char *type, int (*filter) (const char *file), char ***list, int strip);
|
int dir (const char *dir, const char *type, int (*filter) (const char *file), char ***list, int strip);
|
||||||
int rsync (char *src, char *dst, int delete, int (*filter) (const char *file));
|
int rsync (char *src, char *dst, int opt, int (*filter) (const char *file));
|
||||||
|
|
||||||
int pidfile (const char *basename);
|
int pidfile (const char *basename);
|
||||||
int pidfile_signal(const char *pidfile, int signal);
|
int pidfile_signal(const char *pidfile, int signal);
|
||||||
@@ -80,23 +86,50 @@ pid_t pidfile_poll (const char *pidfile);
|
|||||||
|
|
||||||
void *reallocarray(void *optr, size_t nmemb, size_t size);
|
void *reallocarray(void *optr, size_t nmemb, size_t size);
|
||||||
|
|
||||||
int tree(char *path, int show_perms);
|
|
||||||
|
|
||||||
void progress (int percent, int max_width);
|
void progress (int percent, int max_width);
|
||||||
void progress_simple(int percent);
|
void progress_simple(int percent);
|
||||||
|
|
||||||
|
char *which (const char *cmd);
|
||||||
|
int whichp (const char *cmd);
|
||||||
|
|
||||||
#ifndef touch
|
#ifndef touch
|
||||||
# define touch(x) do { if (mknod((x), S_IFREG|0644, 0) && errno != EEXIST) warn("Failed creating %s", x); } while (0)
|
#include <sys/stat.h> /* utimensat() */
|
||||||
|
#include <sys/time.h> /* utimensat() on *BSD */
|
||||||
|
static inline int touch(const char *path)
|
||||||
|
{
|
||||||
|
if (mknod((path), S_IFREG|0644, 0)) {
|
||||||
|
if (errno == EEXIST)
|
||||||
|
return utimensat(0, path, NULL, 0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifndef makedir
|
#ifndef makedir
|
||||||
# define makedir(x, p) do { if (mkdir(x, p) && errno != EEXIST) warn("Failed creating directory %s", x); } while (0)
|
static inline int makedir(const char *path, mode_t mode)
|
||||||
|
{
|
||||||
|
if (mkdir(path, mode) && errno != EEXIST)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifndef makefifo
|
#ifndef makefifo
|
||||||
# define makefifo(x, p) do { if (mkfifo(x, p) && errno != EEXIST) warn("Failed creating FIFO %s", x); } while (0)
|
static inline int makefifo(const char *path, mode_t mode)
|
||||||
|
{
|
||||||
|
if (mkfifo(path, mode) && errno != EEXIST)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifndef erase
|
#ifndef erase
|
||||||
# define erase(x) do { if (remove(x) && errno != ENOENT) warn("Failed removing %s", x); } while (0)
|
static inline int erase(const char *path)
|
||||||
|
{
|
||||||
|
if (remove(path) && errno != ENOENT)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef chardev
|
#ifndef chardev
|
||||||
# define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min)))
|
# define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min)))
|
||||||
#endif
|
#endif
|
||||||
@@ -130,11 +163,6 @@ void progress_simple(int percent);
|
|||||||
#define NELEMS(array) (sizeof(array) / sizeof(array[0]))
|
#define NELEMS(array) (sizeof(array) / sizeof(array[0]))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Mark a function variable as unused, useful for generic callbacks */
|
|
||||||
#ifndef UNUSED
|
|
||||||
#define UNUSED(x) UNUSED_ ## x __attribute__ ((unused))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Does directory end with a slash? */
|
/* Does directory end with a slash? */
|
||||||
static inline int fisslashdir(char *dir)
|
static inline int fisslashdir(char *dir)
|
||||||
{
|
{
|
||||||
@@ -148,9 +176,9 @@ static inline int fisslashdir(char *dir)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Compat */
|
/* Compat */
|
||||||
#define copy_filep(src,dst) fcopyfile(src,dst)
|
#define copy_filep(src, dst) fcopyfile(src, dst)
|
||||||
#define pidfile_read_pid(file) pifile_read(file)
|
#define pidfile_read_pid(file) pifile_read(file)
|
||||||
#define signal_pidfile(file,signo) pidfile_signal(file,signo)
|
#define signal_pidfile(file, signo) pidfile_signal(file, signo)
|
||||||
|
|
||||||
#endif /* LITE_H_ */
|
#endif /* LITE_H_ */
|
||||||
|
|
||||||
@@ -29,13 +29,13 @@
|
|||||||
* Returns:
|
* Returns:
|
||||||
* POSIX OK(0) on success, otherwise -1 with @errno set.
|
* POSIX OK(0) on success, otherwise -1 with @errno set.
|
||||||
*/
|
*/
|
||||||
int mkpath(char *dir, mode_t mode)
|
int mkpath(const char *dir, mode_t mode)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return 1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stat(dir, &sb))
|
if (!stat(dir, &sb))
|
||||||
@@ -50,13 +50,18 @@ int mkpath(char *dir, mode_t mode)
|
|||||||
* makepath - Create all components of the specified directory.
|
* makepath - Create all components of the specified directory.
|
||||||
* @dir: Directory to create.
|
* @dir: Directory to create.
|
||||||
*
|
*
|
||||||
|
* Comment:
|
||||||
|
* It is recommended to use mkpath() over this function since it has
|
||||||
|
* the @mode argument while this function instead default ot 0777,
|
||||||
|
* which in most cases is insecure.
|
||||||
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* POSIX OK (0) on success, otherwise -1 and errno set appropriately.
|
* POSIX OK (0) on success, otherwise -1 and errno set appropriately.
|
||||||
* This function returns EINVAL on bad argument, or ENOMEM when it
|
* This function returns EINVAL on bad argument, or ENOMEM when it
|
||||||
* fails allocating temporary memory. For other error codes see the
|
* fails allocating temporary memory. For other error codes see the
|
||||||
* mkdir() syscall description.
|
* mkdir() syscall description.
|
||||||
*/
|
*/
|
||||||
int makepath(char *dir)
|
int makepath(const char *dir)
|
||||||
{
|
{
|
||||||
return mkpath(dir, 0777);
|
return mkpath(dir, 0777);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Updated by troglobit for libite/finit/uftpd projects 2016/03/19 */
|
/* 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 $ */
|
/* $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 $ */
|
/* $NetBSD: pidfile.c,v 1.4 2001/02/19 22:43:42 cgd Exp $ */
|
||||||
|
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/stat.h> /* utimensat() */
|
#include <sys/stat.h> /* utimensat() */
|
||||||
|
#include <sys/time.h> /* utimensat() on *BSD */
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
@@ -41,7 +42,7 @@
|
|||||||
|
|
||||||
#ifndef pidfile
|
#ifndef pidfile
|
||||||
static char *pidfile_path = NULL;
|
static char *pidfile_path = NULL;
|
||||||
static pid_t pidfile_pid;
|
static pid_t pidfile_pid = 0;
|
||||||
|
|
||||||
static void pidfile_cleanup(void);
|
static void pidfile_cleanup(void);
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ pidfile(const char *basename)
|
|||||||
atexit_already = 0;
|
atexit_already = 0;
|
||||||
|
|
||||||
if (pidfile_path != NULL) {
|
if (pidfile_path != NULL) {
|
||||||
if (pid == pidfile_pid) {
|
if (!access(pidfile_path, R_OK) && pid == pidfile_pid) {
|
||||||
utimensat(0, pidfile_path, NULL, 0);
|
utimensat(0, pidfile_path, NULL, 0);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -74,8 +75,13 @@ pidfile(const char *basename)
|
|||||||
atexit_already = 1;
|
atexit_already = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asprintf(&pidfile_path, "%s%s.pid", __pidfile_path, basename) == -1)
|
if (basename[0] != '/') {
|
||||||
return (-1);
|
if (asprintf(&pidfile_path, "%s%s.pid", __pidfile_path, basename) == -1)
|
||||||
|
return (-1);
|
||||||
|
} else {
|
||||||
|
if (asprintf(&pidfile_path, "%s", basename) == -1)
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
if ((f = fopen(pidfile_path, "w")) == NULL) {
|
if ((f = fopen(pidfile_path, "w")) == NULL) {
|
||||||
save_errno = errno;
|
save_errno = errno;
|
||||||
@@ -95,6 +101,7 @@ pidfile(const char *basename)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
(void) fclose(f);
|
(void) fclose(f);
|
||||||
|
__pidfile_name = pidfile_path;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* LITE extension, no need to set up another atexit() handler
|
* LITE extension, no need to set up another atexit() handler
|
||||||
@@ -113,7 +120,6 @@ pidfile(const char *basename)
|
|||||||
errno = save_errno;
|
errno = save_errno;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
__pidfile_name = pidfile_path;
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -121,8 +127,10 @@ pidfile(const char *basename)
|
|||||||
static void
|
static void
|
||||||
pidfile_cleanup(void)
|
pidfile_cleanup(void)
|
||||||
{
|
{
|
||||||
|
if (pidfile_path != NULL && pidfile_pid == getpid()) {
|
||||||
if (pidfile_path != NULL && pidfile_pid == getpid())
|
|
||||||
(void) unlink(pidfile_path);
|
(void) unlink(pidfile_path);
|
||||||
|
free(pidfile_path);
|
||||||
|
pidfile_path = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+54
-20
@@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h> /* AT_* macros */
|
||||||
#include <stdlib.h> /* NULL, free() */
|
#include <stdlib.h> /* NULL, free() */
|
||||||
#include <string.h> /* strlen() */
|
#include <string.h> /* strlen() */
|
||||||
#include <strings.h> /* rindex() */
|
#include <strings.h> /* rindex() */
|
||||||
@@ -26,16 +27,17 @@
|
|||||||
|
|
||||||
#include "lite.h"
|
#include "lite.h"
|
||||||
|
|
||||||
static int copy(char *src, char *dst);
|
static int copy(char *src, char *dst, int opt);
|
||||||
static int mdir(char *buf, size_t buf_len, char *dir, char *name, mode_t mode);
|
static int mdir(char *buf, size_t buf_len, char *dir, char *name, struct stat *st);
|
||||||
static int prune(char *dst, char **new_files, int new_num);
|
static int prune(char *dst, char **new_files, int new_num);
|
||||||
|
static int set_mtime(char *fn, struct stat *st);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rsync - Synchronize contents and optionally remove non-existing backups
|
* rsync - Synchronize contents and optionally remove non-existing backups
|
||||||
* @src: Source directory
|
* @src: Source directory
|
||||||
* @dst: Destination directory
|
* @dst: Destination directory
|
||||||
* @delete: Prune files from @dst that no longer exist in @src.
|
* @opt: An option mask of %LITE_FOPT_RSYNC_DELETE, %LITE_FOPT_KEEP_MTIME
|
||||||
* @filter: Optional filtering function for source directory.
|
* @filter: Optional filtering function for source directory.
|
||||||
*
|
*
|
||||||
* This is a miniature implementation of the famous rsync for local use only.
|
* This is a miniature implementation of the famous rsync for local use only.
|
||||||
@@ -44,19 +46,29 @@ static int prune(char *dst, char **new_files, int new_num);
|
|||||||
* files removed from src since last backup are pruned from the destination
|
* files removed from src since last backup are pruned from the destination
|
||||||
* (backup) directory.
|
* (backup) directory.
|
||||||
*
|
*
|
||||||
* The filter callback, @filter, if provided, is used to determine what files to
|
* The @opt parameter to rsync() is an option mask for the most common
|
||||||
* include from the source directory when backing up. If a file is to be skipped
|
* rsync(1) options. Previously this argument was called @delete and
|
||||||
* the callback should simply return zero.
|
* to maintain backwards compatibility the value 1 is reserved:
|
||||||
|
*
|
||||||
|
* %LITE_FOPT_RSYNC_DELETE: Prune files from @dst that no longer exist in @src.
|
||||||
|
* %LITE_FOPT_KEEP_MTIME: Preserve modification time
|
||||||
|
*
|
||||||
|
* The filter callback, @filter, if provided, is used to determine what
|
||||||
|
* files to include from the source directory when backing up. If a
|
||||||
|
* file is to be skipped the callback should simply return zero.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* POSIX OK(0), or non-zero with @errno set on error.
|
* POSIX OK(0), or non-zero with @errno set on error.
|
||||||
*/
|
*/
|
||||||
int rsync(char *src, char *dst, int delete, int (*filter) (const char *file))
|
int rsync(char *src, char *dst, int opt, int (*filter)(const char *file))
|
||||||
{
|
{
|
||||||
char source[256];
|
char source[256];
|
||||||
char dest[256];
|
char dest[256];
|
||||||
int i = 0, num = 0, result = 0;
|
int delete = (opt & LITE_FOPT_RSYNC_DELETE) != 0;
|
||||||
|
int keep_mtim = (opt & LITE_FOPT_KEEP_MTIME);
|
||||||
|
int i = 0, num = 0, result = 0, do_mtim = 0;
|
||||||
char **files; /* Array of file names. */
|
char **files; /* Array of file names. */
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
if (!fisdir(dst))
|
if (!fisdir(dst))
|
||||||
makedir(dst, 0755);
|
makedir(dst, 0755);
|
||||||
@@ -65,7 +77,7 @@ int rsync(char *src, char *dst, int delete, int (*filter) (const char *file))
|
|||||||
if (!fexist(src))
|
if (!fexist(src))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (copy(src, dst))
|
if (copy(src, dst, keep_mtim))
|
||||||
result++;
|
result++;
|
||||||
|
|
||||||
return errno;
|
return errno;
|
||||||
@@ -80,9 +92,13 @@ int rsync(char *src, char *dst, int delete, int (*filter) (const char *file))
|
|||||||
else
|
else
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
if (mdir(dest, sizeof(dest), dst, ptr, fmode(src)))
|
if (stat(src, &st))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (mdir(dest, sizeof(dest), dst, ptr, &st))
|
||||||
return 1;
|
return 1;
|
||||||
dst = dest;
|
dst = dest;
|
||||||
|
do_mtim = keep_mtim;
|
||||||
}
|
}
|
||||||
|
|
||||||
num = dir(src, "", filter, &files, 0);
|
num = dir(src, "", filter, &files, 0);
|
||||||
@@ -91,21 +107,31 @@ int rsync(char *src, char *dst, int delete, int (*filter) (const char *file))
|
|||||||
snprintf(source, sizeof(source), "%s%s%s", src, fisslashdir(src) ? "" : "/", files[i]);
|
snprintf(source, sizeof(source), "%s%s%s", src, fisslashdir(src) ? "" : "/", files[i]);
|
||||||
if (fisdir(source)) {
|
if (fisdir(source)) {
|
||||||
char dst2[256];
|
char dst2[256];
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
strcat(source, "/");
|
strcat(source, "/");
|
||||||
if (mdir (dst2, sizeof(dst2), dst, files[i], fmode(source))) {
|
if (stat(source, &st))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (mdir(dst2, sizeof(dst2), dst, files[i], &st)) {
|
||||||
result++;
|
result++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
rsync(source, dst2, delete, filter);
|
rsync(source, dst2, opt, filter);
|
||||||
|
if (keep_mtim)
|
||||||
|
set_mtime(dst2, &st);
|
||||||
|
|
||||||
continue; /* Next file/dir in @src to copy... */
|
continue; /* Next file/dir in @src to copy... */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy(source, dst))
|
if (copy(source, dst, keep_mtim))
|
||||||
result++;
|
result++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (do_mtim)
|
||||||
|
set_mtime(dest, &st);
|
||||||
|
|
||||||
/* We ignore any errors from the pruning, that phase albeit useful is only
|
/* We ignore any errors from the pruning, that phase albeit useful is only
|
||||||
* cosmetic. --Jocke 2011-03-24 */
|
* cosmetic. --Jocke 2011-03-24 */
|
||||||
if (delete)
|
if (delete)
|
||||||
@@ -120,11 +146,9 @@ int rsync(char *src, char *dst, int delete, int (*filter) (const char *file))
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int copy(char *src, char *dst)
|
static int copy(char *src, char *dst, int opt)
|
||||||
{
|
{
|
||||||
errno = 0;
|
copyfile(src, dst, 0, opt | LITE_FOPT_COPYFILE_SYM);
|
||||||
|
|
||||||
copyfile(src, dst, 0, 1);
|
|
||||||
if (errno) {
|
if (errno) {
|
||||||
if (errno != EEXIST)
|
if (errno != EEXIST)
|
||||||
return 1;
|
return 1;
|
||||||
@@ -136,10 +160,10 @@ static int copy(char *src, char *dst)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Creates dir/name @mode ... skipping / if dir already ends so. */
|
/* Creates dir/name @mode ... skipping / if dir already ends so. */
|
||||||
static int mdir(char *buf, size_t buf_len, char *dir, char *name, mode_t mode)
|
static int mdir(char *buf, size_t buf_len, char *dir, char *name, struct stat *st)
|
||||||
{
|
{
|
||||||
snprintf(buf, buf_len, "%s%s%s/", dir, fisslashdir(dir) ? "" : "/", name);
|
snprintf(buf, buf_len, "%s%s%s", dir, fisslashdir(dir) ? "" : "/", name);
|
||||||
if (mkdir(buf, mode)) {
|
if (mkdir(buf, st->st_mode)) {
|
||||||
if (EEXIST != errno)
|
if (EEXIST != errno)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@@ -193,6 +217,16 @@ static int prune(char *dst, char **new_files, int new_num)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int set_mtime(char *fn, struct stat *st)
|
||||||
|
{
|
||||||
|
struct timespec tv[2];
|
||||||
|
|
||||||
|
tv[0] = st->st_atim;
|
||||||
|
tv[1] = st->st_mtim;
|
||||||
|
|
||||||
|
return utimensat(AT_FDCWD, fn, tv, AT_SYMLINK_NOFOLLOW);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* indent-tabs-mode: t
|
* indent-tabs-mode: t
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -45,7 +45,7 @@ FILE *tempfile(void)
|
|||||||
if (-1 == fd)
|
if (-1 == fd)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return fdopen(fd, "rw");
|
return fdopen(fd, "w+");
|
||||||
#else
|
#else
|
||||||
return tmpfile(); /* Fallback on older GLIBC/Linux and actual UNIX systems */
|
return tmpfile(); /* Fallback on older GLIBC/Linux and actual UNIX systems */
|
||||||
#endif
|
#endif
|
||||||
File renamed without changes.
+127
@@ -0,0 +1,127 @@
|
|||||||
|
/* C implementation of UNIX which(1)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017 Joachim Nilsson <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h> /* snprintf() */
|
||||||
|
#include <stdlib.h> /* realloc(), free() */
|
||||||
|
#include <string.h> /* strtok_r() */
|
||||||
|
#include <unistd.h> /* access() */
|
||||||
|
|
||||||
|
/* Strip any arguments in "/path/to/bin --some args", modifies input string */
|
||||||
|
static char *strip_args(char *path)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
if (!path)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/* Find first whitespace (space/tab/etc.) */
|
||||||
|
while (path[i] && !isspace(path[i]))
|
||||||
|
i++;
|
||||||
|
path[i] = 0;
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Like which(1), returns a malloc'ed path to cmd on success, or NULL
|
||||||
|
*/
|
||||||
|
char *which(const char *cmd)
|
||||||
|
{
|
||||||
|
size_t pathlen = 0;
|
||||||
|
char *ptr, *tok, *env, *path = NULL;
|
||||||
|
|
||||||
|
if (!cmd) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd[0] == '/') {
|
||||||
|
path = strip_args(strdup(cmd));
|
||||||
|
if (!path)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!access(path, X_OK))
|
||||||
|
return path;
|
||||||
|
|
||||||
|
if (path)
|
||||||
|
free(path);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr = getenv("PATH");
|
||||||
|
if (!ptr)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
env = strdup(ptr);
|
||||||
|
if (!env)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
tok = strtok_r(env, ":", &ptr);
|
||||||
|
while (tok) {
|
||||||
|
size_t len = strlen(tok) + strlen(cmd) + 2;
|
||||||
|
|
||||||
|
if (pathlen < len) {
|
||||||
|
path = realloc(path, len);
|
||||||
|
if (!path) {
|
||||||
|
free(env);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
pathlen = len;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(path, pathlen, "%s/%s", tok, cmd);
|
||||||
|
path = strip_args(path);
|
||||||
|
if (!path || !access(path, X_OK)) {
|
||||||
|
free(env);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
tok = strtok_r(NULL, ":", &ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path)
|
||||||
|
free(path);
|
||||||
|
free(env);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Like which(), above, but only answers TRUE(1)/FALSE(0)
|
||||||
|
*/
|
||||||
|
int whichp(const char *cmd)
|
||||||
|
{
|
||||||
|
char *path;
|
||||||
|
|
||||||
|
path = which(cmd);
|
||||||
|
if (path) {
|
||||||
|
free(path);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -12,4 +12,6 @@ pidfile
|
|||||||
progress
|
progress
|
||||||
rsync
|
rsync
|
||||||
tempfile
|
tempfile
|
||||||
|
touch
|
||||||
tree
|
tree
|
||||||
|
which
|
||||||
+6
-4
@@ -11,14 +11,16 @@ TESTS += fsendfile
|
|||||||
TESTS += lfile
|
TESTS += lfile
|
||||||
TESTS += makepath
|
TESTS += makepath
|
||||||
TESTS += pidfile
|
TESTS += pidfile
|
||||||
|
TESTS += touch
|
||||||
TESTS += progress
|
TESTS += progress
|
||||||
TESTS += rsync
|
TESTS += rsync
|
||||||
TESTS += tempfile
|
TESTS += tempfile
|
||||||
TESTS += tree
|
TESTS += which
|
||||||
|
|
||||||
check_PROGRAMS = $(TESTS)
|
check_PROGRAMS = $(TESTS)
|
||||||
|
|
||||||
# Ignore warnings about unused result, in e.g. write()
|
# Ignore warnings about unused result, in e.g. write()
|
||||||
CFLAGS = -W -Wall -Wextra -Wno-unused-result
|
CFLAGS += -Wno-unused-result
|
||||||
CPPFLAGS = -D_GNU_SOURCE
|
CPPFLAGS += -D_GNU_SOURCE
|
||||||
LDADD = -L../ ../libite.la
|
LDADD = -L../src/ ../src/libite.la
|
||||||
|
LDFLAGS += -static
|
||||||
+6
-3
@@ -6,7 +6,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "../lite.h"
|
#include "../src/conio.h"
|
||||||
|
#include "../src/lite.h"
|
||||||
|
|
||||||
|
#define PRINT(args...) if (verbose) printf(args)
|
||||||
|
|
||||||
#define fail_unless(test) \
|
#define fail_unless(test) \
|
||||||
do { \
|
do { \
|
||||||
@@ -25,8 +28,8 @@ static inline int test(int result, const char *fmt, ...)
|
|||||||
char buf[80];
|
char buf[80];
|
||||||
size_t len;
|
size_t len;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
const char success[] = " \e[1m[ OK ]\e[0m\n";
|
const char success[] = " \033[1m[ OK ]\033[0m\n";
|
||||||
const char failure[] = " \e[7m[FAIL]\e[0m\n";
|
const char failure[] = " \033[7m[FAIL]\033[0m\n";
|
||||||
const char dots[] = " .....................................................................";
|
const char dots[] = " .....................................................................";
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <err.h>
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <err.h>
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
|||||||
+38
-1
@@ -1,6 +1,43 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
|
#define FSTAB "/etc/fstab"
|
||||||
|
|
||||||
|
static int fstab(void)
|
||||||
|
{
|
||||||
|
int field = 1;
|
||||||
|
char *token;
|
||||||
|
lfile_t *lf;
|
||||||
|
|
||||||
|
lf = lfopen(FSTAB, " \t\n");
|
||||||
|
if (!lf) {
|
||||||
|
perror("Failed opening " FSTAB);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printheader(NULL, "FILE SYSTEM MOUNT OPTIONS D P", 0);
|
||||||
|
while ((token = lftok(lf))) {
|
||||||
|
if (field == 1)
|
||||||
|
printf("%-41s ", token);
|
||||||
|
if (field == 2)
|
||||||
|
printf("%-9s ", token);
|
||||||
|
if (field == 4)
|
||||||
|
printf("%-17s ", token);
|
||||||
|
if (field == 5)
|
||||||
|
printf("%d ", atoi(token));
|
||||||
|
if (field == 6) {
|
||||||
|
field = 0;
|
||||||
|
printf("%d\n", atoi(token));
|
||||||
|
}
|
||||||
|
|
||||||
|
field++;
|
||||||
|
}
|
||||||
|
|
||||||
|
lfclose(lf);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int val;
|
int val;
|
||||||
@@ -33,5 +70,5 @@ int main(void)
|
|||||||
}
|
}
|
||||||
printf("nobody is uid %d\n", val);
|
printf("nobody is uid %d\n", val);
|
||||||
|
|
||||||
return 0;
|
return fstab();
|
||||||
}
|
}
|
||||||
+22
-15
@@ -1,8 +1,10 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <libgen.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
int checkpath(char *dir)
|
int checkpath(const char *dir)
|
||||||
{
|
{
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
@@ -18,7 +20,7 @@ int checkpath(char *dir)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_makepath(char *dir)
|
int test_makepath(const char *dir)
|
||||||
{
|
{
|
||||||
int ret = makepath(dir);
|
int ret = makepath(dir);
|
||||||
|
|
||||||
@@ -34,27 +36,32 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int i, ret = 0;
|
int i, ret = 0;
|
||||||
char *list[] = {
|
char *list[] = {
|
||||||
"/tmp/tok/",
|
"/tmp/libite-test/tok/",
|
||||||
"/tmp/tok2",
|
"/tmp/libite-test/tok2",
|
||||||
"/tmp/ab",
|
"/tmp/libite-test/ab",
|
||||||
"/tmp/b",
|
"/tmp/libite-test/b",
|
||||||
"/tmp/a/",
|
"/tmp/libite-test/a/",
|
||||||
"/tmp/a/b",
|
"/tmp/libite-test/a/b",
|
||||||
"/tmp/a/c/",
|
"/tmp/libite-test/a/c/",
|
||||||
"../../sometestdir/arpa/inet",
|
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i = 0; list[i]; i++)
|
|
||||||
rmdir(list[i]);
|
|
||||||
|
|
||||||
printf("Testing makepath() ...\n");
|
printf("Testing makepath() ...\n");
|
||||||
|
mkdir("/tmp/libite-test", 0755);
|
||||||
|
|
||||||
for (i = 0; list[i] && !ret; i++)
|
for (i = 0; list[i] && !ret; i++)
|
||||||
ret |= test_makepath(list[i]);
|
ret |= test_makepath(list[i]);
|
||||||
|
|
||||||
printf("\nCleaning up ...\n");
|
printf("\nCleaning up ...\n");
|
||||||
for (i = 0; list[i]; i++)
|
system("rm -rf /tmp/libite-test");
|
||||||
rmdir(list[i]);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* compile-command: "make makepath && ./makepath"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
+78
-22
@@ -1,3 +1,4 @@
|
|||||||
|
#include <err.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@@ -5,25 +6,28 @@
|
|||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
extern char *__progname;
|
|
||||||
extern char *__pidfile_name;
|
extern char *__pidfile_name;
|
||||||
extern char *__pidfile_path;
|
extern char *__pidfile_path;
|
||||||
|
|
||||||
|
static char *ident;
|
||||||
|
static char *pidfile_arg;
|
||||||
static char PIDFILE[42];
|
static char PIDFILE[42];
|
||||||
static int verbose = 0;
|
static int verbose = 0;
|
||||||
static struct stat before, after;
|
static struct stat before, after;
|
||||||
|
|
||||||
static void sigterm_handler(int UNUSED(signo))
|
static void sigterm_handler(int signo)
|
||||||
{
|
{
|
||||||
if (verbose)
|
PRINT("Exiting ...\n");
|
||||||
printf("Exiting ...\n");
|
remove(PIDFILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sigalrm_handler(int UNUSED(signo))
|
static void sigalrm_handler(int signo)
|
||||||
{
|
{
|
||||||
pidfile(NULL);
|
PRINT("Calling pidfile(%s)\n", pidfile_arg ?: "NULL");
|
||||||
|
if (pidfile(pidfile_arg))
|
||||||
|
err(1, "failed creating1 %s", pidfile_arg);
|
||||||
if (!fexist(PIDFILE))
|
if (!fexist(PIDFILE))
|
||||||
err(1, "failed creating %s", PIDFILE);
|
err(1, "failed creating2 %s, created %s", PIDFILE, __pidfile_name);
|
||||||
stat(PIDFILE, &before);
|
stat(PIDFILE, &before);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,31 +39,40 @@ static int mtime()
|
|||||||
/* Must sleep a while here otherwise we execute too fast => no mtime change :-( */
|
/* Must sleep a while here otherwise we execute too fast => no mtime change :-( */
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
|
|
||||||
if (verbose)
|
PRINT("Calling pidfile() again to update mtime ...\n");
|
||||||
printf("Calling pidfile() again to update mtime ...\n");
|
if (pidfile(pidfile_arg))
|
||||||
pidfile(NULL);
|
err(1, "failed creating3 %s", pidfile_arg);
|
||||||
stat(PIDFILE, &after);
|
stat(PIDFILE, &after);
|
||||||
|
|
||||||
ret = timespec_newer(&after.st_mtim, &before.st_mtim);
|
ret = timespec_newer(&after.st_mtim, &before.st_mtim);
|
||||||
if (verbose) {
|
PRINT("Before: %s\n", timespec2str(&before.st_mtim, buf, sizeof(buf)));
|
||||||
printf("Before: %s\n", timespec2str(&before.st_mtim, buf, sizeof(buf)));
|
PRINT("After : %s\n", timespec2str(&after.st_mtim, buf, sizeof(buf)));
|
||||||
printf("After : %s\n", timespec2str(&after.st_mtim, buf, sizeof(buf)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return !ret;
|
return !ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int test_pidfile(char *arg0)
|
||||||
{
|
{
|
||||||
if (argc > 1 && !strcmp(argv[1], "-v"))
|
/* pidfile() argument */
|
||||||
verbose = 1;
|
pidfile_arg = arg0;
|
||||||
|
|
||||||
/* Override default _PATH_VARRUN in pidfile() */
|
/* Expected PID file name */
|
||||||
__pidfile_path = _PATH_TMP;
|
if (!arg0)
|
||||||
snprintf(PIDFILE, sizeof(PIDFILE), "%s%s.pid", __pidfile_path, __progname);
|
snprintf(PIDFILE, sizeof(PIDFILE), "%s%s.pid", __pidfile_path, ident);
|
||||||
|
else if (arg0[0] != '/')
|
||||||
|
snprintf(PIDFILE, sizeof(PIDFILE), "%s%s.pid", __pidfile_path, arg0);
|
||||||
|
else
|
||||||
|
snprintf(PIDFILE, sizeof(PIDFILE), "%s", arg0);
|
||||||
|
|
||||||
|
PRINT("Verifying pidfile(%s) ... PID: %d\n", PIDFILE, getpid());
|
||||||
|
|
||||||
|
/* Remove any lingering files from previous test runs */
|
||||||
|
remove(PIDFILE);
|
||||||
|
|
||||||
signal(SIGTERM, sigterm_handler);
|
signal(SIGTERM, sigterm_handler);
|
||||||
signal(SIGALRM, sigalrm_handler);
|
signal(SIGALRM, sigalrm_handler);
|
||||||
|
|
||||||
|
/* For signalling test */
|
||||||
alarm(1);
|
alarm(1);
|
||||||
|
|
||||||
return test(pidfile_poll(PIDFILE) != getpid(), "Testing pidfile_poll()")
|
return test(pidfile_poll(PIDFILE) != getpid(), "Testing pidfile_poll()")
|
||||||
@@ -67,7 +80,50 @@ int main(int argc, char *argv[])
|
|||||||
|| test(mtime(), "Testing mtime update of followup pidfile() call")
|
|| test(mtime(), "Testing mtime update of followup pidfile() call")
|
||||||
|| test(pidfile_signal(PIDFILE, SIGTERM), "Testing signalling ourselves")
|
|| test(pidfile_signal(PIDFILE, SIGTERM), "Testing signalling ourselves")
|
||||||
;
|
;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *progname(char *arg0)
|
||||||
|
{
|
||||||
|
char *nm;
|
||||||
|
|
||||||
|
nm = strrchr(arg0, '/');
|
||||||
|
if (nm)
|
||||||
|
nm++;
|
||||||
|
else
|
||||||
|
nm = arg0;
|
||||||
|
|
||||||
|
return nm;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
size_t i;
|
||||||
|
char *pidfiles[] = {
|
||||||
|
NULL,
|
||||||
|
"pidfile_test1",
|
||||||
|
"/var/tmp/pidfile_test2.pid",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (argc > 1 && !strcmp(argv[1], "-v"))
|
||||||
|
verbose = 1;
|
||||||
|
|
||||||
|
/* Override default _PATH_VARRUN in pidfile() */
|
||||||
|
__pidfile_path = _PATH_TMP;
|
||||||
|
|
||||||
|
/* Find __progname, not all C libraries support this */
|
||||||
|
ident = progname(argv[0]);
|
||||||
|
|
||||||
|
for (i = 0; i < NELEMS(pidfiles); i++)
|
||||||
|
ret += test_pidfile(pidfiles[i]);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* compile-command: "make pidfile && ./pidfile -v"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#include <stdlib.h> /* atexit() */
|
#include <stdlib.h> /* atexit() */
|
||||||
#include <unistd.h> /* usleep() */
|
#include <unistd.h> /* usleep() */
|
||||||
#include "conio.h"
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
#define MAX_WIDTH 80
|
#define MAX_WIDTH 80
|
||||||
|
|||||||
+4
-3
@@ -53,9 +53,9 @@ static void check_tree(char *heading, char *dir)
|
|||||||
if (verbose) {
|
if (verbose) {
|
||||||
if (heading)
|
if (heading)
|
||||||
puts(heading);
|
puts(heading);
|
||||||
|
|
||||||
tree(dir, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: Fixme, add code to list tree, nftw() possibly
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_test(void)
|
int run_test(void)
|
||||||
@@ -72,7 +72,8 @@ int run_test(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
setup_test();
|
setup_test();
|
||||||
result += rsync(BASE "src", DST, 0, NULL);
|
sleep(1);
|
||||||
|
result += rsync(BASE "src", DST, LITE_FOPT_KEEP_MTIME, NULL);
|
||||||
check_tree("Only partial rsync of src <-- No slash!", BASE);
|
check_tree("Only partial rsync of src <-- No slash!", BASE);
|
||||||
#if 0
|
#if 0
|
||||||
cleanup_test();
|
cleanup_test();
|
||||||
|
|||||||
+13
-2
@@ -8,18 +8,29 @@
|
|||||||
#warning O_TMPFILE is missing, either too old GLIBC, Linux, or non-Linux system
|
#warning O_TMPFILE is missing, either too old GLIBC, Linux, or non-Linux system
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define READBACK "Reality is frequently inaccurate.\n"
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
char buf[80] = "";
|
||||||
|
|
||||||
printf("Before tempfile():\n");
|
printf("Before tempfile():\n");
|
||||||
system("ls -lrt " _PATH_TMP " | tail -3");
|
ret = system("ls -lrt " _PATH_TMP " | tail -3");
|
||||||
|
|
||||||
fp = tempfile();
|
fp = tempfile();
|
||||||
fail_unless(fp != NULL);
|
fail_unless(fp != NULL);
|
||||||
|
|
||||||
|
ret = fputs(READBACK, fp);
|
||||||
|
rewind(fp);
|
||||||
|
if (fgets(buf, sizeof(buf), fp))
|
||||||
|
fprintf(stderr, "\nRead-back from tempfile: %s", buf);
|
||||||
|
fail_unless(!strcmp(buf, READBACK));
|
||||||
|
|
||||||
printf("\nAfter tempfile(), should be same list:\n");
|
printf("\nAfter tempfile(), should be same list:\n");
|
||||||
system("ls -lrt " _PATH_TMP " | tail -3");
|
ret = system("ls -lrt " _PATH_TMP " | tail -3");
|
||||||
|
|
||||||
return fclose(fp);
|
return fclose(fp);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
#include <err.h>
|
||||||
|
#include <paths.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "check.h"
|
||||||
|
|
||||||
|
int verbose = 0;
|
||||||
|
|
||||||
|
|
||||||
|
static int mtime(char *file)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
char buf[80];
|
||||||
|
struct stat before, after;
|
||||||
|
|
||||||
|
PRINT("Calling touch() to create file ...\n");
|
||||||
|
touch(file);
|
||||||
|
stat(file, &before);
|
||||||
|
|
||||||
|
/* Must sleep a while here otherwise we execute too fast => no mtime change :-( */
|
||||||
|
usleep(10000);
|
||||||
|
|
||||||
|
PRINT("Calling touch() again to update mtime ...\n");
|
||||||
|
if (touch(file)) {
|
||||||
|
erase(file);
|
||||||
|
err(1, "Failed creating %s", file);
|
||||||
|
}
|
||||||
|
stat(file, &after);
|
||||||
|
|
||||||
|
ret = timespec_newer(&after.st_mtim, &before.st_mtim);
|
||||||
|
PRINT("Before: %s\n", timespec2str(&before.st_mtim, buf, sizeof(buf)));
|
||||||
|
PRINT("After : %s\n", timespec2str(&after.st_mtim, buf, sizeof(buf)));
|
||||||
|
|
||||||
|
return !ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
char file[42] = "/tmp/touch_test.XXXXXX";
|
||||||
|
|
||||||
|
if (argc > 1 && !strcmp(argv[1], "-v"))
|
||||||
|
verbose = 1;
|
||||||
|
|
||||||
|
fd = mkstemp(file);
|
||||||
|
if (fd < 0)
|
||||||
|
err(1, "Failed creating tempfile, %s", file);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
return mtime(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* compile-command: "make pidfile && ./pidfile -v"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#include "check.h"
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int result = 0;
|
|
||||||
size_t i;
|
|
||||||
struct { char *path; int fail; } arr[] = {
|
|
||||||
{ "/etc/passwd", -1 },
|
|
||||||
{ "/dev", 0 },
|
|
||||||
{ "/sbin", 0 },
|
|
||||||
};
|
|
||||||
|
|
||||||
for (i = 0; i < NELEMS(arr); i++) {
|
|
||||||
if (tree(arr[i].path, 1) != arr[i].fail)
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#include "check.h"
|
||||||
|
|
||||||
|
struct tc {
|
||||||
|
char *cmd;
|
||||||
|
int exp;
|
||||||
|
int res;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
size_t i;
|
||||||
|
struct tc test[] = {
|
||||||
|
{ "ls", 1 },
|
||||||
|
{ "free", 1 },
|
||||||
|
{ "modinfo", 1 },
|
||||||
|
{ "useradd", 1 },
|
||||||
|
{ "/bin/which", 1 },
|
||||||
|
{ "/bin/ps aux", 1 },
|
||||||
|
{ "/etc/passwd", 0 },
|
||||||
|
{ NULL, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
for (i = 0; test[i].cmd; i++) {
|
||||||
|
char *path;
|
||||||
|
|
||||||
|
path = which(test[i].cmd);
|
||||||
|
if (!path) {
|
||||||
|
test[i].res = 0;
|
||||||
|
fprintf(stderr, "%20s : Not hot dog\n", test[i].cmd);
|
||||||
|
} else {
|
||||||
|
test[i].res = 1;
|
||||||
|
fprintf(stderr, "%20s : hot dog --> %s\n", test[i].cmd, path);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; test[i].cmd; i++)
|
||||||
|
result += test[i].exp != test[i].res;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
/* Simple /bin/tree replacement
|
|
||||||
*
|
|
||||||
* Copyright (c) 2015 Joachim Nilsson <troglobit@gmail.com>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
static int all = 0;
|
|
||||||
|
|
||||||
static int filter(const struct dirent *entry)
|
|
||||||
{
|
|
||||||
/* Skip current dir ".", and prev dir "..", from list of files */
|
|
||||||
if ((1 == strlen(entry->d_name) && entry->d_name[0] == '.') ||
|
|
||||||
(2 == strlen(entry->d_name) && !strcmp(entry->d_name, "..")))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!all && entry->d_name[0] == '.')
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void get_perms(struct stat *st, char *buf, size_t len)
|
|
||||||
{
|
|
||||||
mode_t m = st->st_mode;
|
|
||||||
|
|
||||||
snprintf(buf, len, "[%c%c%c%c%c%c%c%c%c%c] ",
|
|
||||||
S_ISCHR(m) ? 'c' : S_ISBLK(m) ? 'b' : S_ISFIFO(m) ? 'p' : S_ISLNK(m) ? 'l' : S_ISSOCK(m) ? 's' : '-',
|
|
||||||
(m & S_IRUSR) ? 'r' : '-',
|
|
||||||
(m & S_IWUSR) ? 'w' : '-',
|
|
||||||
(m & S_ISUID ) ? 's' : (m & S_IXUSR) ? 'x' : '-',
|
|
||||||
(m & S_IRGRP) ? 'r' : '-',
|
|
||||||
(m & S_IWGRP) ? 'w' : '-',
|
|
||||||
(m & S_ISGID) ? 's' : (m & S_IXGRP) ? 'x' : '-',
|
|
||||||
(m & S_IROTH) ? 'r' : '-',
|
|
||||||
(m & S_IWOTH) ? 'w' : '-',
|
|
||||||
(m & S_IXOTH) ? 'x' : '-'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int descend(char *path, int show_perms, char *pfx)
|
|
||||||
{
|
|
||||||
int result = 0;
|
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
if (-1 == lstat(path, &st))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if ((st.st_mode & S_IFMT) == S_IFDIR) {
|
|
||||||
int i, n;
|
|
||||||
struct dirent **namelist = NULL;
|
|
||||||
|
|
||||||
n = scandir(path, &namelist, filter, alphasort);
|
|
||||||
if (n) {
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
char t = ' ', p[14] = "", s[256] = "";
|
|
||||||
char buf[256];
|
|
||||||
char dir[80];
|
|
||||||
|
|
||||||
if (i + 1 == n) {
|
|
||||||
printf("%s `- ", pfx);
|
|
||||||
snprintf(dir, sizeof(dir), "%s ", pfx);
|
|
||||||
} else {
|
|
||||||
printf("%s|-- ", pfx);
|
|
||||||
snprintf(dir, sizeof(dir), "%s| ", pfx);
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", path, namelist[i]->d_name);
|
|
||||||
if (!lstat(buf, &st)) {
|
|
||||||
if (show_perms)
|
|
||||||
get_perms(&st, p, sizeof(p));
|
|
||||||
if ((st.st_mode & S_IFMT) == S_IFDIR)
|
|
||||||
t = '/';
|
|
||||||
if (S_ISLNK(st.st_mode)) {
|
|
||||||
snprintf(s, sizeof(s), "-> ");
|
|
||||||
if (-1 == readlink(buf, &s[3], sizeof(s) - 3))
|
|
||||||
s[0] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%s%s%c%s\n", p, namelist[i]->d_name, t, s);
|
|
||||||
if (t == '/')
|
|
||||||
result += descend(buf, show_perms, dir);
|
|
||||||
|
|
||||||
free(namelist[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(namelist);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
errno = ENOTDIR;
|
|
||||||
result = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
int tree(char *path, int show_perms)
|
|
||||||
{
|
|
||||||
printf("[%s]\n", path);
|
|
||||||
return descend(path, show_perms, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Local Variables:
|
|
||||||
* indent-tabs-mode: t
|
|
||||||
* c-file-style: "linux"
|
|
||||||
* End:
|
|
||||||
*/
|
|
||||||
Reference in new issue
Block a user