mirror of
https://github.com/troglobit/libite.git
synced 2026-10-14 10:19:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
960e7f69ed | ||
|
|
68bc83f08f | ||
|
|
986d29caf0 | ||
|
|
2d9f8f595d | ||
|
|
3f8ad99f1f | ||
|
|
63e25ecae4 | ||
|
|
6c53ee819b | ||
|
|
da21e02be0 | ||
|
|
c33500c372 | ||
|
|
bed65c84e6 | ||
|
|
c4f262b721 | ||
|
|
563b387ec7 | ||
|
|
b93d74c065 | ||
|
|
c1f7bc2bbb | ||
|
|
99f644b512 | ||
|
|
92bb0ca399 | ||
|
|
921afdecb4 | ||
|
|
47b02df823 | ||
|
|
4dd14dac42 | ||
|
|
97a3d43e9c | ||
|
|
784a667584 | ||
|
|
1f6ff90d9e | ||
|
|
9eb847e56c | ||
|
|
55272c13f7 | ||
|
|
34097d33b6 | ||
|
|
311288eec9 | ||
|
|
63cf8867c5 | ||
|
|
ac7b4194cf | ||
|
|
e44aaa4fd5 | ||
|
|
97cb2cb87c | ||
|
|
837c3f23be | ||
|
|
4e9b5c13c1 | ||
|
|
d61b847e55 | ||
|
|
90fdcdeb39 | ||
|
|
e36ac8f462 | ||
|
|
eb3bb94cfa | ||
|
|
11b9c88732 | ||
|
|
11d4aafce1 | ||
|
|
5cdc5736f3 | ||
|
|
059bfd7806 | ||
|
|
0cda6339a4 | ||
|
|
8120492fc8 | ||
|
|
2065165ae9 | ||
|
|
95e5fdba9b | ||
|
|
b21d1c8e9b | ||
|
|
5b670951a3 | ||
|
|
612290c9e2 | ||
|
|
80d11dccf7 | ||
|
|
438e7a2722 | ||
|
|
96e023e58e | ||
|
|
67a9b379ba | ||
|
|
1c0988b8e2 | ||
|
|
407b8f6dbf | ||
|
|
bc72e1c3ad | ||
|
|
2d10cf0402 | ||
|
|
7adf2a01f2 | ||
|
|
a4ff8cce01 | ||
|
|
12b9196c65 | ||
|
|
6eee1b1baf | ||
|
|
1a5b184391 | ||
|
|
832c4a936b | ||
|
|
a712364d49 | ||
|
|
fae83c9be3 | ||
|
|
48202ef19e | ||
|
|
7c36f715c7 | ||
|
|
328b28f2d1 | ||
|
|
970fa47ecf | ||
|
|
0a98f5bbd1 | ||
|
|
85336b1f2b | ||
|
|
8128e63898 | ||
|
|
b52f1e5ad6 | ||
|
|
5d1e884d6f | ||
|
|
6537b11e34 | ||
|
|
03598fc01e | ||
|
|
d4649b8284 | ||
|
|
3d2a975f11 | ||
|
|
1b6707f44e | ||
|
|
bdebca9681 | ||
|
|
d364f6b4e1 | ||
|
|
6db730aeff | ||
|
|
c512e1cabd | ||
|
|
5d94ca9a14 | ||
|
|
f0efcb5340 | ||
|
|
4ee5ca61b8 | ||
|
|
ed491ecdba | ||
|
|
b6940814f4 | ||
|
|
1e91e7ea3f | ||
|
|
332861430d | ||
|
|
0813084aa7 | ||
|
|
990ee6874c | ||
|
|
ef4a8691d3 | ||
|
|
75139cdf3c | ||
|
|
c9633ffbb0 | ||
|
|
692dbadd3a | ||
|
|
b1a2975a76 | ||
|
|
67529f2283 | ||
|
|
8e69676943 | ||
|
|
76faae4292 | ||
|
|
e928c30fbd | ||
|
|
3512201a58 | ||
|
|
dc5c4ae36c | ||
|
|
748948b665 | ||
|
|
951050fdd2 | ||
|
|
d5c5996f03 | ||
|
|
f5808e557e | ||
|
|
d4b554ccdc | ||
|
|
098a020843 | ||
|
|
2040569f0a | ||
|
|
733a7062e9 | ||
|
|
7ad11a31df | ||
|
|
8ce46eb439 | ||
|
|
c15e883427 | ||
|
|
63d82da62d | ||
|
|
dd1c67b2b6 | ||
|
|
08d9a90945 | ||
|
|
beba419a0f | ||
|
|
3d695eede5 | ||
|
|
6e18edea93 | ||
|
|
9c89daf770 | ||
|
|
b3d4674bf7 | ||
|
|
aa4576d5ea | ||
|
|
ae56c9e33c | ||
|
|
3387c737be | ||
|
|
8d90ede158 | ||
|
|
b1fe8a1271 | ||
|
|
044c2621ac | ||
|
|
7396dd83c7 | ||
|
|
e5fe988cdc | ||
|
|
824da13977 | ||
|
|
efb1470008 | ||
|
|
d2d0792c06 | ||
|
|
711c59e3a6 | ||
|
|
f85ff3c835 | ||
|
|
16ea69adb4 | ||
|
|
ae492581f8 | ||
|
|
d16385415c | ||
|
|
d27518c5b8 | ||
|
|
724926896a | ||
|
|
ef04307b4a | ||
|
|
5d035d955e | ||
|
|
b65175782d | ||
|
|
c27a8e7ec6 | ||
|
|
d231c1e1eb | ||
|
|
247fb67274 | ||
|
|
c716cc5835 | ||
|
|
e81ce85867 | ||
|
|
549f325c21 | ||
|
|
2a6adeebcd | ||
|
|
cb2beacf2c | ||
|
|
256b6ba038 | ||
|
|
61d9b5fac7 | ||
|
|
38ad841389 | ||
|
|
f1a1a21569 | ||
|
|
7f3f4df9e9 | ||
|
|
02a42a1cad | ||
|
|
28c11f010a |
No files matched your search
@@ -0,0 +1,193 @@
|
|||||||
|
# CodeDocs.xyz Configuration File
|
||||||
|
#
|
||||||
|
# Rename this example to '.codedocs' and put it in the root directory of your
|
||||||
|
# repository. This file is optional, documentation will still be generated
|
||||||
|
# without it using sensible defaults.
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------
|
||||||
|
# CodeDocs Configuration
|
||||||
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Include the Doxygen configuration from another file.
|
||||||
|
# The file must be a relative path with respect to the root of the repository.
|
||||||
|
# If any of the options in this doxyfile include a path (ie, INPUT), these
|
||||||
|
# paths will be considered relative to the root of the repository, not the
|
||||||
|
# location of the DOXYFILE.
|
||||||
|
|
||||||
|
DOXYFILE = doc/Doxyfile
|
||||||
|
|
||||||
|
# Specify external repository to link documentation with.
|
||||||
|
# This is similar to Doxygen's TAGFILES option, but will automatically link to
|
||||||
|
# tags of other repositories already using CodeDocs. List each repository to
|
||||||
|
# link with by giving its location in the form of owner/repository.
|
||||||
|
# For example:
|
||||||
|
# TAGLINKS = doxygen/doxygen CodeDocs/osg
|
||||||
|
# Note: these repositories must already be built on CodeDocs.
|
||||||
|
|
||||||
|
TAGLINKS =
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------
|
||||||
|
# Doxygen Configuration
|
||||||
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Doxygen configuration may also be placed in this file.
|
||||||
|
# Currently, the following Doxygen configuration options are available. Refer
|
||||||
|
# to http://doxygen.org/manual/config.html for detailed explanation of the
|
||||||
|
# options. To request support for more options, contact support@codedocs.xyz.
|
||||||
|
#
|
||||||
|
# ABBREVIATE_BRIEF =
|
||||||
|
# ALIASES =
|
||||||
|
# ALLEXTERNALS =
|
||||||
|
# ALLOW_UNICODE_NAMES =
|
||||||
|
# ALPHABETICAL_INDEX =
|
||||||
|
# ALWAYS_DETAILED_SEC =
|
||||||
|
# AUTOLINK_SUPPORT =
|
||||||
|
# BRIEF_MEMBER_DESC =
|
||||||
|
# BUILTIN_STL_SUPPORT =
|
||||||
|
# CALLER_GRAPH =
|
||||||
|
# CALL_GRAPH =
|
||||||
|
# CASE_SENSE_NAMES =
|
||||||
|
# CITE_BIB_FILES =
|
||||||
|
# CLASS_DIAGRAMS =
|
||||||
|
# CLASS_GRAPH =
|
||||||
|
# COLLABORATION_GRAPH =
|
||||||
|
# COLS_IN_ALPHA_INDEX =
|
||||||
|
# CPP_CLI_SUPPORT =
|
||||||
|
# DIAFILE_DIRS =
|
||||||
|
# DIRECTORY_GRAPH =
|
||||||
|
# DISABLE_INDEX =
|
||||||
|
# DISTRIBUTE_GROUP_DOC =
|
||||||
|
# DOTFILE_DIRS =
|
||||||
|
# DOT_FONTNAME =
|
||||||
|
# DOT_FONTSIZE =
|
||||||
|
# DOT_GRAPH_MAX_NODES =
|
||||||
|
# DOT_IMAGE_FORMAT =
|
||||||
|
# DOT_TRANSPARENT =
|
||||||
|
# DOXYFILE_ENCODING =
|
||||||
|
# ENABLED_SECTIONS =
|
||||||
|
# ENABLE_PREPROCESSING =
|
||||||
|
# ENUM_VALUES_PER_LINE =
|
||||||
|
# EXAMPLE_PATH =
|
||||||
|
# EXAMPLE_PATTERNS =
|
||||||
|
# EXAMPLE_RECURSIVE =
|
||||||
|
EXCLUDE = src/README.md
|
||||||
|
# EXCLUDE_PATTERNS =
|
||||||
|
# EXCLUDE_SYMBOLS =
|
||||||
|
# EXPAND_AS_DEFINED =
|
||||||
|
# EXPAND_ONLY_PREDEF =
|
||||||
|
# EXTENSION_MAPPING =
|
||||||
|
# EXTERNAL_GROUPS =
|
||||||
|
# EXTERNAL_PAGES =
|
||||||
|
# EXTRACT_ALL =
|
||||||
|
# EXTRACT_ANON_NSPACES =
|
||||||
|
# EXTRACT_LOCAL_CLASSES =
|
||||||
|
# EXTRACT_LOCAL_METHODS =
|
||||||
|
# EXTRACT_PACKAGE =
|
||||||
|
# EXTRACT_PRIVATE =
|
||||||
|
# EXTRACT_STATIC =
|
||||||
|
# EXT_LINKS_IN_WINDOW =
|
||||||
|
# FILE_PATTERNS =
|
||||||
|
# FORCE_LOCAL_INCLUDES =
|
||||||
|
# FORMULA_FONTSIZE =
|
||||||
|
# FORMULA_TRANSPARENT =
|
||||||
|
# FULL_PATH_NAMES =
|
||||||
|
# GENERATE_BUGLIST =
|
||||||
|
# GENERATE_DEPRECATEDLIST =
|
||||||
|
# GENERATE_LEGEND =
|
||||||
|
# GENERATE_TESTLIST =
|
||||||
|
# GENERATE_TODOLIST =
|
||||||
|
# GENERATE_TREEVIEW =
|
||||||
|
# GRAPHICAL_HIERARCHY =
|
||||||
|
# GROUP_GRAPHS =
|
||||||
|
# GROUP_NESTED_COMPOUNDS =
|
||||||
|
# HIDE_COMPOUND_REFERENCE= =
|
||||||
|
# HIDE_FRIEND_COMPOUNDS =
|
||||||
|
# HIDE_IN_BODY_DOCS =
|
||||||
|
# HIDE_SCOPE_NAMES =
|
||||||
|
# HIDE_UNDOC_CLASSES =
|
||||||
|
# HIDE_UNDOC_MEMBERS =
|
||||||
|
# HIDE_UNDOC_RELATIONS =
|
||||||
|
# HTML_COLORSTYLE_GAMMA =
|
||||||
|
# HTML_COLORSTYLE_HUE =
|
||||||
|
# HTML_COLORSTYLE_SAT =
|
||||||
|
# HTML_DYNAMIC_SECTIONS =
|
||||||
|
# HTML_EXTRA_FILES =
|
||||||
|
# HTML_EXTRA_STYLESHEET =
|
||||||
|
# HTML_FOOTER =
|
||||||
|
# HTML_HEADER =
|
||||||
|
# HTML_INDEX_NUM_ENTRIES =
|
||||||
|
# HTML_STYLESHEET =
|
||||||
|
# HTML_TIMESTAMP =
|
||||||
|
# IDL_PROPERTY_SUPPORT =
|
||||||
|
# IGNORE_PREFIX =
|
||||||
|
# IMAGE_PATH =
|
||||||
|
# INCLUDED_BY_GRAPH =
|
||||||
|
# INCLUDE_FILE_PATTERNS =
|
||||||
|
# INCLUDE_GRAPH =
|
||||||
|
# INCLUDE_PATH =
|
||||||
|
# INHERIT_DOCS =
|
||||||
|
# INLINE_GROUPED_CLASSES =
|
||||||
|
# INLINE_INFO =
|
||||||
|
# INLINE_INHERITED_MEMB =
|
||||||
|
# INLINE_SIMPLE_STRUCTS =
|
||||||
|
# INLINE_SOURCES =
|
||||||
|
INPUT = src/ README.md doc/API.md
|
||||||
|
# INPUT_ENCODING =
|
||||||
|
# INTERACTIVE_SVG =
|
||||||
|
# INTERNAL_DOCS =
|
||||||
|
# JAVADOC_AUTOBRIEF =
|
||||||
|
# LAYOUT_FILE =
|
||||||
|
# MACRO_EXPANSION =
|
||||||
|
# MARKDOWN_SUPPORT =
|
||||||
|
# MAX_DOT_GRAPH_DEPTH =
|
||||||
|
# MSCFILE_DIRS =
|
||||||
|
# MULTILINE_CPP_IS_BRIEF =
|
||||||
|
# OPTIMIZE_FOR_FORTRAN =
|
||||||
|
# OPTIMIZE_OUTPUT_FOR_C =
|
||||||
|
# OPTIMIZE_OUTPUT_JAVA =
|
||||||
|
# OPTIMIZE_OUTPUT_VHDL =
|
||||||
|
# OUTPUT_LANGUAGE =
|
||||||
|
# PLANTUML_JAR_PATH =
|
||||||
|
# PREDEFINED =
|
||||||
|
# PROJECT_BRIEF =
|
||||||
|
# PROJECT_LOGO =
|
||||||
|
# PROJECT_NAME =
|
||||||
|
# PROJECT_NUMBER =
|
||||||
|
# QT_AUTOBRIEF =
|
||||||
|
# RECURSIVE =
|
||||||
|
# REFERENCED_BY_RELATION =
|
||||||
|
# REFERENCES_LINK_SOURCE =
|
||||||
|
# REFERENCES_RELATION =
|
||||||
|
# REPEAT_BRIEF =
|
||||||
|
# SEARCHENGINE =
|
||||||
|
# SEARCH_INCLUDES =
|
||||||
|
# SEPARATE_MEMBER_PAGES =
|
||||||
|
# SHORT_NAMES =
|
||||||
|
# SHOW_FILES =
|
||||||
|
# SHOW_GROUPED_MEMB_INC =
|
||||||
|
# SHOW_INCLUDE_FILES =
|
||||||
|
# SHOW_NAMESPACES =
|
||||||
|
# SHOW_USED_FILES =
|
||||||
|
# SIP_SUPPORT =
|
||||||
|
# SKIP_FUNCTION_MACROS =
|
||||||
|
# SORT_BRIEF_DOCS =
|
||||||
|
# SORT_BY_SCOPE_NAME =
|
||||||
|
# SORT_GROUP_NAMES =
|
||||||
|
# SORT_MEMBERS_CTORS_1ST =
|
||||||
|
# SORT_MEMBER_DOCS =
|
||||||
|
# SOURCE_BROWSER =
|
||||||
|
# SOURCE_TOOLTIPS =
|
||||||
|
# STRICT_PROTO_MATCHING =
|
||||||
|
# STRIP_CODE_COMMENTS =
|
||||||
|
# STRIP_FROM_INC_PATH =
|
||||||
|
# STRIP_FROM_PATH =
|
||||||
|
# SUBGROUPING =
|
||||||
|
# TAB_SIZE =
|
||||||
|
# TEMPLATE_RELATIONS =
|
||||||
|
# TREEVIEW_WIDTH =
|
||||||
|
# TYPEDEF_HIDES_STRUCT =
|
||||||
|
# UML_LIMIT_NUM_FIELDS =
|
||||||
|
# UML_LOOK =
|
||||||
|
USE_MDFILE_AS_MAINPAGE = README.md
|
||||||
|
# VERBATIM_HEADERS =
|
||||||
|
#
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
Contributing to the Project
|
||||||
|
===========================
|
||||||
|
|
||||||
|
Thank you for considering contributing back to [Free Software][1]!
|
||||||
|
|
||||||
|
There are a few things we would like you to consider when filing an
|
||||||
|
issue or pull request with this project:
|
||||||
|
|
||||||
|
1. If you are filing a bug report or feature request
|
||||||
|
|
||||||
|
Please take the time to check if an issue already has been filed
|
||||||
|
matching your problem
|
||||||
|
|
||||||
|
2. What version are you running, have you tried the latest release?
|
||||||
|
|
||||||
|
UNIX distributions often package and test software for their
|
||||||
|
particular brand. If you are using a pre-packaged version,
|
||||||
|
then please file a bug with that distribution instead.
|
||||||
|
|
||||||
|
3. Coding Style
|
||||||
|
|
||||||
|
Lines are allowed to be longer than 72 characters these days, there
|
||||||
|
is no enforced max. length.
|
||||||
|
|
||||||
|
> **Tip:** Always submit code that follows the style of surrounding code!
|
||||||
|
|
||||||
|
The coding style itself is strictly Linux [KNF][], like GIT it is
|
||||||
|
becoming a de facto standard for C programming
|
||||||
|
|
||||||
|
https://www.kernel.org/doc/Documentation/CodingStyle
|
||||||
|
|
||||||
|
4. Logical Change Sets
|
||||||
|
|
||||||
|
Changes should be broken down into logical units that add a feature
|
||||||
|
or fix a bug. Keep changes separate from each other and do not mix a
|
||||||
|
bug fix with a whitespace cleanup or a new feature addition.
|
||||||
|
|
||||||
|
This is important not only for readability, or for the possibility of
|
||||||
|
maintainers to revert changes, but does also increase your chances of
|
||||||
|
having a change accepted.
|
||||||
|
|
||||||
|
5. Commit messages
|
||||||
|
|
||||||
|
Commit messages exist to track *why* a change was made. Try to be as
|
||||||
|
clear and concise as possible in your commit messages, and always, be
|
||||||
|
proud of your work and set up a proper GIT identity for your commits:
|
||||||
|
|
||||||
|
git config --global user.name "J. Random Hacker"
|
||||||
|
git config --global user.email random.j.hacker@example.com
|
||||||
|
|
||||||
|
See this helpful guide for how to write simple, readable commit
|
||||||
|
messages, or have at least a look at the below example.
|
||||||
|
|
||||||
|
http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
|
||||||
|
|
||||||
|
|
||||||
|
Example
|
||||||
|
-------
|
||||||
|
|
||||||
|
Example commit message from the [Pro Git][gitbook] online book, notice
|
||||||
|
how `git commit -s` is used to automatically add a `Signed-off-by`:
|
||||||
|
|
||||||
|
Capitalized, short (50 chars or less) summary
|
||||||
|
|
||||||
|
More detailed explanatory text, if necessary. Wrap it to about 72
|
||||||
|
characters or so. In some contexts, the first line is treated as the
|
||||||
|
subject of an email and the rest of the text as the body. The blank
|
||||||
|
line separating the summary from the body is critical (unless you omit
|
||||||
|
the body entirely); tools like rebase can get confused if you run the
|
||||||
|
two together.
|
||||||
|
|
||||||
|
Write your commit message in the imperative: "Fix bug" and not "Fixed bug"
|
||||||
|
or "Fixes bug." This convention matches up with commit messages generated
|
||||||
|
by commands like git merge and git revert.
|
||||||
|
|
||||||
|
Further paragraphs come after blank lines.
|
||||||
|
|
||||||
|
- Bullet points are okay, too
|
||||||
|
|
||||||
|
- Typically a hyphen or asterisk is used for the bullet, followed by a
|
||||||
|
single space, with blank lines in between, but conventions vary here
|
||||||
|
|
||||||
|
- Use a hanging indent
|
||||||
|
|
||||||
|
Signed-off-by: J. Random Hacker <random.j.hacker@example.com>
|
||||||
|
|
||||||
|
|
||||||
|
[1]: http://www.gnu.org/philosophy/free-sw.en.html
|
||||||
|
[KNF]: https://en.wikipedia.org/wiki/Kernel_Normal_Form
|
||||||
|
[gitbook]: https://git-scm.com/book/ch5-2.html
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: [troglobit]
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
name: Bob the Builder
|
||||||
|
|
||||||
|
# Run on all branches, including all pull requests, except the 'dev'
|
||||||
|
# branch since that's where we run Coverity Scan (limited tokens/day)
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '**'
|
||||||
|
- '!dev'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
# Verify we can build on latest Ubuntu with both gcc and clang
|
||||||
|
name: ${{ matrix.compiler }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
compiler: [gcc, clang]
|
||||||
|
fail-fast: false
|
||||||
|
env:
|
||||||
|
MAKEFLAGS: -j3
|
||||||
|
CC: ${{ matrix.compiler }}
|
||||||
|
steps:
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get -y update
|
||||||
|
sudo apt-get -y install tree doxygen
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Configure
|
||||||
|
run: |
|
||||||
|
./autogen.sh
|
||||||
|
./configure --prefix= --disable-silent-rules
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
make
|
||||||
|
- name: Install to ~/tmp and Inspect
|
||||||
|
run: |
|
||||||
|
DESTDIR=~/tmp make install-strip
|
||||||
|
tree ~/tmp
|
||||||
|
- name: Run Unit Tests
|
||||||
|
run: |
|
||||||
|
make check || (cat test/test-suite.log; false)
|
||||||
|
- name: Upload Test Results
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: libite-test-${{ matrix.compiler }}
|
||||||
|
path: test/*
|
||||||
|
debian:
|
||||||
|
name: Verify Debian Package
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: debian:stable
|
||||||
|
env:
|
||||||
|
MAKEFLAGS: -j3
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Installing dependencies
|
||||||
|
run: |
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y build-essential autoconf automake pkg-config doxygen \
|
||||||
|
dpkg-dev debhelper devscripts
|
||||||
|
- name: Building Debian package
|
||||||
|
run: |
|
||||||
|
./autogen.sh
|
||||||
|
./configure
|
||||||
|
make check || (cat test/test-suite.log; false)
|
||||||
|
make distcheck
|
||||||
|
make package
|
||||||
|
cat ../*.changes
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
name: Coverity Scan
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'dev'
|
||||||
|
|
||||||
|
env:
|
||||||
|
PROJECT_NAME: libite
|
||||||
|
CONTACT_EMAIL: troglobit@gmail.com
|
||||||
|
COVERITY_NAME: troglobit-libite
|
||||||
|
COVERITY_PROJ: troglobit%2Flibite
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
coverity:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Fetch latest Coverity Scan MD5
|
||||||
|
id: var
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||||
|
run: |
|
||||||
|
wget -q https://scan.coverity.com/download/cxx/linux64 \
|
||||||
|
--post-data "token=$TOKEN&project=${COVERITY_PROJ}&md5=1" \
|
||||||
|
-O coverity-latest.tar.gz.md5
|
||||||
|
echo "md5=$(cat coverity-latest.tar.gz.md5)" | tee -a $GITHUB_OUTPUT
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
id: cache
|
||||||
|
with:
|
||||||
|
path: coverity-latest.tar.gz
|
||||||
|
key: ${{ runner.os }}-coverity-${{ steps.var.outputs.md5 }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-coverity-${{ steps.var.outputs.md5 }}
|
||||||
|
${{ runner.os }}-coverity-
|
||||||
|
${{ runner.os }}-coverity
|
||||||
|
- name: Download Coverity Scan
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||||
|
run: |
|
||||||
|
if [ ! -f coverity-latest.tar.gz ]; then
|
||||||
|
wget -q https://scan.coverity.com/download/cxx/linux64 \
|
||||||
|
--post-data "token=$TOKEN&project=${COVERITY_PROJ}" \
|
||||||
|
-O coverity-latest.tar.gz
|
||||||
|
else
|
||||||
|
echo "Latest Coverity Scan available from cache :-)"
|
||||||
|
md5sum coverity-latest.tar.gz
|
||||||
|
fi
|
||||||
|
mkdir coverity
|
||||||
|
tar xzf coverity-latest.tar.gz --strip 1 -C coverity
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get -y update
|
||||||
|
sudo apt-get -y install pkg-config
|
||||||
|
- name: Configure
|
||||||
|
run: |
|
||||||
|
./autogen.sh
|
||||||
|
./configure --prefix= --disable-silent-rules
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
export PATH=`pwd`/coverity/bin:$PATH
|
||||||
|
cov-build --dir cov-int make
|
||||||
|
- name: Submit results to Coverity Scan
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||||
|
run: |
|
||||||
|
tar czvf ${PROJECT_NAME}.tgz cov-int
|
||||||
|
curl \
|
||||||
|
--form project=${COVERITY_NAME} \
|
||||||
|
--form token=$TOKEN \
|
||||||
|
--form email=${CONTACT_EMAIL} \
|
||||||
|
--form file=@${PROJECT_NAME}.tgz \
|
||||||
|
--form version=trunk \
|
||||||
|
--form description="${PROJECT_NAME} $(git rev-parse HEAD)" \
|
||||||
|
https://scan.coverity.com/builds?project=${COVERITY_PROJ}
|
||||||
|
- name: Upload build.log
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: coverity-build.log
|
||||||
|
path: cov-int/build-log.txt
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
name: Release General
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
name: Build and upload release tarball
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Installing dependencies ...
|
||||||
|
run: |
|
||||||
|
sudo apt-get -y update
|
||||||
|
sudo apt-get -y install tree doxygen
|
||||||
|
- name: Creating Makefiles ...
|
||||||
|
run: |
|
||||||
|
./autogen.sh
|
||||||
|
./configure --prefix=
|
||||||
|
- name: Build release ...
|
||||||
|
run: |
|
||||||
|
make release
|
||||||
|
mkdir -p artifacts/
|
||||||
|
mv ../*.tar.* artifacts/
|
||||||
|
- name: Extract ChangeLog entry ...
|
||||||
|
run: |
|
||||||
|
awk '/-----*/{if (x == 1) exit; x=1;next}x' ChangeLog.md \
|
||||||
|
|head -n -1 > release.md
|
||||||
|
cat release.md
|
||||||
|
- uses: ncipollo/release-action@v1
|
||||||
|
with:
|
||||||
|
name: Libite (-lite) ${{ github.ref_name }}
|
||||||
|
bodyFile: "release.md"
|
||||||
|
artifacts: "artifacts/*"
|
||||||
-20
@@ -1,20 +0,0 @@
|
|||||||
# Travis CI integration -- https://travis-ci.org/troglobit/libite
|
|
||||||
# Defaults to GNU GCC and autotools: ./configure && make && make test
|
|
||||||
language: c
|
|
||||||
|
|
||||||
# Use docker for quicker builds, it now allows https://docs.travis-ci.com/user/apt/
|
|
||||||
sudo: false
|
|
||||||
|
|
||||||
# Test build with both GCC and Clang (LLVM)
|
|
||||||
compiler:
|
|
||||||
- gcc
|
|
||||||
- clang
|
|
||||||
|
|
||||||
script:
|
|
||||||
- ./autogen.sh
|
|
||||||
- ./configure --prefix=/tmp --disable-silent-rules
|
|
||||||
- make clean
|
|
||||||
- make -j5
|
|
||||||
- make install-strip
|
|
||||||
- ls -lR /tmp
|
|
||||||
- make check
|
|
||||||
+167
-1
@@ -3,6 +3,160 @@ 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.6.1][] - 2023-10-15
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- FTBFS uClibc and musl libc, `lite.h` missing `stdarg.h` include
|
||||||
|
|
||||||
|
|
||||||
|
[v2.6.0][] - 2023-09-17
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- New APIs from the [Infix Project](https://github.com/kernelkit/infix):
|
||||||
|
- `fexistf()`
|
||||||
|
- `vfopenf()`
|
||||||
|
- `popenf()`
|
||||||
|
- `vreadsnf()`, `readsnf()`, `writesf()`
|
||||||
|
- `vreadllf()`, `readllf()`, `readdf()`
|
||||||
|
- `writellf()`, `writedf()`
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Spellchecking of API docs
|
||||||
|
|
||||||
|
|
||||||
|
[v2.5.3][] - 2023-04-08
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- Refactor `copyfile()` unit test and verify number of bytes copied
|
||||||
|
- Add missing `rsync()` unit test to ensure proper function
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- `rsync()` does not copy single files correctly
|
||||||
|
- `copyfile()` does not handle empty source files correctly (error)
|
||||||
|
- `copyfile()` does not properly create destination dir
|
||||||
|
|
||||||
|
|
||||||
|
[v2.5.2][] - 2022-04-17
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- Add printf format attribute hint to all vararg functions. This will
|
||||||
|
help users of these functions by telling CC what to look for
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Fix `fisdir()` segfault on GNU/Hurd
|
||||||
|
- Fix `touch)` on Debian/kFreeBSD, use `creat()` instad of `mknod()`
|
||||||
|
|
||||||
|
|
||||||
|
[v2.5.1][] - 2021-12-02
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
Debian-only fix.
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Use `dh_link(1)` to install `/usr/include/lite -> libite/`. The
|
||||||
|
symlink created by libite installer itself is not kept.
|
||||||
|
|
||||||
|
|
||||||
|
[v2.5.0][] - 2021-11-30
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
> **Note:** namespace change; the -lite library include files have moved
|
||||||
|
> from `lite/*.h` to `libite/*.h` due to an unfortunate clash
|
||||||
|
> with "LiTE is a Toobox Engine", from the DirectFB project.
|
||||||
|
> For a transitional period, however, a compatibility symlink
|
||||||
|
> is installed; `lite -> libite/`.
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- Header files have moved from `lite/*.h` to `libite/*.h` to prevent
|
||||||
|
clashing with DirectFB LiTE library.
|
||||||
|
- Include guards in header files have been renamed, much in the same
|
||||||
|
fashion as the move (above), from `LITE_foo_H_` to `LIBITE_FOO_H_`
|
||||||
|
- Add configure option to disable compatibility symlink, for systems
|
||||||
|
that do not want name clashes with DirectFB/LiTE, or do not need to
|
||||||
|
be backwards compatible; use `configure --without-symlink`
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Minor, use defensive coding in `strnlen()` replacement. Only used
|
||||||
|
on systems that do not have a native implementation.
|
||||||
|
|
||||||
|
|
||||||
|
[v2.4.1][] - 2021-10-09
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- Add doxygen API documentation to project, included in tarball, and
|
||||||
|
automatically generated at https://codedocs.xyz/troglobit/libite/
|
||||||
|
- Relocate `tests/` to `test/` in source tree
|
||||||
|
- Relocate `docs/` to `doc/` in source tree
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Prefix CFLAGS/CPPFLAGS/etc with `AM_` in `test/Makefile.am` to prevent
|
||||||
|
clashing with environment. Fix imported from libuEv
|
||||||
|
- Replace obsolete `AM_CONFIG_HEADER` with `AC_CONFIG_HEADERS`
|
||||||
|
- Fix issue with `tempfile()` returning EOPNOTSUPP on Azure, use
|
||||||
|
fallback to `mkostemp()` with `O_CLOEXEC` flag set
|
||||||
|
|
||||||
|
|
||||||
|
[v2.4.0][] - 2021-03-27
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
- Add support for `touchf()`, formatted string support for `touch()`
|
||||||
|
- Add support for `erasef()`, formatted string support for `erase()`
|
||||||
|
- Add support for `strtrim()`, trims leading and trailing white-space
|
||||||
|
from a string
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
|
||||||
|
- Fix `systemf()` improper handling of `system()` return value. Now
|
||||||
|
checks if exited OK, then returning the exit status of the command, or
|
||||||
|
if not exited OK, then checks if the command was signaled, and returns
|
||||||
|
-1 with `errno` set. This also allows for returning 127, like
|
||||||
|
`system()`, if the shell, or the program itself, did not exist
|
||||||
|
|
||||||
|
|
||||||
|
[v2.3.1][] - 2021-02-12
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- Copyright updates, including LICENSE file, year + author last name
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Debian packaging fixes only
|
||||||
|
|
||||||
|
|
||||||
|
[v2.3.0][] - 2021-02-12
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- Add support for `fremove()`, formatted `remove()` replacement
|
||||||
|
- Add support for `truncatef()`, formatted `truncate()` replacement
|
||||||
|
- Add tar.gz archives to distribution
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Handle `ETIMEDOUT` error for `connect()` call in `telnet_open()`
|
||||||
|
|
||||||
|
|
||||||
|
[v2.2.0][] - 2020-03-16
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
- Add support for `systemf()`, formatted string `system()` replacement
|
||||||
|
- Add support for `fmkpath()`, formatted string `mkpath()`
|
||||||
|
- Add support for `fopenf()`, formatted string `fopen()` replacement
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Fix possible memory leak in `rsync()`, found by Coverity Scan
|
||||||
|
- Check return value of `fstat()` to prevent bogus destination file
|
||||||
|
times when using `copyfile()`, found by Coverity Scan
|
||||||
|
|
||||||
|
|
||||||
[v2.1.2][] - 2020-02-22
|
[v2.1.2][] - 2020-02-22
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
@@ -357,7 +511,19 @@ problems this may cause!
|
|||||||
Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
|
Initial extraction of frog DNA from [Finit][]. See [README][] for API details.
|
||||||
|
|
||||||
|
|
||||||
[UNRELEASED]: https://github.com/troglobit/libite/compare/v2.1.2...HEAD
|
[UNRELEASED]: https://github.com/troglobit/libite/compare/v2.6.1...HEAD
|
||||||
|
[v2.6.1]: https://github.com/troglobit/libite/compare/v2.6.0...v2.6.1
|
||||||
|
[v2.6.0]: https://github.com/troglobit/libite/compare/v2.5.3...v2.6.0
|
||||||
|
[v2.5.3]: https://github.com/troglobit/libite/compare/v2.5.2...v2.5.3
|
||||||
|
[v2.5.2]: https://github.com/troglobit/libite/compare/v2.5.1...v2.5.2
|
||||||
|
[v2.5.1]: https://github.com/troglobit/libite/compare/v2.5.0...v2.5.1
|
||||||
|
[v2.5.0]: https://github.com/troglobit/libite/compare/v2.4.1...v2.5.0
|
||||||
|
[v2.4.1]: https://github.com/troglobit/libite/compare/v2.4.0...v2.4.1
|
||||||
|
[v2.4.0]: https://github.com/troglobit/libite/compare/v2.3.1...v2.4.0
|
||||||
|
[v2.3.1]: https://github.com/troglobit/libite/compare/v2.3.0...v2.3.1
|
||||||
|
[v2.3.0]: https://github.com/troglobit/libite/compare/v2.2.1...v2.3.0
|
||||||
|
[v2.2.1]: https://github.com/troglobit/libite/compare/v2.2.0...v2.2.1
|
||||||
|
[v2.2.0]: https://github.com/troglobit/libite/compare/v2.1.2...v2.2.0
|
||||||
[v2.1.2]: https://github.com/troglobit/libite/compare/v2.1.1...v2.1.2
|
[v2.1.2]: https://github.com/troglobit/libite/compare/v2.1.1...v2.1.2
|
||||||
[v2.1.1]: https://github.com/troglobit/libite/compare/v2.1.0...v2.1.1
|
[v2.1.1]: https://github.com/troglobit/libite/compare/v2.1.0...v2.1.1
|
||||||
[v2.1.0]: https://github.com/troglobit/libite/compare/v2.0.2...v2.1.0
|
[v2.1.0]: https://github.com/troglobit/libite/compare/v2.0.2...v2.1.0
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
|
Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
|
||||||
Copyright (c) 2008-2020 Joachim Nilsson <troglobit@gmail.com>
|
Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -18,9 +18,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
|
|
||||||
Note: Much of the code in libite (-lite) is written by Claudio Matsuoka
|
|
||||||
for Finit and released under the MIT/X11 license. Joachim Nilsson
|
|
||||||
later improved on the Finit code base and included pieces of
|
|
||||||
software released under the ISC and BSD licenses. See each
|
|
||||||
respective file for license details.
|
|
||||||
+28
-20
@@ -1,21 +1,24 @@
|
|||||||
ACLOCAL_AMFLAGS = -I m4
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
|
SUBDIRS = src test
|
||||||
doc_DATA = README.md LICENSE ChangeLog.md
|
doc_DATA = README.md LICENSE ChangeLog.md
|
||||||
EXTRA_DIST = README.md LICENSE ChangeLog.md
|
EXTRA_DIST = README.md LICENSE ChangeLog.md
|
||||||
pkgconfigdir = $(libdir)/pkgconfig
|
|
||||||
pkgconfig_DATA = libite.pc
|
|
||||||
SUBDIRS = src tests
|
|
||||||
|
|
||||||
## Generate MD5 checksum file
|
if ENABLE_DOXYGEN
|
||||||
MD5 = md5sum
|
SUBDIRS += doc
|
||||||
md5-dist:
|
.PHONY: doc
|
||||||
@for file in $(DIST_ARCHIVES); do \
|
doc:
|
||||||
$(MD5) $$file > ../$$file.md5; \
|
$(MAKE) -C @top_builddir@/doc $@
|
||||||
done
|
|
||||||
|
## The distribution should include man pages, which are generated
|
||||||
|
dist-hook: doc
|
||||||
|
else
|
||||||
|
doc:
|
||||||
|
@echo "Doxygen documentation (html + man) disabled, skipping ..."
|
||||||
|
endif
|
||||||
|
|
||||||
## Check if tagged in git
|
## Check if tagged in git
|
||||||
release-hook:
|
release-hook:
|
||||||
@if [ ! `git tag | grep $(PACKAGE_VERSION)` ]; then \
|
@if [ ! `git tag -l v$(PACKAGE_VERSION) | grep $(PACKAGE_VERSION)` ]; then \
|
||||||
echo; \
|
echo; \
|
||||||
printf "\e[1m\e[41mCannot find release tag $(PACKAGE_VERSION)\e[0m\n"; \
|
printf "\e[1m\e[41mCannot find release tag $(PACKAGE_VERSION)\e[0m\n"; \
|
||||||
printf "\e[1m\e[5mDo release anyway?\e[0m "; read yorn; \
|
printf "\e[1m\e[5mDo release anyway?\e[0m "; read yorn; \
|
||||||
@@ -31,20 +34,25 @@ release-hook:
|
|||||||
echo; \
|
echo; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# lintian --profile debian -i -I --show-overrides ../$PKG.changes
|
## Generate .deb package
|
||||||
package build-deb:
|
package:
|
||||||
@dpkg-buildpackage -uc -us -B
|
@debuild -uc -us -B --lintian-opts --profile debian -i -I --show-overrides
|
||||||
|
|
||||||
## Target to run when building a release
|
## Target to run when building a release
|
||||||
release: release-hook distcheck package md5-dist
|
release: release-hook distcheck
|
||||||
|
@for file in $(DIST_ARCHIVES); do \
|
||||||
|
md5sum $$file > ../$$file.md5; \
|
||||||
|
sha256sum $$file > ../$$file.sha256; \
|
||||||
|
done
|
||||||
@mv $(DIST_ARCHIVES) ../
|
@mv $(DIST_ARCHIVES) ../
|
||||||
@echo
|
@echo
|
||||||
@echo "Resulting release files:"
|
@echo "Resulting release files:"
|
||||||
@echo "================================================================="
|
@echo "================================================================="
|
||||||
@for file in $(DIST_ARCHIVES); do \
|
@for file in $(DIST_ARCHIVES); do \
|
||||||
printf "%-32s Distribution tarball\n" $$file; \
|
printf "%-32s Distribution tarball\n" $$file; \
|
||||||
printf "%-32s " $$file.md5; cat ../$$file.md5 | cut -f1 -d' '; \
|
printf "%-32s " $$file.md5; cat ../$$file.md5 | cut -f1 -d' '; \
|
||||||
|
printf "%-32s " $$file.sha256; cat ../$$file.sha256 | cut -f1 -d' '; \
|
||||||
done
|
done
|
||||||
@for file in `cd ..; ls $(PACKAGE)*_$(VERSION)*`; do \
|
@for file in `cd ..; ls $(PACKAGE)*_$(VERSION)*`; do \
|
||||||
printf "%-32s Debian/Ubuntu package\n" $$file; \
|
printf "%-32s Debian/Ubuntu package\n" $$file; \
|
||||||
done
|
done
|
||||||
@@ -1,18 +1,20 @@
|
|||||||
-lite | Frog DNA, basically
|
-lite | Frog DNA, basically
|
||||||
===========================
|
===========================
|
||||||
[![Travis Status][]][Travis]
|
[![GitHub Status][]][GitHub] [![codedocs status][]][codedocs] [![Coverity Status][]][Coverity Scan]
|
||||||
|
|
||||||
|
|
||||||
Table of Contents
|
Table of Contents
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
* [Introduction](#introduction)
|
* [Introduction](#introduction)
|
||||||
* [Using -lite](#using--lite)
|
* [Using -lite](#using--lite)
|
||||||
* [Helper Macros](#helper-macros)
|
* [API](doc/API.md#overview)
|
||||||
* [Generic Functions](#generic-functions)
|
* [Important Node](doc/API.md#important-note)
|
||||||
* [OpenBSD Functions](#openbsd-functions)
|
* [Helper Macros](doc/API.md#helper-macros)
|
||||||
* [Build & Install](#origin--references)
|
* [Generic Functions](doc/API.md#generic-functions)
|
||||||
* [TODO](#todo)
|
* [GNU Functions](doc/API.md#gnu-functions)
|
||||||
|
* [OpenBSD/NetBSD/FreeBSD Functions](doc/API.md#openbsd-netbsd-freebsd-functions)
|
||||||
|
* [Build & Install](#build--install)
|
||||||
|
* [Origin & References](#origin--references)
|
||||||
|
|
||||||
|
|
||||||
> **NOTE:** Incompatible changes in v2.0 compared to v1.x!
|
> **NOTE:** Incompatible changes in v2.0 compared to v1.x!
|
||||||
@@ -34,362 +36,65 @@ recommended when traversing lists to delete/free nodes.
|
|||||||
The code is open sourced under a mix of permissive Open Source licenses:
|
The code is open sourced under a mix of permissive Open Source licenses:
|
||||||
[MIT/X11 license][MIT], [ISC license][ISC], and [BSD licenses][BSD].
|
[MIT/X11 license][MIT], [ISC license][ISC], and [BSD licenses][BSD].
|
||||||
|
|
||||||
|
> **Tip:** have a look at my blog post about other useful UNIX API's!
|
||||||
|
> https://troglobit.com/post/2020-02-22-useful-unix-apis/
|
||||||
|
|
||||||
|
|
||||||
Using -lite
|
Using -lite
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
Libite is by default installed as a library and a set of include files.
|
Libite is by default installed as a library and a set of include files.
|
||||||
To prevent clashing with include files of the same name `-lite` employs
|
To prevent clashing with include files of the same name `-lite` employs
|
||||||
an include file namespace `lite/`, which is strongly recommended to use
|
an include file namespace `libite/`, which is strongly recommended to
|
||||||
in your applications:
|
use in your applications:
|
||||||
|
|
||||||
#include <lite/lite.h>
|
```C
|
||||||
#include <lite/conio.h>
|
#include <libite/lite.h>
|
||||||
#include <lite/queue.h>
|
#include <libite/conio.h>
|
||||||
#include <lite/tree.h>
|
#include <libite/queue.h>
|
||||||
|
#include <libite/tree.h>
|
||||||
|
```
|
||||||
|
|
||||||
The output from the `pkg-config` tool holds no surprises in this regard:
|
> **Note:** prior to v2.5.0, the `lite/` namespace was used for headers,
|
||||||
|
> which is still available in the default install. This clashed with
|
||||||
|
> the headers of the LiTE library from the DirectFB project.
|
||||||
|
|
||||||
$ pkg-config --libs --static --cflags libite
|
The output from the `pkg-config` tool holds no surprises:
|
||||||
-I/usr/local/include -L/usr/local/lib -lite
|
|
||||||
|
```bash
|
||||||
|
$ pkg-config --libs --static --cflags libite
|
||||||
|
-I/usr/local/include -D_LIBITE_LITE -L/usr/local/lib -lite
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Note:** `_LIBITE_LITE` is defined since v2.5.0, useful for software
|
||||||
|
> that want to be able to build against headers from an older libite:
|
||||||
|
>
|
||||||
|
> ```C
|
||||||
|
> #ifdef _LIBITE_LITE
|
||||||
|
> # include <libite/lite.h>
|
||||||
|
> #else
|
||||||
|
> # include <lite/lite.h>
|
||||||
|
> #endif
|
||||||
|
> ```
|
||||||
|
|
||||||
The prefix path `/usr/local/` shown here is only the default. Use the
|
The prefix path `/usr/local/` shown here is only the default. Use the
|
||||||
`configure` script to select a different prefix when installing libite.
|
`configure` script to select a different prefix when installing libite.
|
||||||
|
|
||||||
For GNU autotools based projects, use the following in `configure.ac`:
|
For GNU autotools based projects, use the following in `configure.ac`:
|
||||||
|
|
||||||
# Check for required libraries
|
```m4
|
||||||
PKG_CHECK_MODULES([lite], [libite >= 1.5.0])
|
# Check for required libraries
|
||||||
|
PKG_CHECK_MODULES([lite], [libite >= 1.5.0])
|
||||||
|
```
|
||||||
|
|
||||||
and in your `Makefile.am`:
|
and in your `Makefile.am`:
|
||||||
|
|
||||||
proggy_CFLAGS = $(lite_CFLAGS)
|
```Makefile
|
||||||
proggy_LDADD = $(lite_LIBS)
|
proggy_CFLAGS = $(lite_CFLAGS)
|
||||||
|
proggy_LDADD = $(lite_LIBS)
|
||||||
|
```
|
||||||
|
|
||||||
|
> API Documentaion: https://codedocs.xyz/troglobit/libite/
|
||||||
Important Note
|
|
||||||
--------------
|
|
||||||
|
|
||||||
When using functions like `mkpath()`, `makepath()`, and `makefifo()`,
|
|
||||||
make sure your `umask()` is correct so you do not accidentally create
|
|
||||||
files and directories accessible to other users than intended.
|
|
||||||
|
|
||||||
|
|
||||||
Helper Macros
|
|
||||||
-------------
|
|
||||||
|
|
||||||
- `atonum(str)`
|
|
||||||
|
|
||||||
Convert string to natural number, works for 32-bit non-negative
|
|
||||||
integers. Returns -1 on error. (Uses `strtonum()` internally.)
|
|
||||||
|
|
||||||
- `blkdev(dev)`
|
|
||||||
|
|
||||||
Create block device
|
|
||||||
|
|
||||||
- `chardev(dev)`
|
|
||||||
|
|
||||||
Create character device
|
|
||||||
|
|
||||||
- `erase(path)`
|
|
||||||
|
|
||||||
Erase file/directory with `remove()`. Errors on `stderr`
|
|
||||||
|
|
||||||
- `makedir(path)`
|
|
||||||
|
|
||||||
Create directory, like `mkdir()`. Errors on `stderr`
|
|
||||||
|
|
||||||
- `makefifo(path)`
|
|
||||||
|
|
||||||
Create a FIFO, like `mkfifo()`. Errors on `stderr`
|
|
||||||
|
|
||||||
- `min(a,b)`/`max(a,b)`
|
|
||||||
|
|
||||||
These macros take care to avoid double evaluation.
|
|
||||||
|
|
||||||
- `touch(path)`
|
|
||||||
|
|
||||||
Create a file, or update mtime. Errors on `stderr`
|
|
||||||
|
|
||||||
- `S_ISEXEC(mode_t m)`
|
|
||||||
|
|
||||||
Mysteriously missing from GLIBC
|
|
||||||
|
|
||||||
- `ISCLR(word,bit)`
|
|
||||||
|
|
||||||
Is bit in (integer) word cleared?
|
|
||||||
|
|
||||||
- `ISSET(word,bit)`
|
|
||||||
|
|
||||||
Is bit in (integer) word set?
|
|
||||||
|
|
||||||
- `ISOTHER(word,bit)`
|
|
||||||
|
|
||||||
Are any other bits, except bit, in (integer) word set?
|
|
||||||
|
|
||||||
- `SETBIT(word,bit)`
|
|
||||||
|
|
||||||
Set bit in (integer) word.
|
|
||||||
|
|
||||||
- `CLRBIT(word,bit)`
|
|
||||||
|
|
||||||
Clear bit in (integer) word.
|
|
||||||
|
|
||||||
- `NELEMS(array)`
|
|
||||||
|
|
||||||
Returns the number of elements in an array. From the great book, The
|
|
||||||
Practice of Programming, by Kernighan and Pike.
|
|
||||||
|
|
||||||
|
|
||||||
Generic Functions
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
- `chomp(str)`
|
|
||||||
|
|
||||||
Perl like chomp function, chop off last char if newline.
|
|
||||||
|
|
||||||
- `copyfile(src, dst, len, opt)`
|
|
||||||
|
|
||||||
Like the shell `cp(1)` and `dd(1),`, can also copy symlinks and
|
|
||||||
preserve the mtime of the source file. The opt argument can be
|
|
||||||
a mask of:
|
|
||||||
|
|
||||||
- `LITE_FOPT_COPYFILE_SYM (0x01)`
|
|
||||||
- `LITE_FOPT_KEEP_MTIME (0x02)`
|
|
||||||
|
|
||||||
In releases prior to v2.0 the opt argument was called `symlink`.
|
|
||||||
The APIs are 100% compatible if the value `1` was used to enable
|
|
||||||
the symlink option.
|
|
||||||
|
|
||||||
- `dir(dir, ext, filter, list, strip)`
|
|
||||||
|
|
||||||
Wrapper for `scandir()` with optional filter. Returns a list of
|
|
||||||
names: files and directories that must be freed after use. See
|
|
||||||
the unit test for an example, or take a look at `glob(3)`, it's
|
|
||||||
probably what you want anyway.
|
|
||||||
|
|
||||||
- `fcopyfile(src, dst)`
|
|
||||||
|
|
||||||
Like `copyfile()` but uses already open `FILE *` pointers. Copies
|
|
||||||
from current file positions to current file positions until EOF.
|
|
||||||
|
|
||||||
- `fexist(file)`
|
|
||||||
|
|
||||||
Check for the existence of a file, returns True(1) or False(0).
|
|
||||||
|
|
||||||
- `fisdir(path)`
|
|
||||||
|
|
||||||
Check for the existence of a directory, returns True(1) or False(0).
|
|
||||||
|
|
||||||
- `fsendfile(src, dst, len)`
|
|
||||||
|
|
||||||
Copy data between file streams, very similar to `fcopyfile()`, but
|
|
||||||
`dst` is allowed to be `NULL` to be able to read and discard `len`
|
|
||||||
bytes from `src`.
|
|
||||||
|
|
||||||
- `ifconfig(ifname, addr, mask, up)`
|
|
||||||
|
|
||||||
Basic ifconfig like operations on an interface. Only supports IPv4
|
|
||||||
addresses. Note that mask is not CIDR notation.
|
|
||||||
|
|
||||||
- `lfopen(file, sep)`, `lfclose(lf)`
|
|
||||||
|
|
||||||
LITE file API for parsing UNIX style configuration files like
|
|
||||||
`/etc/protocols` and `/etc/services`.
|
|
||||||
|
|
||||||
- `lftok(lf)`
|
|
||||||
|
|
||||||
Read tokens, delimited by `sep`, from file opened with `lfopen()`.
|
|
||||||
|
|
||||||
- `lfgetkey(lf, key)`
|
|
||||||
|
|
||||||
Find `key` in file opened with `lfopen()`, return value/argument.
|
|
||||||
|
|
||||||
- `lfgetint(lf, key)`
|
|
||||||
|
|
||||||
Wrapper for `lfgetkey()`, returns positive integer value to `key`,
|
|
||||||
or `-1` if `key` is not found.
|
|
||||||
|
|
||||||
- `fgetint(file, sep, key)`
|
|
||||||
|
|
||||||
Wrapper for `lfopen()`, `lfgetint()`, and `lfclose()`. Useful for
|
|
||||||
when only reading a single `key` from a file.
|
|
||||||
|
|
||||||
- `makepath(dir)`
|
|
||||||
|
|
||||||
Create all components of the specified directory.
|
|
||||||
|
|
||||||
- `mkpath(dir, mode)`
|
|
||||||
|
|
||||||
Like `makepath()`, but also takes a `mode_t` permission mode argument.
|
|
||||||
|
|
||||||
- `movefile(src, dst)`
|
|
||||||
|
|
||||||
Like `copyfile()`, but renames `src` to `dst`, or recreates symlink
|
|
||||||
with the `dst` name. On successful operation the source is removed
|
|
||||||
and the function returns POSIX OK (0).
|
|
||||||
|
|
||||||
- `pidfile(name)`
|
|
||||||
|
|
||||||
Create a daemon PID file using either the `name` as a full path, if
|
|
||||||
`name` starts with `/`, or in `_PATH_VARRUN` using `name` as the
|
|
||||||
basename of the application. If `name` is `NULL`, then `__progname`
|
|
||||||
is used as the basename. The resulting file name is available to the
|
|
||||||
user as a read-only pointer:
|
|
||||||
|
|
||||||
extern char *__pidfile_name;
|
|
||||||
|
|
||||||
Use this function to create a PID file for your daemon when it is
|
|
||||||
ready to receive signals. A client application may poll for the
|
|
||||||
existence of this file, so make sure to have your signal handlers
|
|
||||||
properly setup before calling this function.
|
|
||||||
|
|
||||||
The PID file is removed when the program exits, using an `atexit()`
|
|
||||||
handler. However, depending on how the program terminates the file
|
|
||||||
may still exist even though the program is no longer running.
|
|
||||||
|
|
||||||
Calling this function multiple times updates the mtime of the file.
|
|
||||||
Only one `atexit()` handler is created, regardless of the amount of
|
|
||||||
times the function is called. If the file is removed, subsequent
|
|
||||||
calls to this function will recreate the file.
|
|
||||||
|
|
||||||
See below for a link to OpenBSD man page.
|
|
||||||
|
|
||||||
- `pidfile_read(pidfile)`
|
|
||||||
|
|
||||||
Read PID from pid file created by `pidfile()`.
|
|
||||||
|
|
||||||
- `pidfile_signal(pidfile, signal)`
|
|
||||||
|
|
||||||
Send signal to PID found in pid file created by `pidfile()`.
|
|
||||||
|
|
||||||
- `progress(percent, max_width)`
|
|
||||||
|
|
||||||
Simple ASCII progress bar with a spinner. Start it with `percent=0`
|
|
||||||
and set the `max_width=chars` to indicate width of the progress bar.
|
|
||||||
Called multiple times with the same percentage value cause spinner to
|
|
||||||
spin.
|
|
||||||
|
|
||||||
- `rsync(src, dst, opt, *filter())`
|
|
||||||
|
|
||||||
Very simple `rsync()` to copy files and directories recursively. It
|
|
||||||
supports pruning files from the destination tree that do not exist in
|
|
||||||
the source tree and preserving the mtime of the source files. The opt
|
|
||||||
argument can be a mask of:
|
|
||||||
|
|
||||||
- `LITE_FOPT_RSYNC_DELETE (0x01)`
|
|
||||||
- `LITE_FOPT_KEEP_MTIME (0x02)`
|
|
||||||
|
|
||||||
In releases prior to v2.0 the argument controlling pruning was called
|
|
||||||
`delete`, it is now called `opt`. The APIs are 100% compatible if the
|
|
||||||
value `1` was used.
|
|
||||||
|
|
||||||
- `strmatch()`, `strnmatch()`
|
|
||||||
|
|
||||||
Find matching string in an array of strings. Returns index in array
|
|
||||||
on match, or `-1` on error or not found.
|
|
||||||
|
|
||||||
- `telnet_open(), telnet_close(), telnet_expect()`
|
|
||||||
|
|
||||||
Poor mans telnet expect in C. Opens connection to a Telnet service;
|
|
||||||
FTP, Telnet, similar, and run an expect-like script.
|
|
||||||
|
|
||||||
- `telnet_session()`
|
|
||||||
|
|
||||||
Wrapper for the above three in one API.
|
|
||||||
|
|
||||||
- `tempfile()`
|
|
||||||
|
|
||||||
Secure replacement for `tmpfile()`. Creates an invisible temporary
|
|
||||||
file in `/tmp` that is removed when the returned `FILE` pointer is
|
|
||||||
closed.
|
|
||||||
|
|
||||||
**Note:** Requires Linux v3.11, or later, will fall back to the old
|
|
||||||
and unsafe `tmpfile()` on older systems.
|
|
||||||
|
|
||||||
- `which(cmd)`, `whichp(cmd)`
|
|
||||||
|
|
||||||
C implementation of UNIX which(1). Returns a malloc'ed string with the
|
|
||||||
full path to `cmd` on success, otherwise `NULL`.
|
|
||||||
|
|
||||||
`whichp()` is a predicate function, returns `TRUE` or `FALSE`.
|
|
||||||
|
|
||||||
**Note:** `which("/bin/ps aux")` will return `/bin/ps`, or `TRUE`,
|
|
||||||
provided of course `/bin/ps` exists.
|
|
||||||
|
|
||||||
- `yorn(fmt, ...)`
|
|
||||||
|
|
||||||
Pose a question to user, appended with `(y/N)?`, returns `TRUE` for
|
|
||||||
yes (both `y` and `Y` are handled) and `FALSE` for everything else.
|
|
||||||
|
|
||||||
|
|
||||||
GNU Functions
|
|
||||||
-------------
|
|
||||||
|
|
||||||
The following are useful GNU functions, that do not exist on *BSD, and
|
|
||||||
some other platforms.
|
|
||||||
|
|
||||||
- `strdupa(str)`
|
|
||||||
|
|
||||||
http://man7.org/linux/man-pages/man3/strdupa.3.html
|
|
||||||
|
|
||||||
- `strndupa(str)`
|
|
||||||
|
|
||||||
http://man7.org/linux/man-pages/man3/strndupa.3.html
|
|
||||||
|
|
||||||
- `strnlen(str, lim)`
|
|
||||||
|
|
||||||
http://man7.org/linux/man-pages/man3/strnlen.3.html
|
|
||||||
|
|
||||||
|
|
||||||
OpenBSD/NetBSD/FreeBSD Functions
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
The following are popular functions and highly useful macros from the
|
|
||||||
*BSD world of UNIX that are sadly missing on Linux.
|
|
||||||
|
|
||||||
- `fparseln(fp, *len, *lineno, delim, flags)`
|
|
||||||
|
|
||||||
http://man.openbsd.org/OpenBSD-current/man3/fparseln.3
|
|
||||||
|
|
||||||
- `pidfile(basename)`
|
|
||||||
|
|
||||||
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/pidfile.3
|
|
||||||
|
|
||||||
**Note:** the version of `pidfile()` in -lite has been extended to
|
|
||||||
handle it being called multiple times, i.e. to not create multiple
|
|
||||||
`atexit()` handlers, and also to export a few internal paths:
|
|
||||||
|
|
||||||
- `__pidfile_path`: prefix path, default `_PATH_VARRUN`. Notice the
|
|
||||||
trailing slash requirement if you want to override it!
|
|
||||||
- `__pidfile_name`: full path to PID file , similar to `__progname`.
|
|
||||||
See previous section for details.
|
|
||||||
|
|
||||||
- `reallocarray(ptr, nmemb, size)`
|
|
||||||
|
|
||||||
http://man.openbsd.org/OpenBSD-current/man3/reallocarray.3
|
|
||||||
|
|
||||||
- `strlcpy(dst, src, len)`
|
|
||||||
|
|
||||||
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/strlcpy.3
|
|
||||||
|
|
||||||
- `strlcat(dst, src, len)`
|
|
||||||
|
|
||||||
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/strlcat.3
|
|
||||||
|
|
||||||
- `strtonum()`
|
|
||||||
|
|
||||||
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/strtonum.3
|
|
||||||
|
|
||||||
- `sys/queue.h` API
|
|
||||||
|
|
||||||
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/LIST_EMPTY.3
|
|
||||||
|
|
||||||
- `sys/tree.h` API
|
|
||||||
|
|
||||||
Niels Provos' famous splay and red-black tree implementation.
|
|
||||||
|
|
||||||
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/SPLAY_FOREACH.3
|
|
||||||
|
|
||||||
|
|
||||||
Build & Install
|
Build & Install
|
||||||
@@ -398,24 +103,47 @@ Build & Install
|
|||||||
This library was initially built for and developed on GNU/Linux systems
|
This library was initially built for and developed on GNU/Linux systems
|
||||||
as a light weight utility library, these days NetBSD should also work.
|
as a light weight utility library, these days NetBSD should also work.
|
||||||
|
|
||||||
./configure
|
```bash
|
||||||
make -j5
|
$ ./configure
|
||||||
sudo make install-strip
|
$ make -j5
|
||||||
sudo ldconfig
|
$ sudo make install-strip
|
||||||
|
$ sudo ldconfig
|
||||||
|
```
|
||||||
|
|
||||||
|
Use <kbd>./configure --without-symlink</kbd> to prevent the install step
|
||||||
|
from creating the `lite -> libite/` compatibility symlink for the header
|
||||||
|
files, required for systems with DirectFB LiTE. The default, however,
|
||||||
|
is to install the symlink to ensure compatibility with existing software
|
||||||
|
that depends on the `-lite` library headers in their previous namespace.
|
||||||
|
|
||||||
**Note:** When checking out code from GIT, use <kbd>./autogen.sh</kbd>
|
**Note:** When checking out code from GIT, use <kbd>./autogen.sh</kbd>
|
||||||
to generate a `configure` script. It is a generated file and otherwise
|
to generate a `configure` script. It is a generated file and otherwise
|
||||||
only included in released tarballs.
|
only included in released tarballs.
|
||||||
|
|
||||||
|
|
||||||
[1]: https://github.com/troglobit/finit
|
Origin & References
|
||||||
[2]: http://www.openbsd.org/
|
-------------------
|
||||||
[3]: http://www.openbsd.org/cgi-bin/man.cgi?query=strlcpy
|
|
||||||
[4]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/LIST_EMPTY.3
|
Much of the code in libite (-lite) is written by [Claudio Matsuoka][]
|
||||||
[5]: https://developer.gnome.org/glib/
|
for the original [Finit][original finit] and released under the MIT/X11
|
||||||
[7]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/SPLAY_FOREACH.3
|
license. Joachim Wiberg later improved on the [Finit][1] code base and
|
||||||
[MIT]: https://en.wikipedia.org/wiki/MIT_License
|
included pieces of software released under the ISC and BSD licenses.
|
||||||
[ISC]: https://en.wikipedia.org/wiki/ISC_license
|
See each respective file for license details.
|
||||||
[BSD]: https://en.wikipedia.org/wiki/BSD_licenses
|
|
||||||
[Travis]: https://travis-ci.org/troglobit/libite
|
[1]: https://github.com/troglobit/finit
|
||||||
[Travis Status]: https://travis-ci.org/troglobit/libite.png?branch=master
|
[2]: http://www.openbsd.org/
|
||||||
|
[3]: http://www.openbsd.org/cgi-bin/man.cgi?query=strlcpy
|
||||||
|
[4]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/LIST_EMPTY.3
|
||||||
|
[5]: https://developer.gnome.org/glib/
|
||||||
|
[7]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/SPLAY_FOREACH.3
|
||||||
|
[MIT]: https://en.wikipedia.org/wiki/MIT_License
|
||||||
|
[ISC]: https://en.wikipedia.org/wiki/ISC_license
|
||||||
|
[BSD]: https://en.wikipedia.org/wiki/BSD_licenses
|
||||||
|
[GitHub]: https://github.com/troglobit/libite/actions/workflows/build.yml/
|
||||||
|
[GitHub Status]: https://github.com/troglobit/libite/actions/workflows/build.yml/badge.svg
|
||||||
|
[Coverity Scan]: https://scan.coverity.com/projects/20602
|
||||||
|
[Coverity Status]: https://img.shields.io/coverity/scan/20602.svg
|
||||||
|
[codedocs]: https://codedocs.xyz/troglobit/libite.log
|
||||||
|
[codedocs status]: https://codedocs.xyz/troglobit/libite.svg
|
||||||
|
[Claudio Matsuoka]: https://github.com/cmatsuoka
|
||||||
|
[original finit]: http://helllabs.org/finit/
|
||||||
+28
-5
@@ -1,16 +1,39 @@
|
|||||||
AC_INIT(libite, 2.1.2, https://github.com/troglobit/libite/issues)
|
AC_INIT(libite, 2.6.1, https://github.com/troglobit/libite/issues)
|
||||||
AC_CONFIG_AUX_DIR(aux)
|
AC_CONFIG_AUX_DIR(aux)
|
||||||
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz])
|
AM_INIT_AUTOMAKE([1.11 foreign dist-xz])
|
||||||
AM_SILENT_RULES([yes])
|
AM_SILENT_RULES([yes])
|
||||||
|
|
||||||
AC_CONFIG_SRCDIR(src/lite.h)
|
AC_CONFIG_SRCDIR(src/lite.h)
|
||||||
AM_CONFIG_HEADER(config.h)
|
AC_CONFIG_HEADERS(config.h)
|
||||||
AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile libite.pc])
|
AC_CONFIG_FILES([Makefile doc/Makefile doc/Doxyfile src/Makefile src/libite.pc test/Makefile])
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
|
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
AC_PROG_INSTALL
|
AC_PROG_INSTALL
|
||||||
AM_PROG_AR
|
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
|
||||||
LT_INIT
|
LT_INIT
|
||||||
|
|
||||||
|
# Check for Doxygen and enable its features.
|
||||||
|
# For details, see m4/ax_prog_doxygen.m4 and
|
||||||
|
# http://www.bioinf.uni-freiburg.de/~mmann/HowTo/automake.html#doxygenSupport
|
||||||
|
DX_DOXYGEN_FEATURE(ON)
|
||||||
|
DX_DOT_FEATURE(OFF)
|
||||||
|
DX_CHI_FEATURE(OFF)
|
||||||
|
DX_RTF_FEATURE(OFF)
|
||||||
|
DX_XML_FEATURE(OFF)
|
||||||
|
DX_PDF_FEATURE(OFF)
|
||||||
|
DX_PS_FEATURE(OFF)
|
||||||
|
DX_CHM_FEATURE(OFF)
|
||||||
|
DX_HTML_FEATURE(ON)
|
||||||
|
DX_MAN_FEATURE(OFF)
|
||||||
|
DX_INIT_DOXYGEN(${PACKAGE_NAME}, [${top_builddir}/doc/Doxyfile], [${top_builddir}/doc])
|
||||||
|
|
||||||
|
AC_ARG_WITH([symlink],
|
||||||
|
AS_HELP_STRING([--without-symlink], [Disable compat /usr/include/lite -> libite symlink]),,
|
||||||
|
[with_symlink=yes])
|
||||||
|
|
||||||
|
AM_CONDITIONAL([ENABLE_DOXYGEN], [test "x${DX_FLAG_doc}" = x1])
|
||||||
|
AM_CONDITIONAL([ENABLE_HTML], [test "x${DX_FLAG_html}" = x1])
|
||||||
|
AM_CONDITIONAL([COMPAT_SYMLINK], [test "x$with_symlink" != "xno"])
|
||||||
|
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
*.substvars
|
*.substvars
|
||||||
.debhelper/*
|
.debhelper/*
|
||||||
tmp/*
|
tmp/*
|
||||||
|
libite/*
|
||||||
libite5/*
|
libite5/*
|
||||||
libite-dev/*
|
libite-dev/*
|
||||||
autoreconf*
|
autoreconf*
|
||||||
|
|||||||
Vendored
+90
@@ -1,3 +1,93 @@
|
|||||||
|
libite (2.6.0) stable; urgency=medium
|
||||||
|
|
||||||
|
* New APIs from Infix Project:
|
||||||
|
- fexistf()
|
||||||
|
- vfopenf()
|
||||||
|
- popenf()
|
||||||
|
- vreadsnf(), readsnf(), writesf()
|
||||||
|
- vreadllf(), readllf(), readdf()
|
||||||
|
- writellf(), writedf()
|
||||||
|
* Spellchecking of API docs
|
||||||
|
|
||||||
|
-- Joachim Wiberg <troglobit@gmail.com> Sun, 17 Sep 2023 12:16:47 +0200
|
||||||
|
|
||||||
|
libite (2.5.3) stable; urgency=medium
|
||||||
|
|
||||||
|
* rsync() does not copy single files correctly
|
||||||
|
* copyfile() does not handle empty source files correctly (error)
|
||||||
|
* copyfile() does not properly create destination dir
|
||||||
|
* Add printf format attribute hint to all vararg functions
|
||||||
|
* Fix fisdir() segfault on GNU/Hurd
|
||||||
|
* Fix touch() on Debian/kFreeBSD, use creat() instad of mknod()
|
||||||
|
|
||||||
|
-- Joachim Wiberg <troglobit@gmail.com> Sat, 08 Apr 2023 07:04:00 +0200
|
||||||
|
|
||||||
|
libite (2.5.1) stable; urgency=medium
|
||||||
|
|
||||||
|
* Use dh_link(1) to install `/usr/include/lite -> libite/`.
|
||||||
|
|
||||||
|
-- Joachim Wiberg <troglobit@gmail.com> Thu, 02 Dec 2021 00:08:41 +0100
|
||||||
|
|
||||||
|
libite (2.5.0) stable; urgency=medium
|
||||||
|
|
||||||
|
* Header files have moved from `lite/*.h` to `libite/*.h` to prevent
|
||||||
|
clashing with DirectFB LiTE library. For a transitional period,
|
||||||
|
however, a compatibility symlink is installed; `lite -> libite/`.
|
||||||
|
|
||||||
|
-- Joachim Wiberg <troglobit@gmail.com> Tue, 30 Nov 2021 06:57:17 +0100
|
||||||
|
|
||||||
|
libite (2.4.1) stable; urgency=medium
|
||||||
|
|
||||||
|
* Add doxygen documentation, https://codedocs.xyz/troglobit/libite/
|
||||||
|
* Fix issue with tempfile() returning EOPNOTSUP on certain file systems,
|
||||||
|
added fallback that uses mkstemp() with O_CLOEXEC flag set
|
||||||
|
|
||||||
|
-- Joachim Wiberg <troglobit@gmail.com> Sat, 09 Oct 2021 08:56:43 +0200
|
||||||
|
|
||||||
|
libite (2.4.0) stable; urgency=medium
|
||||||
|
|
||||||
|
* New functions:
|
||||||
|
- touchf(), formatted string support for touch()
|
||||||
|
- erasef(), formatted string support for erase()
|
||||||
|
- strtrim(), trims leading and trailing white-space from a string
|
||||||
|
* Fix systemf() improper handling of system() return value. Now checks
|
||||||
|
if exited OK, then returning the exit status of the command, or if not
|
||||||
|
exited OK, then checks if the command was signaled, and returns -1 with
|
||||||
|
errno set. This also allows for returning 127, like system(), if the
|
||||||
|
shell, or the program itself, did not exist.
|
||||||
|
|
||||||
|
-- Joachim Wiberg <troglobit@gmail.com> Sat, 27 Mar 2021 09:12:32 +0100
|
||||||
|
|
||||||
|
libite (2.3.1) stable; urgency=medium
|
||||||
|
|
||||||
|
* Minor packaging fixes.
|
||||||
|
* Copyright updates, including LICENSE file, year + author last name
|
||||||
|
|
||||||
|
-- Joachim Wiberg <troglobit@gmail.com> Fri, 12 Feb 2021 15:10:42 +0100
|
||||||
|
|
||||||
|
libite (2.3.0) stable; urgency=medium
|
||||||
|
|
||||||
|
* New functions:
|
||||||
|
- Add support for fremove(), formatted remove() replacement
|
||||||
|
- Add support for truncatef(), formatted truncate() replacement
|
||||||
|
* Fixes
|
||||||
|
- Handle ETIMEDOUT error for connect() call in telnet_open()
|
||||||
|
|
||||||
|
-- Joachim Wiberg <troglobit@gmail.com> Fri, 12 Feb 2021 08:03:47 +0100
|
||||||
|
|
||||||
|
libite (2.2.0) stable; urgency=medium
|
||||||
|
|
||||||
|
* New functions:
|
||||||
|
- systemf(), formatted string system() replacement
|
||||||
|
- fmkpath(), formatted string mkpath() replacement
|
||||||
|
- fopenf(), formatted string fopen() replacement
|
||||||
|
* Fixes
|
||||||
|
- possible memory leak in rsync()
|
||||||
|
- Check return value of fstat() to prevent bogus destination file
|
||||||
|
times when using copyfile()
|
||||||
|
|
||||||
|
-- Joachim Nilsson <troglobit@gmail.com> Mon, 16 Mar 2020 15:42:02 +0100
|
||||||
|
|
||||||
libite (2.1.2) stable; urgency=high
|
libite (2.1.2) stable; urgency=high
|
||||||
|
|
||||||
* Fix upgrade of base package, new library name to match SONAME
|
* Fix upgrade of base package, new library name to match SONAME
|
||||||
|
|||||||
Vendored
+6
-5
@@ -1,12 +1,13 @@
|
|||||||
Source: libite
|
Source: libite
|
||||||
Priority: optional
|
|
||||||
Maintainer: Joachim Nilsson <troglobit@gmail.com>
|
|
||||||
Build-Depends: debhelper (>= 10)
|
|
||||||
Standards-Version: 4.3.0
|
|
||||||
Section: libs
|
Section: libs
|
||||||
|
Priority: optional
|
||||||
|
Maintainer: Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
Build-Depends: debhelper (>= 10)
|
||||||
|
Build-Depends-Indep: doxygen
|
||||||
|
Standards-Version: 4.3.0
|
||||||
Homepage: https://github.com/troglobit/libite/
|
Homepage: https://github.com/troglobit/libite/
|
||||||
Vcs-Git: https://github.com/troglobit/libite.git
|
|
||||||
Vcs-Browser: https://github.com/troglobit/libite/
|
Vcs-Browser: https://github.com/troglobit/libite/
|
||||||
|
Vcs-Git: https://github.com/troglobit/libite.git
|
||||||
|
|
||||||
Package: libite-dev
|
Package: libite-dev
|
||||||
Priority: optional
|
Priority: optional
|
||||||
|
|||||||
Vendored
+46
-14
@@ -4,7 +4,7 @@ Source: https.//github.com/troglobit/libite/
|
|||||||
Files: *
|
Files: *
|
||||||
Copyright:
|
Copyright:
|
||||||
2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
|
2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
|
||||||
2008-2020 Joachim Nilsson <troglobit@gmail.com>
|
2008-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
License: MIT
|
License: MIT
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -25,25 +25,49 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
|
|
||||||
Files: chomp.c
|
Files: chomp.c
|
||||||
Copyright: 2014-2020 Joachim Nilsson <troglobit@gmail.com>
|
Copyright: 2014-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
License: ISC
|
License: ISC
|
||||||
|
|
||||||
Files: conio.h
|
Files: conio.?
|
||||||
Copyright: 2009-2020 Joachim Nilsson <troglobit@gmail.com>
|
Copyright: 2009-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
License: ISC
|
License: ISC
|
||||||
|
|
||||||
Files: dir.c
|
Files: dir.c
|
||||||
Copyright: 2008-2020 Joachim Nilsson <troglobit@gmail.com>
|
Copyright: 2008-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
License: ISC
|
License: ISC
|
||||||
|
|
||||||
|
Files: fopenf.c fremove.c systemf.c truncatef.c
|
||||||
|
Copyright: 2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: fparseln.c
|
||||||
|
Copyright: 1997 Christos Zoulas
|
||||||
|
License: BSD-2-clause
|
||||||
|
|
||||||
|
Files: fsendfile.c
|
||||||
|
Copyright: 2013 Tobias Waldekranz <tobias@waldekranz.com>
|
||||||
|
License: MIT
|
||||||
|
|
||||||
Files: lfile.c
|
Files: lfile.c
|
||||||
Copyright: 2015-2020 Joachim Nilsson <troglobit@gmail.com>
|
Copyright: 2015-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: makepath.c
|
||||||
|
Copyright: 2016-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
License: ISC
|
License: ISC
|
||||||
|
|
||||||
Files: pidfile.c
|
Files: pidfile.c
|
||||||
Copyright: 1999 The NetBSD Foundation, Inc.
|
Copyright: 1999 The NetBSD Foundation, Inc.
|
||||||
License: BSD-2-clause
|
License: BSD-2-clause
|
||||||
|
|
||||||
|
Files: pidfilefn.c
|
||||||
|
Copyright: 2009-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: progress.c
|
||||||
|
Copyright: 2012-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
Files: queue.h
|
Files: queue.h
|
||||||
Copyright: 1991, 1993 The Regents of the University of California.
|
Copyright: 1991, 1993 The Regents of the University of California.
|
||||||
License: BSD-3-clause
|
License: BSD-3-clause
|
||||||
@@ -53,7 +77,7 @@ Copyright: 2008 Otto Moerbeek <otto@drijf.net>
|
|||||||
License: ISC
|
License: ISC
|
||||||
|
|
||||||
Files: rsync.c
|
Files: rsync.c
|
||||||
Copyright: 2011-2020 Joachim Nilsson <troglobit@gmail.com>
|
Copyright: 2011-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
License: ISC
|
License: ISC
|
||||||
|
|
||||||
Files: strdupa.h strndupa.h
|
Files: strdupa.h strndupa.h
|
||||||
@@ -64,12 +88,16 @@ Files: strlcat.c strlcpy.c
|
|||||||
Copyright: 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
Copyright: 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
License: MIT
|
License: MIT
|
||||||
|
|
||||||
|
Files: strlite.h
|
||||||
|
Copyright: 2008-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
License: MIT
|
||||||
|
|
||||||
Files: strmatch.c
|
Files: strmatch.c
|
||||||
Copyright: 2009-2020 Joachim Nilsson <troglobit@gmail.com>
|
Copyright: 2009-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
License: ISC
|
License: ISC
|
||||||
|
|
||||||
Files: strnlen.c
|
Files: strnlen.c
|
||||||
Copyright: 2016-2020 Joachim Nilsson <troglobit@gmail.com>
|
Copyright: 2016-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
License: ISC
|
License: ISC
|
||||||
|
|
||||||
Files: strtonum.c
|
Files: strtonum.c
|
||||||
@@ -77,20 +105,24 @@ Copyright: 2004 Ted Unangst and Todd Miller
|
|||||||
License: ISC
|
License: ISC
|
||||||
|
|
||||||
Files: telnet.c
|
Files: telnet.c
|
||||||
Copyright: 2010-2020 Joachim Nilsson <troglobit@gmail.com>
|
Copyright: 2010-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
License: ISC
|
License: ISC
|
||||||
|
|
||||||
Files: tempfile.c
|
Files: tempfile.c
|
||||||
Copyright: 2015-2020 Joachim Nilsson <troglobit@gmail.com>
|
Copyright: 2015-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
License: ISC
|
License: ISC
|
||||||
|
|
||||||
Files: tree.h
|
Files: tree.h
|
||||||
Copyright: 2002 Niels Provos <provos@citi.umich.edu>
|
Copyright: 2002 Niels Provos <provos@citi.umich.edu>
|
||||||
License: BSD-2-clause
|
License: BSD-2-clause
|
||||||
|
|
||||||
Files: yorn.c
|
Files: which.c
|
||||||
Copyright: 2009-2020 Joachim Nilsson <troglobit@gmail.com>
|
Copyright: 2017-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
License: ISC
|
License: ISC
|
||||||
|
|
||||||
Files: tests/*.c
|
Files: yorn.c
|
||||||
|
Copyright: 2009-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
License: ISC
|
||||||
|
|
||||||
|
Files: test/*.c
|
||||||
License: public-domain
|
License: public-domain
|
||||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
usr/include/lite/*.h
|
usr/include/libite/*.h
|
||||||
usr/lib/*/lib*.a
|
usr/lib/*/lib*.a
|
||||||
usr/lib/*/lib*.so
|
usr/lib/*/lib*.so
|
||||||
usr/lib/*/pkgconfig/lib*.pc
|
usr/lib/*/pkgconfig/lib*.pc
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
/usr/include/libite /usr/include/lite
|
||||||
Vendored
+8
-1
@@ -5,11 +5,15 @@ libite.so.5 libite5 #MINVER#
|
|||||||
chomp@Base 2.0.0
|
chomp@Base 2.0.0
|
||||||
copyfile@Base 2.0.0
|
copyfile@Base 2.0.0
|
||||||
dir@Base 2.0.0
|
dir@Base 2.0.0
|
||||||
|
erasef@Base 2.4.0
|
||||||
fcopyfile@Base 2.0.0
|
fcopyfile@Base 2.0.0
|
||||||
fexist@Base 2.0.0
|
fexist@Base 2.0.0
|
||||||
fgetint@Base 2.0.0
|
fgetint@Base 2.0.0
|
||||||
fisdir@Base 2.0.0
|
fisdir@Base 2.0.0
|
||||||
|
fmkpath@Base 2.2.0
|
||||||
|
fopenf@Base 2.2.0
|
||||||
fparseln@Base 2.0.0
|
fparseln@Base 2.0.0
|
||||||
|
fremove@Base 2.3.0
|
||||||
fsendfile@Base 2.0.0
|
fsendfile@Base 2.0.0
|
||||||
ifconfig@Base 2.0.0
|
ifconfig@Base 2.0.0
|
||||||
initscr@Base 2.0.0
|
initscr@Base 2.0.0
|
||||||
@@ -29,17 +33,20 @@ libite.so.5 libite5 #MINVER#
|
|||||||
progress_simple@Base 2.0.0
|
progress_simple@Base 2.0.0
|
||||||
reallocarray@Base 2.0.0
|
reallocarray@Base 2.0.0
|
||||||
rsync@Base 2.0.0
|
rsync@Base 2.0.0
|
||||||
sdbuf@Base 2.0.0
|
|
||||||
strlcat@Base 2.0.0
|
strlcat@Base 2.0.0
|
||||||
strlcpy@Base 2.0.0
|
strlcpy@Base 2.0.0
|
||||||
strmatch@Base 2.1.0
|
strmatch@Base 2.1.0
|
||||||
strnmatch@Base 2.1.0
|
strnmatch@Base 2.1.0
|
||||||
strtonum@Base 2.1.0
|
strtonum@Base 2.1.0
|
||||||
|
strtrim@Base 2.4.0
|
||||||
|
systemf@Base 2.2.0
|
||||||
telnet_close@Base 2.1.0
|
telnet_close@Base 2.1.0
|
||||||
telnet_expect@Base 2.1.0
|
telnet_expect@Base 2.1.0
|
||||||
telnet_open@Base 2.1.0
|
telnet_open@Base 2.1.0
|
||||||
telnet_session@Base 2.1.0
|
telnet_session@Base 2.1.0
|
||||||
tempfile@Base 2.0.0
|
tempfile@Base 2.0.0
|
||||||
|
touchf@Base 2.4.0
|
||||||
|
truncatef@Base 2.3.0
|
||||||
which@Base 2.0.0
|
which@Base 2.0.0
|
||||||
whichp@Base 2.0.0
|
whichp@Base 2.0.0
|
||||||
yorn@Base 2.1.0
|
yorn@Base 2.1.0
|
||||||
Vendored
+7
-5
@@ -1,15 +1,17 @@
|
|||||||
#!/usr/bin/make -f
|
#!/usr/bin/make -f
|
||||||
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
|
|
||||||
|
|
||||||
# Uncomment this to turn on verbose mode.
|
# Uncomment this to turn on verbose mode.
|
||||||
#export DH_VERBOSE=1
|
#export DH_VERBOSE=1
|
||||||
|
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
|
||||||
|
|
||||||
%:
|
%:
|
||||||
dh $@ --with autoreconf
|
dh $@ --with autoreconf
|
||||||
|
|
||||||
override_dh_auto_install:
|
override_dh_auto_configure:
|
||||||
dh_auto_install
|
dh_auto_configure -- --without-symlink
|
||||||
-rm -f debian/libite/usr/share/doc/libite/LICENSE
|
|
||||||
|
|
||||||
override_dh_installchangelogs:
|
override_dh_installchangelogs:
|
||||||
dh_installchangelogs ChangeLog.md
|
dh_installchangelogs ChangeLog.md
|
||||||
|
|
||||||
|
override_dh_auto_install:
|
||||||
|
dh_auto_install
|
||||||
|
find debian -name LICENSE -delete
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
html/*
|
||||||
|
libite.tag
|
||||||
|
Doxyfile
|
||||||
+459
@@ -0,0 +1,459 @@
|
|||||||
|
API Documentation
|
||||||
|
=================
|
||||||
|
|
||||||
|
|
||||||
|
Important Note
|
||||||
|
--------------
|
||||||
|
|
||||||
|
When using functions like `mkpath()`, `makepath()`, and `makefifo()`,
|
||||||
|
make sure your `umask()` is correct so you do not accidentally create
|
||||||
|
files and directories accessible to other users than intended.
|
||||||
|
|
||||||
|
|
||||||
|
Helper Macros
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- `atonum(str)`
|
||||||
|
|
||||||
|
Convert string to natural number, works for 32-bit non-negative
|
||||||
|
integers. Returns -1 on error. (Uses `strtonum()` internally.)
|
||||||
|
|
||||||
|
- `blkdev(dev)`
|
||||||
|
|
||||||
|
Create block device
|
||||||
|
|
||||||
|
- `chardev(dev)`
|
||||||
|
|
||||||
|
Create character device
|
||||||
|
|
||||||
|
- `erase(path)`
|
||||||
|
|
||||||
|
Erase file/directory with `remove()`. Errors on `stderr`
|
||||||
|
|
||||||
|
- `erasef(fmt, ...)`
|
||||||
|
|
||||||
|
Like `erase()` but takes a formatted printf-like string as argument.
|
||||||
|
|
||||||
|
- `makedir(path)`
|
||||||
|
|
||||||
|
Create directory, like `mkdir()`. Errors on `stderr`
|
||||||
|
|
||||||
|
- `makefifo(path)`
|
||||||
|
|
||||||
|
Create a FIFO, like `mkfifo()`. Errors on `stderr`
|
||||||
|
|
||||||
|
- `min(a,b)`/`max(a,b)`
|
||||||
|
|
||||||
|
These macros take care to avoid double evaluation.
|
||||||
|
|
||||||
|
- `touch(path)`
|
||||||
|
|
||||||
|
Create a file, or update mtime. Errors on `stderr`
|
||||||
|
|
||||||
|
- `touchf(fmt, ...)`
|
||||||
|
|
||||||
|
Like `touch()` but takes a formatted printf-like string as argument.
|
||||||
|
|
||||||
|
- `S_ISEXEC(mode_t m)`
|
||||||
|
|
||||||
|
Mysteriously missing from GLIBC
|
||||||
|
|
||||||
|
- `ISCLR(word,bit)`
|
||||||
|
|
||||||
|
Is bit in (integer) word cleared?
|
||||||
|
|
||||||
|
- `ISSET(word,bit)`
|
||||||
|
|
||||||
|
Is bit in (integer) word set?
|
||||||
|
|
||||||
|
- `ISOTHER(word,bit)`
|
||||||
|
|
||||||
|
Are any other bits, except bit, in (integer) word set?
|
||||||
|
|
||||||
|
- `SETBIT(word,bit)`
|
||||||
|
|
||||||
|
Set bit in (integer) word.
|
||||||
|
|
||||||
|
- `CLRBIT(word,bit)`
|
||||||
|
|
||||||
|
Clear bit in (integer) word.
|
||||||
|
|
||||||
|
- `NELEMS(array)`
|
||||||
|
|
||||||
|
Returns the number of elements in an array. From the great book, The
|
||||||
|
Practice of Programming, by Kernighan and Pike.
|
||||||
|
|
||||||
|
|
||||||
|
Generic Functions
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
- `chomp(str)`
|
||||||
|
|
||||||
|
Perl like chomp function, chop off last char if newline.
|
||||||
|
|
||||||
|
- `copyfile(src, dst, len, opt)`
|
||||||
|
|
||||||
|
Like the shell `cp(1)` and `dd(1),`, can also copy symlinks and
|
||||||
|
preserve the mtime of the source file. The opt argument can be
|
||||||
|
a mask of:
|
||||||
|
|
||||||
|
- `LITE_FOPT_COPYFILE_SYM (0x01)`
|
||||||
|
- `LITE_FOPT_KEEP_MTIME (0x02)`
|
||||||
|
|
||||||
|
In releases prior to v2.0 the opt argument was called `symlink`.
|
||||||
|
The APIs are 100% compatible if the value `1` was used to enable
|
||||||
|
the symlink option.
|
||||||
|
|
||||||
|
- `dir(dir, ext, filter, list, strip)`
|
||||||
|
|
||||||
|
Wrapper for `scandir()` with optional filter. Returns a list of
|
||||||
|
names: files and directories that must be freed after use. See
|
||||||
|
the unit test for an example, or take a look at `glob(3)`, it's
|
||||||
|
probably what you want anyway.
|
||||||
|
|
||||||
|
- `fcopyfile(src, dst)`
|
||||||
|
|
||||||
|
Like `copyfile()` but uses already open `FILE *` pointers. Copies
|
||||||
|
from current file positions to current file positions until EOF.
|
||||||
|
|
||||||
|
- `fexist(file)`
|
||||||
|
|
||||||
|
Check for the existence of a file, returns True(1) or False(0).
|
||||||
|
|
||||||
|
- `fisdir(path)`
|
||||||
|
|
||||||
|
Check for the existence of a directory, returns True(1) or False(0).
|
||||||
|
|
||||||
|
- `fopenf(mode, fmt, ...)` and `vfopenf(mode, fmt, ap)`
|
||||||
|
|
||||||
|
Like `fopen()`, but takes a formatted string as argument. This
|
||||||
|
greatly simplifies operations that usually consist of composing a
|
||||||
|
filename from parts into a dynamic buffer before actually opening
|
||||||
|
the file.
|
||||||
|
|
||||||
|
> **Notice:** the swapped order of `pathname` and `mode`!
|
||||||
|
|
||||||
|
- `fremove(fmt, ...)`
|
||||||
|
|
||||||
|
Like `remove()`, but takes a formatted string as argument. This
|
||||||
|
greatly simplifies operations that usually consist of composing a
|
||||||
|
filename from parts into a dynamic buffer before actually removing
|
||||||
|
the file.
|
||||||
|
|
||||||
|
- `fsendfile(src, dst, len)`
|
||||||
|
|
||||||
|
Copy data between file streams, very similar to `fcopyfile()`, but
|
||||||
|
`dst` is allowed to be `NULL` to be able to read and discard `len`
|
||||||
|
bytes from `src`.
|
||||||
|
|
||||||
|
- `ifconfig(ifname, addr, mask, up)`
|
||||||
|
|
||||||
|
Basic ifconfig like operations on an interface. Only supports IPv4
|
||||||
|
addresses. Note that mask is not CIDR notation.
|
||||||
|
|
||||||
|
- `lfopen(file, sep)`, `lfclose(lf)`
|
||||||
|
|
||||||
|
LITE file API for parsing UNIX style configuration files like
|
||||||
|
`/etc/protocols` and `/etc/services`.
|
||||||
|
|
||||||
|
- `lftok(lf)`
|
||||||
|
|
||||||
|
Read tokens, delimited by `sep`, from file opened with `lfopen()`.
|
||||||
|
|
||||||
|
- `lfgetkey(lf, key)`
|
||||||
|
|
||||||
|
Find `key` in file opened with `lfopen()`, return value/argument.
|
||||||
|
|
||||||
|
- `lfgetint(lf, key)`
|
||||||
|
|
||||||
|
Wrapper for `lfgetkey()`, returns positive integer value to `key`,
|
||||||
|
or `-1` if `key` is not found.
|
||||||
|
|
||||||
|
- `fgetint(file, sep, key)`
|
||||||
|
|
||||||
|
Wrapper for `lfopen()`, `lfgetint()`, and `lfclose()`. Useful for
|
||||||
|
when only reading a single `key` from a file.
|
||||||
|
|
||||||
|
- `makepath(dir)`
|
||||||
|
|
||||||
|
Create all components of the specified directory.
|
||||||
|
|
||||||
|
- `mkpath(dir, mode)`
|
||||||
|
|
||||||
|
Like `makepath()`, but also takes a `mode_t` permission mode argument.
|
||||||
|
|
||||||
|
- `fmkpath(mode, fmt, ...)`
|
||||||
|
|
||||||
|
Like `mkpath()`, but takes a formatted string as argument.
|
||||||
|
|
||||||
|
> **Notice:** the swapped order of `pathname` and `mode`!
|
||||||
|
|
||||||
|
- `movefile(src, dst)`
|
||||||
|
|
||||||
|
Like `copyfile()`, but renames `src` to `dst`, or recreates symlink
|
||||||
|
with the `dst` name. On successful operation the source is removed
|
||||||
|
and the function returns POSIX OK (0).
|
||||||
|
|
||||||
|
- `pidfile(name)`
|
||||||
|
|
||||||
|
Create a daemon PID file using either the `name` as a full path, if
|
||||||
|
`name` starts with `/`, or in `_PATH_VARRUN` using `name` as the
|
||||||
|
basename of the application. If `name` is `NULL`, then `__progname`
|
||||||
|
is used as the basename. The resulting file name is available to the
|
||||||
|
user as a read-only pointer:
|
||||||
|
|
||||||
|
extern char *__pidfile_name;
|
||||||
|
|
||||||
|
Use this function to create a PID file for your daemon when it is
|
||||||
|
ready to receive signals. A client application may poll for the
|
||||||
|
existence of this file, so make sure to have your signal handlers
|
||||||
|
properly setup before calling this function.
|
||||||
|
|
||||||
|
The PID file is removed when the program exits, using an `atexit()`
|
||||||
|
handler. However, depending on how the program terminates the file
|
||||||
|
may still exist even though the program is no longer running.
|
||||||
|
|
||||||
|
Calling this function multiple times updates the mtime of the file.
|
||||||
|
Only one `atexit()` handler is created, regardless of the amount of
|
||||||
|
times the function is called. If the file is removed, subsequent
|
||||||
|
calls to this function will recreate the file.
|
||||||
|
|
||||||
|
See below for a link to OpenBSD man page.
|
||||||
|
|
||||||
|
- `pidfile_read(pidfile)`
|
||||||
|
|
||||||
|
Read PID from pid file created by `pidfile()`.
|
||||||
|
|
||||||
|
- `pidfile_signal(pidfile, signal)`
|
||||||
|
|
||||||
|
Send signal to PID found in pid file created by `pidfile()`.
|
||||||
|
|
||||||
|
- `progress(percent, max_width)`
|
||||||
|
|
||||||
|
Simple ASCII progress bar with a spinner. Start it with `percent=0`
|
||||||
|
and set the `max_width=chars` to indicate width of the progress bar.
|
||||||
|
Called multiple times with the same percentage value cause spinner to
|
||||||
|
spin.
|
||||||
|
|
||||||
|
- `rsync(src, dst, opt, *filter())`
|
||||||
|
|
||||||
|
Very simple `rsync()` to copy files and directories recursively. It
|
||||||
|
supports pruning files from the destination tree that do not exist in
|
||||||
|
the source tree and preserving the mtime of the source files. The opt
|
||||||
|
argument can be a mask of:
|
||||||
|
|
||||||
|
- `LITE_FOPT_RSYNC_DELETE (0x01)`
|
||||||
|
- `LITE_FOPT_KEEP_MTIME (0x02)`
|
||||||
|
|
||||||
|
In releases prior to v2.0 the argument controlling pruning was called
|
||||||
|
`delete`, it is now called `opt`. The APIs are 100% compatible if the
|
||||||
|
value `1` was used.
|
||||||
|
|
||||||
|
- `runbg(cmd, delay)`
|
||||||
|
|
||||||
|
Run a command in the background, after delay microseconds, essentially
|
||||||
|
a background `execvp()` with a delay. The function employs double-fork
|
||||||
|
to prevent zombies and closes all open files, including stdio.
|
||||||
|
|
||||||
|
```C
|
||||||
|
char *cmd[] = { "sh", "-c", "echo 'hej' >/tmp/foo", NULL};
|
||||||
|
|
||||||
|
runbg(cmd, 200000); /* Create /tmp/foo after 200 millisec */
|
||||||
|
/* Execution continues here immediately */
|
||||||
|
```
|
||||||
|
|
||||||
|
- `strmatch(str, list)`, `strnmatch(str, list, len)`
|
||||||
|
|
||||||
|
Find matching string in an array of strings. Returns index in array on
|
||||||
|
match, or `-1` on error or not found. `strnmatch()` takes an extra arg
|
||||||
|
to compare only `len` number of characters from `str`.
|
||||||
|
|
||||||
|
- `strtrim(str)`
|
||||||
|
|
||||||
|
Trims a string from any leading and trailing white-space, returns the
|
||||||
|
trimmed result in the same buffer.
|
||||||
|
|
||||||
|
- `systemf(fmt, ...)`
|
||||||
|
|
||||||
|
Like `system()`, but takes a formatted string as argument. This
|
||||||
|
greatly simplifies operations that usually consist of composing a
|
||||||
|
command from parts into a dynamic buffer before calling it.
|
||||||
|
|
||||||
|
- `telnet_open(addr, port), telnet_close(ctx), telnet_expect(ctx, script, output)`
|
||||||
|
|
||||||
|
Poor mans telnet expect in C. Opens connection to a Telnet service;
|
||||||
|
FTP, Telnet, similar, and run an expect-like script.
|
||||||
|
|
||||||
|
- `telnet_session(addr, port, script output)`
|
||||||
|
|
||||||
|
Wrapper for the above three in one API.
|
||||||
|
|
||||||
|
- `tempfile()`
|
||||||
|
|
||||||
|
Secure replacement for `tmpfile()`. Creates an invisible temporary
|
||||||
|
file in `/tmp` that is removed when the returned `FILE` pointer is
|
||||||
|
closed.
|
||||||
|
|
||||||
|
**Note:** Requires Linux v3.11, or later, will fall back to the old
|
||||||
|
and unsafe `tmpfile()` on older systems.
|
||||||
|
|
||||||
|
- `truncatef(length, fmt, ...)`
|
||||||
|
|
||||||
|
Like `truncate()`, but takes a formatted string as argument. This
|
||||||
|
simplifies some operations when the filename otherwise have to be
|
||||||
|
composed from parts into a separate array before calling the real
|
||||||
|
function.
|
||||||
|
|
||||||
|
- `which(cmd)`, `whichp(cmd)`
|
||||||
|
|
||||||
|
C implementation of UNIX which(1). Returns a malloc'ed string with the
|
||||||
|
full path to `cmd` on success, otherwise `NULL`.
|
||||||
|
|
||||||
|
`whichp()` is a predicate function, returns `TRUE` or `FALSE`.
|
||||||
|
|
||||||
|
**Note:** `which("/bin/ps aux")` will return `/bin/ps`, or `TRUE`,
|
||||||
|
provided of course `/bin/ps` exists.
|
||||||
|
|
||||||
|
- `yorn(fmt, ...)`
|
||||||
|
|
||||||
|
Pose a question to user, appended with `(y/N)?`, returns `TRUE` for
|
||||||
|
yes (both `y` and `Y` are handled) and `FALSE` for everything else.
|
||||||
|
|
||||||
|
|
||||||
|
Procfile Functions
|
||||||
|
------------------
|
||||||
|
|
||||||
|
These functions can be used to simplify access to data in `/proc` and
|
||||||
|
`/sys` on a Linux system.
|
||||||
|
|
||||||
|
### String Functions
|
||||||
|
|
||||||
|
- `readsnf(line, len, fmt, ...)`
|
||||||
|
|
||||||
|
Read first line from a file composed from `fmt`, with optional args.
|
||||||
|
At most `len` bytes from the file are stored in `line`.
|
||||||
|
|
||||||
|
On success this function returns `line` with any trailing newlines
|
||||||
|
`chomp()`ed off. On error `NULL` is returned.
|
||||||
|
|
||||||
|
- `vreadsnf(line, len, fmt, ap)`
|
||||||
|
|
||||||
|
Similar to `readsnf()` but takes a `va_list` argument instead.
|
||||||
|
|
||||||
|
- `writesf(str, mode, fmt, ...)`
|
||||||
|
|
||||||
|
Write the string buffer `str`, with an additional newline, to a file
|
||||||
|
composed from `fmt`, with optional args. The file is opened with the
|
||||||
|
given `mode`, e.g. "w+", which allows for both replacing and appending
|
||||||
|
file content.
|
||||||
|
|
||||||
|
The function returns POSIX OK(0) on success or -1 on failure with the
|
||||||
|
`errno` variable set to a value from either `fopen()` or `fclose()`.
|
||||||
|
|
||||||
|
### Integer Functions
|
||||||
|
|
||||||
|
Read and write 32-bit and 64-bit signed values from/to files.
|
||||||
|
|
||||||
|
- `vreadllf(value, fmt, ap)` and `readllf(value, fmt, ...)`
|
||||||
|
|
||||||
|
Only the first line is read. If the line has newline that is stripped
|
||||||
|
before calling `strtoll()` on the line. The arguments to the latter
|
||||||
|
function is such that it can convert also from a hexadecimal value.
|
||||||
|
|
||||||
|
This function may fail and return -1 on opening the file, reading a
|
||||||
|
line, or if the `strtoll()` function fails. All of which set the
|
||||||
|
`errno` variable. Otherwise this function return POSIX OK(0).
|
||||||
|
|
||||||
|
- `readdf(value, fmt, ...)`
|
||||||
|
|
||||||
|
Read a signed 32-bit value from a file composed from `fmt`, with
|
||||||
|
optional args. This function use `vreadllf()` with an additional
|
||||||
|
range checking for `INT_MIN` and `INT_MAX`. Values outside that
|
||||||
|
cause this function to return -1 with `errno` set to `ERANGE`.
|
||||||
|
|
||||||
|
- `writedf(value, mode, fmt, ...)`
|
||||||
|
|
||||||
|
Write a signed 32-bit `value` to a file composed from `fmt`, with
|
||||||
|
optional args. The file is opened with the given `mode`, e.g. "w+",
|
||||||
|
which allows for both replacing and appending file content.
|
||||||
|
|
||||||
|
The function returns POSIX OK(0) on success or -1 on failure with the
|
||||||
|
`errno` variable set to a value from either `fopen()` or `fclose()`.
|
||||||
|
|
||||||
|
- `writellf(value, mode, fmt, ...)`
|
||||||
|
|
||||||
|
Write a signed 64-bit `value` to a file composed from `fmt`, with
|
||||||
|
optional args. The file is opened with the given `mode`, e.g. "w+",
|
||||||
|
which allows for both replacing and appending file content.
|
||||||
|
|
||||||
|
The function returns POSIX OK(0) on success or -1 on failure with the
|
||||||
|
`errno` variable set to a value from either `fopen()` or `fclose()`.
|
||||||
|
|
||||||
|
|
||||||
|
GNU Functions
|
||||||
|
-------------
|
||||||
|
|
||||||
|
The following are useful GNU functions, that do not exist on *BSD, and
|
||||||
|
some other platforms.
|
||||||
|
|
||||||
|
- `strdupa(str)`
|
||||||
|
|
||||||
|
http://man7.org/linux/man-pages/man3/strdupa.3.html
|
||||||
|
|
||||||
|
- `strndupa(str)`
|
||||||
|
|
||||||
|
http://man7.org/linux/man-pages/man3/strndupa.3.html
|
||||||
|
|
||||||
|
- `strnlen(str, lim)`
|
||||||
|
|
||||||
|
http://man7.org/linux/man-pages/man3/strnlen.3.html
|
||||||
|
|
||||||
|
|
||||||
|
OpenBSD/NetBSD/FreeBSD Functions
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
|
The following are popular functions and highly useful macros from the
|
||||||
|
*BSD world of UNIX that are sadly missing on Linux.
|
||||||
|
|
||||||
|
- `fparseln(fp, *len, *lineno, delim, flags)`
|
||||||
|
|
||||||
|
http://man.openbsd.org/OpenBSD-current/man3/fparseln.3
|
||||||
|
|
||||||
|
- `pidfile(basename)`
|
||||||
|
|
||||||
|
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/pidfile.3
|
||||||
|
|
||||||
|
**Note:** the version of `pidfile()` in -lite has been extended to
|
||||||
|
handle it being called multiple times, i.e. to not create multiple
|
||||||
|
`atexit()` handlers, and also to export a few internal paths:
|
||||||
|
|
||||||
|
- `__pidfile_path`: prefix path, default `_PATH_VARRUN`. Notice the
|
||||||
|
trailing slash requirement if you want to override it!
|
||||||
|
- `__pidfile_name`: full path to PID file , similar to `__progname`.
|
||||||
|
See previous section for details.
|
||||||
|
|
||||||
|
- `reallocarray(ptr, nmemb, size)`
|
||||||
|
|
||||||
|
http://man.openbsd.org/OpenBSD-current/man3/reallocarray.3
|
||||||
|
|
||||||
|
- `strlcpy(dst, src, len)`
|
||||||
|
|
||||||
|
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/strlcpy.3
|
||||||
|
|
||||||
|
- `strlcat(dst, src, len)`
|
||||||
|
|
||||||
|
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/strlcat.3
|
||||||
|
|
||||||
|
- `strtonum()`
|
||||||
|
|
||||||
|
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/strtonum.3
|
||||||
|
|
||||||
|
- `sys/queue.h` API
|
||||||
|
|
||||||
|
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/LIST_EMPTY.3
|
||||||
|
|
||||||
|
- `sys/tree.h` API
|
||||||
|
|
||||||
|
Niels Provos' famous splay and red-black tree implementation.
|
||||||
|
|
||||||
|
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/SPLAY_FOREACH.3
|
||||||
+2579
File diff suppressed because it is too large.
Load diff
@@ -71,13 +71,13 @@ disable your brain and follow the rules, one by one.
|
|||||||
have changed. The initial version is 1:0:0, we follow the rules above to
|
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,
|
the letter: increase revision, increase current and set revision to zero,
|
||||||
and finally increase age. This, rather confusingly, gives us 2:0:1 which
|
and finally increase age. This, rather confusingly, gives us 2:0:1 which
|
||||||
libtool then translates to `libconfuse.so.1.1.0`.
|
libtool then translates to `libite.so.1.1.0`.
|
||||||
|
|
||||||
**Example #2:** some existing functions are changed, they now return an
|
**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
|
`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
|
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
|
zero, set age to zero. This gives us 1:0:0, which is then translated to
|
||||||
`libconfuse.so.1.0.0`.
|
`libite.so.1.0.0`.
|
||||||
|
|
||||||
### Note
|
### Note
|
||||||
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
dist_doc_DATA = API.md
|
||||||
|
EXTRA_DIST = API.md Doxyfile.in
|
||||||
|
DISTCLEANFILES = libite.tag
|
||||||
|
|
||||||
|
if ENABLE_HTML
|
||||||
|
pkghtmldir = $(docdir)/html
|
||||||
|
pkghtml_DATA = html/*
|
||||||
|
|
||||||
|
#
|
||||||
|
# Doxygen rules from m4/ax_prog_doxygen.m4
|
||||||
|
#
|
||||||
|
@DX_RULES@
|
||||||
|
|
||||||
|
$(pkghtml_DATA): doxygen-doc
|
||||||
|
|
||||||
|
all-local: doc
|
||||||
|
|
||||||
|
clean-local:
|
||||||
|
-rm -rf html libite.tag
|
||||||
|
|
||||||
|
doc: doxygen-doc
|
||||||
|
endif
|
||||||
File renamed without changes.
@@ -0,0 +1,585 @@
|
|||||||
|
# ===========================================================================
|
||||||
|
# http://www.gnu.org/software/autoconf-archive/ax_prog_doxygen.html
|
||||||
|
# ===========================================================================
|
||||||
|
#
|
||||||
|
# SYNOPSIS
|
||||||
|
#
|
||||||
|
# DX_INIT_DOXYGEN(PROJECT-NAME, [DOXYFILE-PATH], [OUTPUT-DIR], ...)
|
||||||
|
# DX_DOXYGEN_FEATURE(ON|OFF)
|
||||||
|
# DX_DOT_FEATURE(ON|OFF)
|
||||||
|
# DX_HTML_FEATURE(ON|OFF)
|
||||||
|
# DX_CHM_FEATURE(ON|OFF)
|
||||||
|
# DX_CHI_FEATURE(ON|OFF)
|
||||||
|
# DX_MAN_FEATURE(ON|OFF)
|
||||||
|
# DX_RTF_FEATURE(ON|OFF)
|
||||||
|
# DX_XML_FEATURE(ON|OFF)
|
||||||
|
# DX_PDF_FEATURE(ON|OFF)
|
||||||
|
# DX_PS_FEATURE(ON|OFF)
|
||||||
|
#
|
||||||
|
# DESCRIPTION
|
||||||
|
#
|
||||||
|
# The DX_*_FEATURE macros control the default setting for the given
|
||||||
|
# Doxygen feature. Supported features are 'DOXYGEN' itself, 'DOT' for
|
||||||
|
# generating graphics, 'HTML' for plain HTML, 'CHM' for compressed HTML
|
||||||
|
# help (for MS users), 'CHI' for generating a separate .chi file by the
|
||||||
|
# .chm file, and 'MAN', 'RTF', 'XML', 'PDF' and 'PS' for the appropriate
|
||||||
|
# output formats. The environment variable DOXYGEN_PAPER_SIZE may be
|
||||||
|
# specified to override the default 'a4wide' paper size.
|
||||||
|
#
|
||||||
|
# By default, HTML, PDF and PS documentation is generated as this seems to
|
||||||
|
# be the most popular and portable combination. MAN pages created by
|
||||||
|
# Doxygen are usually problematic, though by picking an appropriate subset
|
||||||
|
# and doing some massaging they might be better than nothing. CHM and RTF
|
||||||
|
# are specific for MS (note that you can't generate both HTML and CHM at
|
||||||
|
# the same time). The XML is rather useless unless you apply specialized
|
||||||
|
# post-processing to it.
|
||||||
|
#
|
||||||
|
# The macros mainly control the default state of the feature. The use can
|
||||||
|
# override the default by specifying --enable or --disable. The macros
|
||||||
|
# ensure that contradictory flags are not given (e.g.,
|
||||||
|
# --enable-doxygen-html and --enable-doxygen-chm,
|
||||||
|
# --enable-doxygen-anything with --disable-doxygen, etc.) Finally, each
|
||||||
|
# feature will be automatically disabled (with a warning) if the required
|
||||||
|
# programs are missing.
|
||||||
|
#
|
||||||
|
# Once all the feature defaults have been specified, call DX_INIT_DOXYGEN
|
||||||
|
# with the following parameters: a one-word name for the project for use
|
||||||
|
# as a filename base etc., an optional configuration file name (the
|
||||||
|
# default is '$(srcdir)/Doxyfile', the same as Doxygen's default), and an
|
||||||
|
# optional output directory name (the default is 'doxygen-doc'). To run
|
||||||
|
# doxygen multiple times for different configuration files and output
|
||||||
|
# directories provide more parameters: the second, forth, sixth, etc
|
||||||
|
# parameter are configuration file names and the third, fifth, seventh,
|
||||||
|
# etc parameter are output directories. No checking is done to catch
|
||||||
|
# duplicates.
|
||||||
|
#
|
||||||
|
# Automake Support
|
||||||
|
#
|
||||||
|
# The DX_RULES substitution can be used to add all needed rules to the
|
||||||
|
# Makefile. Note that this is a substitution without being a variable:
|
||||||
|
# only the @DX_RULES@ syntax will work.
|
||||||
|
#
|
||||||
|
# The provided targets are:
|
||||||
|
#
|
||||||
|
# doxygen-doc: Generate all doxygen documentation.
|
||||||
|
#
|
||||||
|
# doxygen-run: Run doxygen, which will generate some of the
|
||||||
|
# documentation (HTML, CHM, CHI, MAN, RTF, XML)
|
||||||
|
# but will not do the post processing required
|
||||||
|
# for the rest of it (PS, PDF).
|
||||||
|
#
|
||||||
|
# doxygen-ps: Generate doxygen PostScript documentation.
|
||||||
|
#
|
||||||
|
# doxygen-pdf: Generate doxygen PDF documentation.
|
||||||
|
#
|
||||||
|
# Note that by default these are not integrated into the automake targets.
|
||||||
|
# If doxygen is used to generate man pages, you can achieve this
|
||||||
|
# integration by setting man3_MANS to the list of man pages generated and
|
||||||
|
# then adding the dependency:
|
||||||
|
#
|
||||||
|
# $(man3_MANS): doxygen-doc
|
||||||
|
#
|
||||||
|
# This will cause make to run doxygen and generate all the documentation.
|
||||||
|
#
|
||||||
|
# The following variable is intended for use in Makefile.am:
|
||||||
|
#
|
||||||
|
# DX_CLEANFILES = everything to clean.
|
||||||
|
#
|
||||||
|
# Then add this variable to MOSTLYCLEANFILES.
|
||||||
|
#
|
||||||
|
# LICENSE
|
||||||
|
#
|
||||||
|
# Copyright (c) 2009 Oren Ben-Kiki <oren@ben-kiki.org>
|
||||||
|
# Copyright (c) 2015 Olaf Mandel <olaf@mandel.name>
|
||||||
|
#
|
||||||
|
# Copying and distribution of this file, with or without modification, are
|
||||||
|
# permitted in any medium without royalty provided the copyright notice
|
||||||
|
# and this notice are preserved. This file is offered as-is, without any
|
||||||
|
# warranty.
|
||||||
|
|
||||||
|
#serial 20
|
||||||
|
|
||||||
|
## ----------##
|
||||||
|
## Defaults. ##
|
||||||
|
## ----------##
|
||||||
|
|
||||||
|
DX_ENV=""
|
||||||
|
AC_DEFUN([DX_FEATURE_doc], ON)
|
||||||
|
AC_DEFUN([DX_FEATURE_dot], OFF)
|
||||||
|
AC_DEFUN([DX_FEATURE_man], OFF)
|
||||||
|
AC_DEFUN([DX_FEATURE_html], ON)
|
||||||
|
AC_DEFUN([DX_FEATURE_chm], OFF)
|
||||||
|
AC_DEFUN([DX_FEATURE_chi], OFF)
|
||||||
|
AC_DEFUN([DX_FEATURE_rtf], OFF)
|
||||||
|
AC_DEFUN([DX_FEATURE_xml], OFF)
|
||||||
|
AC_DEFUN([DX_FEATURE_pdf], ON)
|
||||||
|
AC_DEFUN([DX_FEATURE_ps], ON)
|
||||||
|
|
||||||
|
## --------------- ##
|
||||||
|
## Private macros. ##
|
||||||
|
## --------------- ##
|
||||||
|
|
||||||
|
# DX_ENV_APPEND(VARIABLE, VALUE)
|
||||||
|
# ------------------------------
|
||||||
|
# Append VARIABLE="VALUE" to DX_ENV for invoking doxygen and add it
|
||||||
|
# as a substitution (but not a Makefile variable). The substitution
|
||||||
|
# is skipped if the variable name is VERSION.
|
||||||
|
AC_DEFUN([DX_ENV_APPEND],
|
||||||
|
[AC_SUBST([DX_ENV], ["$DX_ENV $1='$2'"])dnl
|
||||||
|
m4_if([$1], [VERSION], [], [AC_SUBST([$1], [$2])dnl
|
||||||
|
AM_SUBST_NOTMAKE([$1])])dnl
|
||||||
|
])
|
||||||
|
|
||||||
|
# DX_DIRNAME_EXPR
|
||||||
|
# ---------------
|
||||||
|
# Expand into a shell expression prints the directory part of a path.
|
||||||
|
AC_DEFUN([DX_DIRNAME_EXPR],
|
||||||
|
[[expr ".$1" : '\(\.\)[^/]*$' \| "x$1" : 'x\(.*\)/[^/]*$']])
|
||||||
|
|
||||||
|
# DX_IF_FEATURE(FEATURE, IF-ON, IF-OFF)
|
||||||
|
# -------------------------------------
|
||||||
|
# Expands according to the M4 (static) status of the feature.
|
||||||
|
AC_DEFUN([DX_IF_FEATURE], [ifelse(DX_FEATURE_$1, ON, [$2], [$3])])
|
||||||
|
|
||||||
|
# DX_REQUIRE_PROG(VARIABLE, PROGRAM)
|
||||||
|
# ----------------------------------
|
||||||
|
# Require the specified program to be found for the DX_CURRENT_FEATURE to work.
|
||||||
|
AC_DEFUN([DX_REQUIRE_PROG], [
|
||||||
|
AC_PATH_TOOL([$1], [$2])
|
||||||
|
if test "$DX_FLAG_[]DX_CURRENT_FEATURE$$1" = 1; then
|
||||||
|
AC_MSG_WARN([$2 not found - will not DX_CURRENT_DESCRIPTION])
|
||||||
|
AC_SUBST(DX_FLAG_[]DX_CURRENT_FEATURE, 0)
|
||||||
|
fi
|
||||||
|
])
|
||||||
|
|
||||||
|
# DX_TEST_FEATURE(FEATURE)
|
||||||
|
# ------------------------
|
||||||
|
# Expand to a shell expression testing whether the feature is active.
|
||||||
|
AC_DEFUN([DX_TEST_FEATURE], [test "$DX_FLAG_$1" = 1])
|
||||||
|
|
||||||
|
# DX_CHECK_DEPEND(REQUIRED_FEATURE, REQUIRED_STATE)
|
||||||
|
# -------------------------------------------------
|
||||||
|
# Verify that a required features has the right state before trying to turn on
|
||||||
|
# the DX_CURRENT_FEATURE.
|
||||||
|
AC_DEFUN([DX_CHECK_DEPEND], [
|
||||||
|
test "$DX_FLAG_$1" = "$2" \
|
||||||
|
|| AC_MSG_ERROR([doxygen-DX_CURRENT_FEATURE ifelse([$2], 1,
|
||||||
|
requires, contradicts) doxygen-DX_CURRENT_FEATURE])
|
||||||
|
])
|
||||||
|
|
||||||
|
# DX_CLEAR_DEPEND(FEATURE, REQUIRED_FEATURE, REQUIRED_STATE)
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
# Turn off the DX_CURRENT_FEATURE if the required feature is off.
|
||||||
|
AC_DEFUN([DX_CLEAR_DEPEND], [
|
||||||
|
test "$DX_FLAG_$1" = "$2" || AC_SUBST(DX_FLAG_[]DX_CURRENT_FEATURE, 0)
|
||||||
|
])
|
||||||
|
|
||||||
|
# DX_FEATURE_ARG(FEATURE, DESCRIPTION,
|
||||||
|
# CHECK_DEPEND, CLEAR_DEPEND,
|
||||||
|
# REQUIRE, DO-IF-ON, DO-IF-OFF)
|
||||||
|
# --------------------------------------------
|
||||||
|
# Parse the command-line option controlling a feature. CHECK_DEPEND is called
|
||||||
|
# if the user explicitly turns the feature on (and invokes DX_CHECK_DEPEND),
|
||||||
|
# otherwise CLEAR_DEPEND is called to turn off the default state if a required
|
||||||
|
# feature is disabled (using DX_CLEAR_DEPEND). REQUIRE performs additional
|
||||||
|
# requirement tests (DX_REQUIRE_PROG). Finally, an automake flag is set and
|
||||||
|
# DO-IF-ON or DO-IF-OFF are called according to the final state of the feature.
|
||||||
|
AC_DEFUN([DX_ARG_ABLE], [
|
||||||
|
AC_DEFUN([DX_CURRENT_FEATURE], [$1])
|
||||||
|
AC_DEFUN([DX_CURRENT_DESCRIPTION], [$2])
|
||||||
|
AC_ARG_ENABLE(doxygen-$1,
|
||||||
|
[AS_HELP_STRING(DX_IF_FEATURE([$1], [--disable-doxygen-$1],
|
||||||
|
[--enable-doxygen-$1]),
|
||||||
|
DX_IF_FEATURE([$1], [don't $2], [$2]))],
|
||||||
|
[
|
||||||
|
case "$enableval" in
|
||||||
|
#(
|
||||||
|
y|Y|yes|Yes|YES)
|
||||||
|
AC_SUBST([DX_FLAG_$1], 1)
|
||||||
|
$3
|
||||||
|
;; #(
|
||||||
|
n|N|no|No|NO)
|
||||||
|
AC_SUBST([DX_FLAG_$1], 0)
|
||||||
|
;; #(
|
||||||
|
*)
|
||||||
|
AC_MSG_ERROR([invalid value '$enableval' given to doxygen-$1])
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
], [
|
||||||
|
AC_SUBST([DX_FLAG_$1], [DX_IF_FEATURE([$1], 1, 0)])
|
||||||
|
$4
|
||||||
|
])
|
||||||
|
if DX_TEST_FEATURE([$1]); then
|
||||||
|
$5
|
||||||
|
:
|
||||||
|
fi
|
||||||
|
if DX_TEST_FEATURE([$1]); then
|
||||||
|
$6
|
||||||
|
:
|
||||||
|
else
|
||||||
|
$7
|
||||||
|
:
|
||||||
|
fi
|
||||||
|
])
|
||||||
|
|
||||||
|
## -------------- ##
|
||||||
|
## Public macros. ##
|
||||||
|
## -------------- ##
|
||||||
|
|
||||||
|
# DX_XXX_FEATURE(DEFAULT_STATE)
|
||||||
|
# -----------------------------
|
||||||
|
AC_DEFUN([DX_DOXYGEN_FEATURE], [AC_DEFUN([DX_FEATURE_doc], [$1])])
|
||||||
|
AC_DEFUN([DX_DOT_FEATURE], [AC_DEFUN([DX_FEATURE_dot], [$1])])
|
||||||
|
AC_DEFUN([DX_MAN_FEATURE], [AC_DEFUN([DX_FEATURE_man], [$1])])
|
||||||
|
AC_DEFUN([DX_HTML_FEATURE], [AC_DEFUN([DX_FEATURE_html], [$1])])
|
||||||
|
AC_DEFUN([DX_CHM_FEATURE], [AC_DEFUN([DX_FEATURE_chm], [$1])])
|
||||||
|
AC_DEFUN([DX_CHI_FEATURE], [AC_DEFUN([DX_FEATURE_chi], [$1])])
|
||||||
|
AC_DEFUN([DX_RTF_FEATURE], [AC_DEFUN([DX_FEATURE_rtf], [$1])])
|
||||||
|
AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])])
|
||||||
|
AC_DEFUN([DX_XML_FEATURE], [AC_DEFUN([DX_FEATURE_xml], [$1])])
|
||||||
|
AC_DEFUN([DX_PDF_FEATURE], [AC_DEFUN([DX_FEATURE_pdf], [$1])])
|
||||||
|
AC_DEFUN([DX_PS_FEATURE], [AC_DEFUN([DX_FEATURE_ps], [$1])])
|
||||||
|
|
||||||
|
# DX_INIT_DOXYGEN(PROJECT, [CONFIG-FILE], [OUTPUT-DOC-DIR], ...)
|
||||||
|
# --------------------------------------------------------------
|
||||||
|
# PROJECT also serves as the base name for the documentation files.
|
||||||
|
# The default CONFIG-FILE is "$(srcdir)/Doxyfile" and OUTPUT-DOC-DIR is
|
||||||
|
# "doxygen-doc".
|
||||||
|
# More arguments are interpreted as interleaved CONFIG-FILE and
|
||||||
|
# OUTPUT-DOC-DIR values.
|
||||||
|
AC_DEFUN([DX_INIT_DOXYGEN], [
|
||||||
|
|
||||||
|
# Files:
|
||||||
|
AC_SUBST([DX_PROJECT], [$1])
|
||||||
|
AC_SUBST([DX_CONFIG], ['ifelse([$2], [], [$(srcdir)/Doxyfile], [$2])'])
|
||||||
|
AC_SUBST([DX_DOCDIR], ['ifelse([$3], [], [doxygen-doc], [$3])'])
|
||||||
|
m4_if(m4_eval(3 < m4_count($@)), 1, [m4_for([DX_i], 4, m4_count($@), 2,
|
||||||
|
[AC_SUBST([DX_CONFIG]m4_eval(DX_i[/2]),
|
||||||
|
'm4_default_nblank_quoted(m4_argn(DX_i, $@),
|
||||||
|
[$(srcdir)/Doxyfile])')])])dnl
|
||||||
|
m4_if(m4_eval(3 < m4_count($@)), 1, [m4_for([DX_i], 5, m4_count($@,), 2,
|
||||||
|
[AC_SUBST([DX_DOCDIR]m4_eval([(]DX_i[-1)/2]),
|
||||||
|
'm4_default_nblank_quoted(m4_argn(DX_i, $@),
|
||||||
|
[doxygen-doc])')])])dnl
|
||||||
|
m4_define([DX_loop], m4_dquote(m4_if(m4_eval(3 < m4_count($@)), 1,
|
||||||
|
[m4_for([DX_i], 4, m4_count($@), 2, [, m4_eval(DX_i[/2])])],
|
||||||
|
[])))dnl
|
||||||
|
|
||||||
|
# Environment variables used inside doxygen.cfg:
|
||||||
|
DX_ENV_APPEND(SRCDIR, $srcdir)
|
||||||
|
DX_ENV_APPEND(PROJECT, $DX_PROJECT)
|
||||||
|
DX_ENV_APPEND(VERSION, $PACKAGE_VERSION)
|
||||||
|
|
||||||
|
# Doxygen itself:
|
||||||
|
DX_ARG_ABLE(doc, [generate any doxygen documentation],
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
[DX_REQUIRE_PROG([DX_DOXYGEN], doxygen)
|
||||||
|
DX_REQUIRE_PROG([DX_PERL], perl)],
|
||||||
|
[DX_ENV_APPEND(PERL_PATH, $DX_PERL)])
|
||||||
|
|
||||||
|
# Dot for graphics:
|
||||||
|
DX_ARG_ABLE(dot, [generate graphics for doxygen documentation],
|
||||||
|
[DX_CHECK_DEPEND(doc, 1)],
|
||||||
|
[DX_CLEAR_DEPEND(doc, 1)],
|
||||||
|
[DX_REQUIRE_PROG([DX_DOT], dot)],
|
||||||
|
[DX_ENV_APPEND(HAVE_DOT, YES)
|
||||||
|
DX_ENV_APPEND(DOT_PATH, [`DX_DIRNAME_EXPR($DX_DOT)`])],
|
||||||
|
[DX_ENV_APPEND(HAVE_DOT, NO)])
|
||||||
|
|
||||||
|
# Man pages generation:
|
||||||
|
DX_ARG_ABLE(man, [generate doxygen manual pages],
|
||||||
|
[DX_CHECK_DEPEND(doc, 1)],
|
||||||
|
[DX_CLEAR_DEPEND(doc, 1)],
|
||||||
|
[],
|
||||||
|
[DX_ENV_APPEND(GENERATE_MAN, YES)],
|
||||||
|
[DX_ENV_APPEND(GENERATE_MAN, NO)])
|
||||||
|
|
||||||
|
# RTF file generation:
|
||||||
|
DX_ARG_ABLE(rtf, [generate doxygen RTF documentation],
|
||||||
|
[DX_CHECK_DEPEND(doc, 1)],
|
||||||
|
[DX_CLEAR_DEPEND(doc, 1)],
|
||||||
|
[],
|
||||||
|
[DX_ENV_APPEND(GENERATE_RTF, YES)],
|
||||||
|
[DX_ENV_APPEND(GENERATE_RTF, NO)])
|
||||||
|
|
||||||
|
# XML file generation:
|
||||||
|
DX_ARG_ABLE(xml, [generate doxygen XML documentation],
|
||||||
|
[DX_CHECK_DEPEND(doc, 1)],
|
||||||
|
[DX_CLEAR_DEPEND(doc, 1)],
|
||||||
|
[],
|
||||||
|
[DX_ENV_APPEND(GENERATE_XML, YES)],
|
||||||
|
[DX_ENV_APPEND(GENERATE_XML, NO)])
|
||||||
|
|
||||||
|
# (Compressed) HTML help generation:
|
||||||
|
DX_ARG_ABLE(chm, [generate doxygen compressed HTML help documentation],
|
||||||
|
[DX_CHECK_DEPEND(doc, 1)],
|
||||||
|
[DX_CLEAR_DEPEND(doc, 1)],
|
||||||
|
[DX_REQUIRE_PROG([DX_HHC], hhc)],
|
||||||
|
[DX_ENV_APPEND(HHC_PATH, $DX_HHC)
|
||||||
|
DX_ENV_APPEND(GENERATE_HTML, YES)
|
||||||
|
DX_ENV_APPEND(GENERATE_HTMLHELP, YES)],
|
||||||
|
[DX_ENV_APPEND(GENERATE_HTMLHELP, NO)])
|
||||||
|
|
||||||
|
# Separate CHI file generation.
|
||||||
|
DX_ARG_ABLE(chi, [generate doxygen separate compressed HTML help index file],
|
||||||
|
[DX_CHECK_DEPEND(chm, 1)],
|
||||||
|
[DX_CLEAR_DEPEND(chm, 1)],
|
||||||
|
[],
|
||||||
|
[DX_ENV_APPEND(GENERATE_CHI, YES)],
|
||||||
|
[DX_ENV_APPEND(GENERATE_CHI, NO)])
|
||||||
|
|
||||||
|
# Plain HTML pages generation:
|
||||||
|
DX_ARG_ABLE(html, [generate doxygen plain HTML documentation],
|
||||||
|
[DX_CHECK_DEPEND(doc, 1) DX_CHECK_DEPEND(chm, 0)],
|
||||||
|
[DX_CLEAR_DEPEND(doc, 1) DX_CLEAR_DEPEND(chm, 0)],
|
||||||
|
[],
|
||||||
|
[DX_ENV_APPEND(GENERATE_HTML, YES)],
|
||||||
|
[DX_TEST_FEATURE(chm) || DX_ENV_APPEND(GENERATE_HTML, NO)])
|
||||||
|
|
||||||
|
# PostScript file generation:
|
||||||
|
DX_ARG_ABLE(ps, [generate doxygen PostScript documentation],
|
||||||
|
[DX_CHECK_DEPEND(doc, 1)],
|
||||||
|
[DX_CLEAR_DEPEND(doc, 1)],
|
||||||
|
[DX_REQUIRE_PROG([DX_LATEX], latex)
|
||||||
|
DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex)
|
||||||
|
DX_REQUIRE_PROG([DX_DVIPS], dvips)
|
||||||
|
DX_REQUIRE_PROG([DX_EGREP], egrep)])
|
||||||
|
|
||||||
|
# PDF file generation:
|
||||||
|
DX_ARG_ABLE(pdf, [generate doxygen PDF documentation],
|
||||||
|
[DX_CHECK_DEPEND(doc, 1)],
|
||||||
|
[DX_CLEAR_DEPEND(doc, 1)],
|
||||||
|
[DX_REQUIRE_PROG([DX_PDFLATEX], pdflatex)
|
||||||
|
DX_REQUIRE_PROG([DX_MAKEINDEX], makeindex)
|
||||||
|
DX_REQUIRE_PROG([DX_EGREP], egrep)])
|
||||||
|
|
||||||
|
# LaTeX generation for PS and/or PDF:
|
||||||
|
if DX_TEST_FEATURE(ps) || DX_TEST_FEATURE(pdf); then
|
||||||
|
DX_ENV_APPEND(GENERATE_LATEX, YES)
|
||||||
|
else
|
||||||
|
DX_ENV_APPEND(GENERATE_LATEX, NO)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Paper size for PS and/or PDF:
|
||||||
|
AC_ARG_VAR(DOXYGEN_PAPER_SIZE,
|
||||||
|
[a4wide (default), a4, letter, legal or executive])
|
||||||
|
case "$DOXYGEN_PAPER_SIZE" in
|
||||||
|
#(
|
||||||
|
"")
|
||||||
|
AC_SUBST(DOXYGEN_PAPER_SIZE, "")
|
||||||
|
;; #(
|
||||||
|
a4wide|a4|letter|legal|executive)
|
||||||
|
DX_ENV_APPEND(PAPER_SIZE, $DOXYGEN_PAPER_SIZE)
|
||||||
|
;; #(
|
||||||
|
*)
|
||||||
|
AC_MSG_ERROR([unknown DOXYGEN_PAPER_SIZE='$DOXYGEN_PAPER_SIZE'])
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Rules:
|
||||||
|
AS_IF([[test $DX_FLAG_html -eq 1]],
|
||||||
|
[[DX_SNIPPET_html="## ------------------------------- ##
|
||||||
|
## Rules specific for HTML output. ##
|
||||||
|
## ------------------------------- ##
|
||||||
|
|
||||||
|
DX_CLEAN_HTML = \$(DX_DOCDIR)/html]dnl
|
||||||
|
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
|
||||||
|
\$(DX_DOCDIR]DX_i[)/html]])[
|
||||||
|
|
||||||
|
"]],
|
||||||
|
[[DX_SNIPPET_html=""]])
|
||||||
|
AS_IF([[test $DX_FLAG_chi -eq 1]],
|
||||||
|
[[DX_SNIPPET_chi="
|
||||||
|
DX_CLEAN_CHI = \$(DX_DOCDIR)/\$(PACKAGE).chi]dnl
|
||||||
|
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
|
||||||
|
\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).chi]])["]],
|
||||||
|
[[DX_SNIPPET_chi=""]])
|
||||||
|
AS_IF([[test $DX_FLAG_chm -eq 1]],
|
||||||
|
[[DX_SNIPPET_chm="## ------------------------------ ##
|
||||||
|
## Rules specific for CHM output. ##
|
||||||
|
## ------------------------------ ##
|
||||||
|
|
||||||
|
DX_CLEAN_CHM = \$(DX_DOCDIR)/chm]dnl
|
||||||
|
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
|
||||||
|
\$(DX_DOCDIR]DX_i[)/chm]])[\
|
||||||
|
${DX_SNIPPET_chi}
|
||||||
|
|
||||||
|
"]],
|
||||||
|
[[DX_SNIPPET_chm=""]])
|
||||||
|
AS_IF([[test $DX_FLAG_man -eq 1]],
|
||||||
|
[[DX_SNIPPET_man="## ------------------------------ ##
|
||||||
|
## Rules specific for MAN output. ##
|
||||||
|
## ------------------------------ ##
|
||||||
|
|
||||||
|
DX_CLEAN_MAN = \$(DX_DOCDIR)/man]dnl
|
||||||
|
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
|
||||||
|
\$(DX_DOCDIR]DX_i[)/man]])[
|
||||||
|
|
||||||
|
"]],
|
||||||
|
[[DX_SNIPPET_man=""]])
|
||||||
|
AS_IF([[test $DX_FLAG_rtf -eq 1]],
|
||||||
|
[[DX_SNIPPET_rtf="## ------------------------------ ##
|
||||||
|
## Rules specific for RTF output. ##
|
||||||
|
## ------------------------------ ##
|
||||||
|
|
||||||
|
DX_CLEAN_RTF = \$(DX_DOCDIR)/rtf]dnl
|
||||||
|
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
|
||||||
|
\$(DX_DOCDIR]DX_i[)/rtf]])[
|
||||||
|
|
||||||
|
"]],
|
||||||
|
[[DX_SNIPPET_rtf=""]])
|
||||||
|
AS_IF([[test $DX_FLAG_xml -eq 1]],
|
||||||
|
[[DX_SNIPPET_xml="## ------------------------------ ##
|
||||||
|
## Rules specific for XML output. ##
|
||||||
|
## ------------------------------ ##
|
||||||
|
|
||||||
|
DX_CLEAN_XML = \$(DX_DOCDIR)/xml]dnl
|
||||||
|
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
|
||||||
|
\$(DX_DOCDIR]DX_i[)/xml]])[
|
||||||
|
|
||||||
|
"]],
|
||||||
|
[[DX_SNIPPET_xml=""]])
|
||||||
|
AS_IF([[test $DX_FLAG_ps -eq 1]],
|
||||||
|
[[DX_SNIPPET_ps="## ----------------------------- ##
|
||||||
|
## Rules specific for PS output. ##
|
||||||
|
## ----------------------------- ##
|
||||||
|
|
||||||
|
DX_CLEAN_PS = \$(DX_DOCDIR)/\$(PACKAGE).ps]dnl
|
||||||
|
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
|
||||||
|
\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).ps]])[
|
||||||
|
|
||||||
|
DX_PS_GOAL = doxygen-ps
|
||||||
|
|
||||||
|
doxygen-ps: \$(DX_CLEAN_PS)
|
||||||
|
|
||||||
|
]m4_foreach([DX_i], [DX_loop],
|
||||||
|
[[\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).ps: \$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag
|
||||||
|
\$(DX_V_LATEX)cd \$(DX_DOCDIR]DX_i[)/latex; \\
|
||||||
|
rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \\
|
||||||
|
\$(DX_LATEX) refman.tex; \\
|
||||||
|
\$(DX_MAKEINDEX) refman.idx; \\
|
||||||
|
\$(DX_LATEX) refman.tex; \\
|
||||||
|
countdown=5; \\
|
||||||
|
while \$(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \\
|
||||||
|
refman.log > /dev/null 2>&1 \\
|
||||||
|
&& test \$\$countdown -gt 0; do \\
|
||||||
|
\$(DX_LATEX) refman.tex; \\
|
||||||
|
countdown=\`expr \$\$countdown - 1\`; \\
|
||||||
|
done; \\
|
||||||
|
\$(DX_DVIPS) -o ../\$(PACKAGE).ps refman.dvi
|
||||||
|
|
||||||
|
]])["]],
|
||||||
|
[[DX_SNIPPET_ps=""]])
|
||||||
|
AS_IF([[test $DX_FLAG_pdf -eq 1]],
|
||||||
|
[[DX_SNIPPET_pdf="## ------------------------------ ##
|
||||||
|
## Rules specific for PDF output. ##
|
||||||
|
## ------------------------------ ##
|
||||||
|
|
||||||
|
DX_CLEAN_PDF = \$(DX_DOCDIR)/\$(PACKAGE).pdf]dnl
|
||||||
|
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
|
||||||
|
\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).pdf]])[
|
||||||
|
|
||||||
|
DX_PDF_GOAL = doxygen-pdf
|
||||||
|
|
||||||
|
doxygen-pdf: \$(DX_CLEAN_PDF)
|
||||||
|
|
||||||
|
]m4_foreach([DX_i], [DX_loop],
|
||||||
|
[[\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).pdf: \$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag
|
||||||
|
\$(DX_V_LATEX)cd \$(DX_DOCDIR]DX_i[)/latex; \\
|
||||||
|
rm -f *.aux *.toc *.idx *.ind *.ilg *.log *.out; \\
|
||||||
|
\$(DX_PDFLATEX) refman.tex; \\
|
||||||
|
\$(DX_MAKEINDEX) refman.idx; \\
|
||||||
|
\$(DX_PDFLATEX) refman.tex; \\
|
||||||
|
countdown=5; \\
|
||||||
|
while \$(DX_EGREP) 'Rerun (LaTeX|to get cross-references right)' \\
|
||||||
|
refman.log > /dev/null 2>&1 \\
|
||||||
|
&& test \$\$countdown -gt 0; do \\
|
||||||
|
\$(DX_PDFLATEX) refman.tex; \\
|
||||||
|
countdown=\`expr \$\$countdown - 1\`; \\
|
||||||
|
done; \\
|
||||||
|
mv refman.pdf ../\$(PACKAGE).pdf
|
||||||
|
|
||||||
|
]])["]],
|
||||||
|
[[DX_SNIPPET_pdf=""]])
|
||||||
|
AS_IF([[test $DX_FLAG_ps -eq 1 -o $DX_FLAG_pdf -eq 1]],
|
||||||
|
[[DX_SNIPPET_latex="## ------------------------------------------------- ##
|
||||||
|
## Rules specific for LaTeX (shared for PS and PDF). ##
|
||||||
|
## ------------------------------------------------- ##
|
||||||
|
|
||||||
|
DX_V_LATEX = \$(_DX_v_LATEX_\$(V))
|
||||||
|
_DX_v_LATEX_ = \$(_DX_v_LATEX_\$(AM_DEFAULT_VERBOSITY))
|
||||||
|
_DX_v_LATEX_0 = @echo \" LATEX \" \$][@;
|
||||||
|
|
||||||
|
DX_CLEAN_LATEX = \$(DX_DOCDIR)/latex]dnl
|
||||||
|
m4_foreach([DX_i], [m4_shift(DX_loop)], [[\\
|
||||||
|
\$(DX_DOCDIR]DX_i[)/latex]])[
|
||||||
|
|
||||||
|
"]],
|
||||||
|
[[DX_SNIPPET_latex=""]])
|
||||||
|
|
||||||
|
AS_IF([[test $DX_FLAG_doc -eq 1]],
|
||||||
|
[[DX_SNIPPET_doc="## --------------------------------- ##
|
||||||
|
## Format-independent Doxygen rules. ##
|
||||||
|
## --------------------------------- ##
|
||||||
|
|
||||||
|
${DX_SNIPPET_html}\
|
||||||
|
${DX_SNIPPET_chm}\
|
||||||
|
${DX_SNIPPET_man}\
|
||||||
|
${DX_SNIPPET_rtf}\
|
||||||
|
${DX_SNIPPET_xml}\
|
||||||
|
${DX_SNIPPET_ps}\
|
||||||
|
${DX_SNIPPET_pdf}\
|
||||||
|
${DX_SNIPPET_latex}\
|
||||||
|
DX_V_DXGEN = \$(_DX_v_DXGEN_\$(V))
|
||||||
|
_DX_v_DXGEN_ = \$(_DX_v_DXGEN_\$(AM_DEFAULT_VERBOSITY))
|
||||||
|
_DX_v_DXGEN_0 = @echo \" DXGEN \" \$<;
|
||||||
|
|
||||||
|
.PHONY: doxygen-run doxygen-doc \$(DX_PS_GOAL) \$(DX_PDF_GOAL)
|
||||||
|
|
||||||
|
.INTERMEDIATE: doxygen-run \$(DX_PS_GOAL) \$(DX_PDF_GOAL)
|
||||||
|
|
||||||
|
doxygen-run:]m4_foreach([DX_i], [DX_loop],
|
||||||
|
[[ \$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag]])[
|
||||||
|
|
||||||
|
doxygen-doc: doxygen-run \$(DX_PS_GOAL) \$(DX_PDF_GOAL)
|
||||||
|
|
||||||
|
]m4_foreach([DX_i], [DX_loop],
|
||||||
|
[[\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag: \$(DX_CONFIG]DX_i[) \$(pkginclude_HEADERS)
|
||||||
|
\$(DX_V_DXGEN)\$(DX_ENV) DOCDIR=\$(DX_DOCDIR]DX_i[) \$(DX_DOXYGEN) \$(DX_CONFIG]DX_i[)
|
||||||
|
\$(A""M_V_at)echo Timestamp >\$][@
|
||||||
|
|
||||||
|
]])dnl
|
||||||
|
[DX_CLEANFILES = \\]
|
||||||
|
m4_foreach([DX_i], [DX_loop],
|
||||||
|
[[ \$(DX_DOCDIR]DX_i[)/doxygen_sqlite3.db \\
|
||||||
|
\$(DX_DOCDIR]DX_i[)/\$(PACKAGE).tag \\
|
||||||
|
]])dnl
|
||||||
|
[ -r \\
|
||||||
|
\$(DX_CLEAN_HTML) \\
|
||||||
|
\$(DX_CLEAN_CHM) \\
|
||||||
|
\$(DX_CLEAN_CHI) \\
|
||||||
|
\$(DX_CLEAN_MAN) \\
|
||||||
|
\$(DX_CLEAN_RTF) \\
|
||||||
|
\$(DX_CLEAN_XML) \\
|
||||||
|
\$(DX_CLEAN_PS) \\
|
||||||
|
\$(DX_CLEAN_PDF) \\
|
||||||
|
\$(DX_CLEAN_LATEX)"]],
|
||||||
|
[[DX_SNIPPET_doc=""]])
|
||||||
|
AC_SUBST([DX_RULES],
|
||||||
|
["${DX_SNIPPET_doc}"])dnl
|
||||||
|
AM_SUBST_NOTMAKE([DX_RULES])
|
||||||
|
|
||||||
|
#For debugging:
|
||||||
|
#echo DX_FLAG_doc=$DX_FLAG_doc
|
||||||
|
#echo DX_FLAG_dot=$DX_FLAG_dot
|
||||||
|
#echo DX_FLAG_man=$DX_FLAG_man
|
||||||
|
#echo DX_FLAG_html=$DX_FLAG_html
|
||||||
|
#echo DX_FLAG_chm=$DX_FLAG_chm
|
||||||
|
#echo DX_FLAG_chi=$DX_FLAG_chi
|
||||||
|
#echo DX_FLAG_rtf=$DX_FLAG_rtf
|
||||||
|
#echo DX_FLAG_xml=$DX_FLAG_xml
|
||||||
|
#echo DX_FLAG_pdf=$DX_FLAG_pdf
|
||||||
|
#echo DX_FLAG_ps=$DX_FLAG_ps
|
||||||
|
#echo DX_ENV=$DX_ENV
|
||||||
|
])
|
||||||
+29
-10
@@ -2,25 +2,44 @@ lib_LTLIBRARIES = libite.la
|
|||||||
|
|
||||||
libite_la_CPPFLAGS = -D_GNU_SOURCE
|
libite_la_CPPFLAGS = -D_GNU_SOURCE
|
||||||
libite_la_CFLAGS = -W -Wall -Wextra
|
libite_la_CFLAGS = -W -Wall -Wextra
|
||||||
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 5:1:0
|
libite_la_LDFLAGS = $(AM_LDFLAGS) -version-info 9:0:4
|
||||||
libite_la_SOURCES = chomp.c copyfile.c \
|
libite_la_SOURCES = chomp.c copyfile.c \
|
||||||
conio.c conio.h \
|
conio.c conio.h dir.c \
|
||||||
dir.c \
|
erasef.c fopenf.c fremove.c \
|
||||||
fexist.c fisdir.c \
|
fexist.c fisdir.c \
|
||||||
fparseln.c fsendfile.c \
|
fparseln.c fsendfile.c \
|
||||||
ifconfig.c lfile.c \
|
ifconfig.c lfile.c \
|
||||||
makepath.c progress.c \
|
makepath.c procval.c progress.c \
|
||||||
pidfile.c pidfilefn.c \
|
pidfile.c pidfilefn.c popenf.c \
|
||||||
reallocarray.c rsync.c \
|
reallocarray.c rsync.c runbg.c \
|
||||||
strlcpy.c strlcat.c strtonum.c \
|
strlcpy.c strlcat.c strtonum.c \
|
||||||
strdupa.h strndupa.h strnlen.h \
|
strdupa.h strndupa.h strnlen.h \
|
||||||
strmatch.c telnet.c tempfile.c \
|
strmatch.c systemf.c strtrim.c \
|
||||||
yorn.c which.c \
|
telnet.c tempfile.c truncatef.c \
|
||||||
|
touchf.c yorn.c which.c \
|
||||||
lite.h strlite.h \
|
lite.h strlite.h \
|
||||||
queue.h tree.h
|
queue.h tree.h
|
||||||
|
|
||||||
|
|
||||||
## Distribute these header files in the <lite/...> name space
|
## Distribute these header files in the <libite/...> namespace
|
||||||
pkgincludedir = $(includedir)/lite
|
pkgincludedir = $(includedir)/libite
|
||||||
pkginclude_HEADERS = lite.h queue.h conio.h tree.h strlite.h strdupa.h \
|
pkginclude_HEADERS = lite.h queue.h conio.h tree.h strlite.h strdupa.h \
|
||||||
strndupa.h strnlen.h
|
strndupa.h strnlen.h
|
||||||
|
|
||||||
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
|
pkgconfig_DATA = libite.pc
|
||||||
|
|
||||||
|
## For compatibility with previous <lite/...> namespace
|
||||||
|
if COMPAT_SYMLINK
|
||||||
|
install-data-hook:
|
||||||
|
link=$(DESTDIR)$(includedir)/lite; \
|
||||||
|
if [ ! -f $$link ]; then \
|
||||||
|
$(LN_S) libite $$link; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
uninstall-hook:
|
||||||
|
link=$(shell readlink $(DESTDIR)$(includedir)/lite); \
|
||||||
|
if [ "$$link" = "libite" ]; then \
|
||||||
|
$(RM) $(DESTDIR)$(includedir)/lite; \
|
||||||
|
fi
|
||||||
|
endif
|
||||||
+12
-6
@@ -1,6 +1,6 @@
|
|||||||
/* Perl inspired chomp() implementation.
|
/* Perl inspired chomp() implementation.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2014-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,19 +15,25 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file chomp.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2014-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* chomp - Perl like chomp function, chop off last char(s) if newline.
|
* Perl like chomp function, chop off last char(s) if newline.
|
||||||
* @str: String to chomp
|
* @param str String to chomp
|
||||||
*
|
*
|
||||||
* This function is like Perl chomp, but it's set to chop of all
|
* This function is like Perl chomp, but it's set to chop of all
|
||||||
* trailing newlines. Useful in combination with fgets().
|
* trailing newlines. Useful in combination with fgets().
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns @a str, or @c NULL with @a errno set, if @a str is not a valid pointer.
|
||||||
* If @str is a valid pointer this function returns @str, otherwise
|
* @exception EINVAL if the input argument is not a valid pointer.
|
||||||
* @errno is set to %EINVAL and this function returns %NULL.
|
|
||||||
*/
|
*/
|
||||||
char *chomp(char *str)
|
char *chomp(char *str)
|
||||||
{
|
{
|
||||||
|
|||||||
+22
-1
@@ -1,6 +1,6 @@
|
|||||||
/* A conio.h like implementation for VTANSI displays.
|
/* A conio.h like implementation for VTANSI displays.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,11 +15,32 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file conio.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2009-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Probe terminal size
|
||||||
|
* @param row pointer to integer to store number of rows
|
||||||
|
* @param col pointer to integer to store number of columns
|
||||||
|
*
|
||||||
|
* This function checks if stdin and stdout isatty() and then sets the
|
||||||
|
* TTY in raw mode to silently ask the size using ANSI escape sequences.
|
||||||
|
* This is achieved by trying to go to corner 999,999 followed by
|
||||||
|
* querying the cursor position. Afterwards the TTY is returned to the
|
||||||
|
* state if was before, e.g. cooked. The number of rows and columns is
|
||||||
|
* returned in the input arguments to this function.
|
||||||
|
*
|
||||||
|
* If stdio is @a not a TTY, then a default 24x80 is returned.
|
||||||
|
*/
|
||||||
void initscr(int *row, int *col)
|
void initscr(int *row, int *col)
|
||||||
{
|
{
|
||||||
if (!row || !col)
|
if (!row || !col)
|
||||||
|
|||||||
+42
-16
@@ -1,6 +1,6 @@
|
|||||||
/* A conio.h like implementation for VTANSI displays.
|
/* A conio.h like implementation for VTANSI displays.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,17 +15,26 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file conio.h
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2009-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*
|
||||||
|
* Helper macros and functions for interacting with TTY terminals.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONIO_H_
|
#ifndef LIBITE_CONIO_H_
|
||||||
#define CONIO_H_
|
#define LIBITE_CONIO_H_
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/* Attributes */
|
/** Attributes */
|
||||||
#define RESETATTR 0
|
#define RESETATTR 0
|
||||||
#define BRIGHT 1
|
#define BRIGHT 1
|
||||||
#define DIM 2
|
#define DIM 2
|
||||||
@@ -34,7 +43,7 @@ extern "C"
|
|||||||
#define REVERSE 7
|
#define REVERSE 7
|
||||||
#define HIDDEN 8
|
#define HIDDEN 8
|
||||||
|
|
||||||
/* Colors for text and background */
|
/** Colors for text and background */
|
||||||
#define BLACK 0x0
|
#define BLACK 0x0
|
||||||
#define RED 0x1
|
#define RED 0x1
|
||||||
#define GREEN 0x2
|
#define GREEN 0x2
|
||||||
@@ -54,39 +63,50 @@ extern "C"
|
|||||||
#define WHITE 0x17
|
#define WHITE 0x17
|
||||||
|
|
||||||
#ifndef SCREEN_WIDTH
|
#ifndef SCREEN_WIDTH
|
||||||
#define SCREEN_WIDTH 80 /* Override using, e.g. #define SCREEN_WIDTH tty_width() */
|
#define SCREEN_WIDTH 80 /**< Fallback screen width, possible to override. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Esc[2JEsc[1;1H - Clear screen and move cursor to 1,1 (upper left) pos. */
|
/** Clear screen and move cursor to 1,1 (upper left) pos. */
|
||||||
#define clrscr() fputs("\033[2J\033[1;1H", stdout)
|
#define clrscr() fputs("\033[2J\033[1;1H", stdout)
|
||||||
/* Esc[K - Erases from the current cursor position to the end of the current line. */
|
/** Erases from the current cursor position to the end of the current line. */
|
||||||
#define clreol() fputs("\033[K", stdout)
|
#define clreol() fputs("\033[K", stdout)
|
||||||
/* Esc[2K - Erases the entire current line. */
|
/** Erases the entire current line. */
|
||||||
#define delline() fputs("\033[2K", stdout)
|
#define delline() fputs("\033[2K", stdout)
|
||||||
/* Esc[Line;ColumnH - Moves the cursor to the specified position (coordinates) */
|
/** Moves the cursor to the specified position (coordinates) */
|
||||||
#define gotoxy(x,y) fprintf(stdout, "\033[%d;%dH", y, x)
|
#define gotoxy(x,y) fprintf(stdout, "\033[%d;%dH", y, x)
|
||||||
/* Esc[?25l (lower case L) - Hide Cursor */
|
/** Hide Cursor */
|
||||||
#define hidecursor() fputs("\033[?25l", stdout)
|
#define hidecursor() fputs("\033[?25l", stdout)
|
||||||
/* Esc[?25h (lower case H) - Show Cursor */
|
/** Show Cursor */
|
||||||
#define showcursor() fputs("\033[?25h", stdout)
|
#define showcursor() fputs("\033[?25h", stdout)
|
||||||
|
|
||||||
/* Esc[Value;...;Valuem - Set Graphics Mode (attr, color, val) */
|
/** Set Graphics Mode (attr, color, val) */
|
||||||
#define __set_gm(a,c,v) \
|
#define __set_gm(a,c,v) \
|
||||||
if (!c) \
|
if (!c) \
|
||||||
fprintf(stdout, "\033[%dm", a); \
|
fprintf(stdout, "\033[%dm", a); \
|
||||||
else \
|
else \
|
||||||
fprintf(stdout, "\033[%d;%dm", c & 0x10 ? 1 : 0, (c & 0xF) + v)
|
fprintf(stdout, "\033[%d;%dm", c & 0x10 ? 1 : 0, (c & 0xF) + v)
|
||||||
|
|
||||||
|
/** Set text attribute */
|
||||||
#define textattr(attr) __set_gm(attr, 0, 0)
|
#define textattr(attr) __set_gm(attr, 0, 0)
|
||||||
|
/** Set text color */
|
||||||
#define textcolor(color) __set_gm(RESETATTR, color, 30)
|
#define textcolor(color) __set_gm(RESETATTR, color, 30)
|
||||||
|
/** Set text background */
|
||||||
#define textbackground(color) __set_gm(RESETATTR, color, 40)
|
#define textbackground(color) __set_gm(RESETATTR, color, 40)
|
||||||
|
|
||||||
void initscr(int *row, int *col);
|
void initscr(int *row, int *col);
|
||||||
|
|
||||||
/* Print table heading @line to @fp, with optional leading newline
|
/**
|
||||||
* Example:
|
* Print table heading, with optional leading newline.
|
||||||
|
* @param fp output stream
|
||||||
|
* @param line string to print
|
||||||
|
* @param nl leading newline or not
|
||||||
|
* @param attr attribute
|
||||||
|
*
|
||||||
|
* @verbatim
|
||||||
* _________________ <-- Empty line with UNDERSCORE to frame first heading
|
* _________________ <-- Empty line with UNDERSCORE to frame first heading
|
||||||
* First heading <-- In normal/RESETATTR
|
* First heading <-- In normal/RESETATTR
|
||||||
* SUBHEADING <-- In REVERSE and with capital letters like 'top'
|
* SUBHEADING <-- In REVERSE and with capital letters like 'top'
|
||||||
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
static inline void printhdr(FILE *fp, const char *line, int nl, int attr)
|
static inline void printhdr(FILE *fp, const char *line, int nl, int attr)
|
||||||
{
|
{
|
||||||
@@ -99,12 +119,18 @@ static inline void printhdr(FILE *fp, const char *line, int nl, int attr)
|
|||||||
SCREEN_WIDTH - (int)strlen(line), "");
|
SCREEN_WIDTH - (int)strlen(line), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print reverse mode table heading, e.g. black text on white background.
|
||||||
|
* @param fp output stream
|
||||||
|
* @param line string to print
|
||||||
|
* @param nl leading newline or not
|
||||||
|
*/
|
||||||
static inline void printheader(FILE *fp, const char *line, int nl)
|
static inline void printheader(FILE *fp, const char *line, int nl)
|
||||||
{
|
{
|
||||||
printhdr(fp, line, nl, REVERSE);
|
printhdr(fp, line, nl, REVERSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONIO_H_ */
|
#endif /* LIBITE_CONIO_H_ */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
+57
-36
@@ -21,6 +21,13 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file copyfile.c
|
||||||
|
* @author Claudio Matsuoka
|
||||||
|
* @date 2008
|
||||||
|
* @copyright MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -31,6 +38,7 @@ static int adjust_target(const char *src, char **dst)
|
|||||||
{
|
{
|
||||||
int isdir = 0;
|
int isdir = 0;
|
||||||
|
|
||||||
|
retry:
|
||||||
if (fisdir(*dst)) {
|
if (fisdir(*dst)) {
|
||||||
int slash = 0;
|
int slash = 0;
|
||||||
char *tmp, *ptr = strrchr(src, '/');
|
char *tmp, *ptr = strrchr(src, '/');
|
||||||
@@ -51,16 +59,25 @@ static int adjust_target(const char *src, char **dst)
|
|||||||
|
|
||||||
sprintf(tmp, "%s%s%s", *dst, slash ? "" : "/", ptr);
|
sprintf(tmp, "%s%s%s", *dst, slash ? "" : "/", ptr);
|
||||||
*dst = tmp;
|
*dst = tmp;
|
||||||
|
} else {
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (stat(*dst, &st) && fisslashdir(*dst)) {
|
||||||
|
makedir(*dst, 0755);
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return isdir;
|
return isdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Actual copy loop, used by both copyfile() and fcopyfile()
|
/*
|
||||||
* breaks loop on error and EOF */
|
* Actual copy loop, used by both copyfile() and fcopyfile() breaks loop
|
||||||
|
* on error and EOF
|
||||||
|
*/
|
||||||
static ssize_t do_copy(int in, int out, size_t num, char *buffer, size_t len)
|
static ssize_t do_copy(int in, int out, size_t num, char *buffer, size_t len)
|
||||||
{
|
{
|
||||||
ssize_t ret = 0, size = 0;
|
ssize_t ret = 0, size = -1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
size_t count = num > len ? len : num;
|
size_t count = num > len ? len : num;
|
||||||
@@ -69,11 +86,16 @@ static ssize_t do_copy(int in, int out, size_t num, char *buffer, size_t len)
|
|||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
if (ret == -1 && EINTR == errno)
|
if (ret == -1 && EINTR == errno)
|
||||||
continue;
|
continue;
|
||||||
|
if (ret == 0 && size == -1)
|
||||||
|
size = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret > 0)
|
if (ret > 0) {
|
||||||
|
if (size == -1)
|
||||||
|
size = 0;
|
||||||
size += write(out, buffer, ret);
|
size += write(out, buffer, ret);
|
||||||
|
}
|
||||||
num -= count;
|
num -= count;
|
||||||
} while (num > 0);
|
} while (num > 0);
|
||||||
|
|
||||||
@@ -85,35 +107,39 @@ static void set_mtime(int in, int out)
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
struct timespec tv[2];
|
struct timespec tv[2];
|
||||||
|
|
||||||
fstat(in, &st);
|
if (fstat(in, &st))
|
||||||
|
return;
|
||||||
|
|
||||||
tv[0] = st.st_atim;
|
tv[0] = st.st_atim;
|
||||||
tv[1] = st.st_mtim;
|
tv[1] = st.st_mtim;
|
||||||
futimens(out, tv);
|
futimens(out, tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* copyfile - Copy a file to another.
|
* Copy a file to another.
|
||||||
* @src: Full path name to source file.
|
* @param src Full path name to source file.
|
||||||
* @dst: Full path name to target file.
|
* @param dst Full path name to target file.
|
||||||
* @len: Number of bytes to copy, zero (0) for entire file.
|
* @param len Number of bytes to copy, zero (0) for entire file.
|
||||||
* @opt: An option mask of %LITE_FOPT_COPYFILE_SYM, %LITE_FOPT_KEEP_MTIME
|
* @param opt An option mask of ::LITE_FOPT_COPYFILE_SYM, ::LITE_FOPT_KEEP_MTIME
|
||||||
*
|
*
|
||||||
* This is a C implementation of the command line cp(1) utility. It is one
|
* 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
|
* The @a opt field replaces the @a sym argument in previous releases
|
||||||
* works as follows. To maintain backwards compatibility with @sym
|
* and works as follows. To maintain backwards compatibility with @a
|
||||||
* the %LITE_FOPT_COPYFILE_SYM maintains a value of 1:
|
* sym the ::LITE_FOPT_COPYFILE_SYM has a value of @c 1. Supported
|
||||||
|
* option flags are:
|
||||||
*
|
*
|
||||||
* %LITE_FOPT_COPYFILE_SYM: Recreate symlink or follow to copy target
|
* - ::LITE_FOPT_COPYFILE_SYM Recreate symlink or follow to copy target
|
||||||
* %LITE_FOPT_KEEP_MTIME: Preserve modification time
|
* - ::LITE_FOPT_KEEP_MTIME Preserve modification time
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns The number of bytes copied, or zero, which may be an error
|
||||||
* The number of bytes copied, zero may be error (check errno!), but it
|
* (check @a errno, see Exceptions below), but it may also indicate that
|
||||||
* may also indicate that @src was empty. If @src is a directory @errno
|
* @a src was empty. See exceptions, below.
|
||||||
* will be set to %EISDIR since copyfile() is not recursive.
|
*
|
||||||
|
* @exception EISDIR if @a src is a directory, since copyfile() is not recursive.
|
||||||
*/
|
*/
|
||||||
ssize_t copyfile(const char *src, const char *dst, int len, int opt)
|
ssize_t copyfile(const char *src, const char *dst, int len, int opt)
|
||||||
{
|
{
|
||||||
@@ -183,7 +209,7 @@ ssize_t copyfile(const char *src, const char *dst, int len, int opt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
size = do_copy(in, out, num, buffer, BUFSIZ);
|
size = do_copy(in, out, num, buffer, BUFSIZ);
|
||||||
if (!size && errno)
|
if (size < 0)
|
||||||
saved_errno = errno;
|
saved_errno = errno;
|
||||||
else if (keep_mtim)
|
else if (keep_mtim)
|
||||||
set_mtime(in, out);
|
set_mtime(in, out);
|
||||||
@@ -201,20 +227,19 @@ exit:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* movefile - Move a file to another location
|
* Move a file to another location
|
||||||
* @src: Source file.
|
* @param src Source file.
|
||||||
* @dst: Target file, or location.
|
* @param dst Target file, or location.
|
||||||
*
|
*
|
||||||
* This is a C implementation of the command line mv(1) utility.
|
* This is a C implementation of the command line mv(1) utility.
|
||||||
* Usually the rename() API is sufficient, but not when moving across
|
* Usually the rename() API is sufficient, but not when moving across
|
||||||
* file system boundaries.
|
* file system boundaries.
|
||||||
*
|
*
|
||||||
* The @src argument must include the full path to the source file,
|
* The @p src argument must include the full path to the source file,
|
||||||
* whereas the @dst argument may only be a directory, in which case the
|
* whereas the @p dst argument may only be a directory, in which case
|
||||||
* same file name from @src is used.
|
* the same file name from @p src is used.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns POSIX OK(0), or non-zero with @a errno set.
|
||||||
* POSIX OK(0), or non-zero with errno set.
|
|
||||||
*/
|
*/
|
||||||
int movefile(const char *src, const char *dst)
|
int movefile(const char *src, const char *dst)
|
||||||
{
|
{
|
||||||
@@ -244,15 +269,11 @@ int movefile(const char *src, const char *dst)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fcopyfile - Copy between FILE *fp.
|
* Copy between FILE *fp.
|
||||||
* @src: Source FILE.
|
* @param src Source FILE.
|
||||||
* @dst: Destination FILE.
|
* @param dst Destination FILE.
|
||||||
*
|
*
|
||||||
* Function takes signals into account and will restart the syscalls as
|
* @returns POSIX OK(0), or non-zero with @a errno set on error.
|
||||||
* long as error is %EINTR.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* POSIX OK(0), or non-zero with errno set on error.
|
|
||||||
*/
|
*/
|
||||||
int fcopyfile(FILE *src, FILE *dst)
|
int fcopyfile(FILE *src, FILE *dst)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* Functions for operating on files in directories.
|
/* Functions for operating on files in directories.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2008-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2008-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,6 +15,13 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file dir.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2008-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -48,32 +55,29 @@ static int matcher(const struct dirent *entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dir - List all files of a certain type in the given directory.
|
* List all files of a certain type in the given directory.
|
||||||
* @dir: Base directory for dir operation.
|
* @param dir Base directory for dir operation.
|
||||||
* @type: File type suffix, e.g. ".cfg".
|
* @param type File type suffix, e.g. ".cfg".
|
||||||
* @filter: Optional file name filter.
|
* @param filter Optional file name filter.
|
||||||
* @list: Pointer to an array of file names.
|
* @param list Pointer to an array of file names.
|
||||||
* @strip: Flag, if set dir() strips the file type.
|
* @param strip Flag, if set dir() strips the file type.
|
||||||
*
|
*
|
||||||
* This function returns a @list of files, matching the @type suffix,
|
* This function returns a @a list of files, matching the @a type
|
||||||
* in the given directory @dir.
|
* suffix, in the given directory @a dir.
|
||||||
*
|
*
|
||||||
* The @list argument is a pointer to where to store the dynamically
|
* The @a list argument is a pointer to where to store the dynamically
|
||||||
* allocated list of file names. This list should be free'd by first
|
* allocated list of file names. This list should be free'd by first
|
||||||
* calling free() on each file name and then on the list itself.
|
* calling free() on each file name and then on the list itself.
|
||||||
*
|
*
|
||||||
* If @filter is not %NULL it will be called for each file found. If
|
* If @a filter is not @c NULL it will be called for each file found.
|
||||||
* @filter returns non-zero the @file argument will be included in the
|
* If @a filter returns non-zero the @a file argument is included in the
|
||||||
* resulting @list. If @filter returns zero for given @file it will
|
* resulting @a list. If @a filter returns zero for given @a file it is
|
||||||
* be discarded.
|
* discarded. If the @a strip flag is set the resulting @a list of
|
||||||
|
* files has their file type stripped, including the dot. So a match
|
||||||
|
* "config0.cfg" would be returned as "config0".
|
||||||
*
|
*
|
||||||
* If the @strip flag is set the resulting @list of files has their
|
* @returns The number of files in @a list, zero if no matching files of
|
||||||
* file type stripped, including the dot. So a match "config0.cfg"
|
* @a type, or non-zero on error with @a errno set.
|
||||||
* would be returned as "config0".
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* Number of files in @list, zero if no matching files of @type, or
|
|
||||||
* non-zero on error with @errno set.
|
|
||||||
*/
|
*/
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/* Formatted erase()
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file erasef.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "lite.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like erase() but with formatted string support.
|
||||||
|
* @param fmt Formatted string to be composed into a pathname
|
||||||
|
*
|
||||||
|
* This is a wrapper for the erase() function in lite.h, lessening the
|
||||||
|
* burden of having to compose the filename from parts in a seprate
|
||||||
|
* buffer.
|
||||||
|
*
|
||||||
|
* @returns Upon successful completion erasef() returns POSIX OK(0),
|
||||||
|
* otherwise, -1 is returned and @a errno is set to indicate the error.
|
||||||
|
*/
|
||||||
|
int erasef(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *file;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
file = alloca(len + 1);
|
||||||
|
if (!file) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(file, len + 1, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return erase(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
+48
-4
@@ -21,15 +21,26 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file fexist.c
|
||||||
|
* @author Claudio Matsuoka
|
||||||
|
* @date 2008
|
||||||
|
* @copyright MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "lite.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fexist - Check if a file exists in the file system.
|
* Check if a file exists in the file system.
|
||||||
* @file: File to look for, with full path.
|
* @param file File to look for, with full path.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns @c TRUE(1) if the @a file exists, otherwise @c FALSE(0).
|
||||||
* %TRUE(1) if the file exists, otherwise %FALSE(0).
|
|
||||||
*/
|
*/
|
||||||
int fexist(const char *file)
|
int fexist(const char *file)
|
||||||
{
|
{
|
||||||
@@ -44,6 +55,39 @@ int fexist(const char *file)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like fexist() but with formatted string support
|
||||||
|
* @param fmt Formatted string to be composed into the file to look for.
|
||||||
|
*
|
||||||
|
* This is a wrapper for the fexist() function in lite.h, lessening the
|
||||||
|
* burden of having to compose the filename from parts in a seprate
|
||||||
|
* buffer.
|
||||||
|
*
|
||||||
|
* @returns @c TRUE(1) if the @a file exists, otherwise @c FALSE(0).
|
||||||
|
*/
|
||||||
|
int fexistf(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *file;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
file = alloca(len + 1);
|
||||||
|
if (!file) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(file, len + 1, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return fexist(file);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* indent-tabs-mode: t
|
* indent-tabs-mode: t
|
||||||
|
|||||||
+11
-5
@@ -21,21 +21,27 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file fisdir.c
|
||||||
|
* @author Claudio Matsuoka
|
||||||
|
* @date 2008
|
||||||
|
* @copyright MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fisdir - Check if a path exists and is a directory.
|
* Check if a path exists and is a directory.
|
||||||
* @path: Path to file or directory
|
* @param path Path to file or directory
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns @c TRUE(1) if @p path exists and is a directory, otherwise @c FALSE(0).
|
||||||
* %TRUE(1) if @path exists and is a directory, otherwise %FALSE(0).
|
|
||||||
*/
|
*/
|
||||||
int fisdir(const char *path)
|
int fisdir(const char *path)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
if (!stat(path, &sb) && S_ISDIR(sb.st_mode))
|
if (path && !stat(path, &sb) && S_ISDIR(sb.st_mode))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
/* Formatted fopen()
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file fopenf.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Similar to fopenf() except it takes a @a va_list argument
|
||||||
|
* @param mode An fopen() mode string, e.g. "w+".
|
||||||
|
* @param fmt Formatted string to be composed into a pathname.
|
||||||
|
* @param ap List of variable arguemnts from va_start().
|
||||||
|
*
|
||||||
|
* See fopenf() for details.
|
||||||
|
*
|
||||||
|
* @returns a FILE pointer, or @c NULL on error.
|
||||||
|
*/
|
||||||
|
FILE *vfopenf(const char *mode, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
va_list apc;
|
||||||
|
char *file;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_copy(apc, ap);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, apc);
|
||||||
|
va_end(apc);
|
||||||
|
|
||||||
|
file = alloca(len + 1);
|
||||||
|
if (!file) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_copy(apc, ap);
|
||||||
|
vsnprintf(file, len + 1, fmt, apc);
|
||||||
|
va_end(apc);
|
||||||
|
|
||||||
|
return fopen(file, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open a file based on the formatted string and optional arguments
|
||||||
|
* @param mode An fopen() mode string, e.g. "w+".
|
||||||
|
* @param fmt Formatted string to be composed into a pathname.
|
||||||
|
*
|
||||||
|
* This function is an extension to the fopen() family, lessening the burden
|
||||||
|
* of first having to compose the filename from parts in a seprate buffer.
|
||||||
|
*
|
||||||
|
* @returns Upon successful completion, fopenf() returns a FILE pointer.
|
||||||
|
* Otherwise, @c NULL is returned and @a errno is set to indicate the
|
||||||
|
* error.
|
||||||
|
*/
|
||||||
|
FILE *fopenf(const char *mode, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
fp = vfopenf(mode, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if (!fp)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
+26
-4
@@ -24,6 +24,13 @@
|
|||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file fparseln.c
|
||||||
|
* @author Christos Zoulas
|
||||||
|
* @date 1997
|
||||||
|
* @copyright 2-clause BSD License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -63,10 +70,25 @@ isescaped(const char *sp, const char *p, int esc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* fparseln():
|
/**
|
||||||
* Read a line from a file parsing continuations ending in \
|
* Read a line from a file parsing continuations and trailing newlines
|
||||||
* and eliminating trailing newlines, or comments starting with
|
* @param fp FILE pointer to read from
|
||||||
* the comment char.
|
* @param size The resulting length of the string, unused if @c NULL
|
||||||
|
* @param lineno Incremented with number of lines read, unused if @c NULL
|
||||||
|
* @param str Characters to look for, escape character, continuation, and comment
|
||||||
|
* @param flags ::FPARSELN_UNESCCOMM, ::FPARSELN_UNESCCONT, ::FPARSELN_UNESCESC, ::FPARSELN_UNESCREST, ::FPARSELN_UNESCALL
|
||||||
|
*
|
||||||
|
* This function reads a line from a file, parsing continuations ending
|
||||||
|
* in '\' and eliminating trailing newlines, or comments starting with
|
||||||
|
* the comment char '#'.
|
||||||
|
*
|
||||||
|
* If @a size is not @c NULL, the resulting length of the returned string
|
||||||
|
* is stored in @a size.
|
||||||
|
*
|
||||||
|
* If @a lineno is not @c NULL, it is incremented for each actual line
|
||||||
|
* read from @a fp.
|
||||||
|
*
|
||||||
|
* @returns the line read from @a fp, or @c NULL on EOF or error.
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
|
fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/* Formatted fremove()
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file fremove.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a file based on the formatted string and optional arguments
|
||||||
|
* @param fmt Formatted string to be composed into a pathname
|
||||||
|
*
|
||||||
|
* This function is an extension to remove(), lessening the burden of
|
||||||
|
* first having to compose the filename from parts in a seprate buffer.
|
||||||
|
*
|
||||||
|
* @returns same as remove(3), with an extra @a errno, @c ENOBUFS if
|
||||||
|
* alloca() fails to get a temporary buffer for composing the file name.
|
||||||
|
*/
|
||||||
|
int fremove(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *file;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
file = alloca(len + 1);
|
||||||
|
if (!file) {
|
||||||
|
errno = ENOBUFS;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(file, len + 1, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return remove(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
+18
-11
@@ -21,25 +21,32 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file fsendfile.c
|
||||||
|
* @author Tobias Waldekranz
|
||||||
|
* @date 2013
|
||||||
|
* @copyright MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fsendfile - copy data between file streams
|
* Copy data between file streams.
|
||||||
* @src: Source stream
|
* @param src Source stream
|
||||||
* @dst: Destination stream
|
* @param dst Destination stream
|
||||||
* @len: Number of bytes to copy
|
* @param len Number of bytes to copy
|
||||||
*
|
*
|
||||||
* @dst may be %NULL, in which case @len bytes are read and discarded
|
* The @p dst argument may be @c NULL, in which case @a len bytes are
|
||||||
* from @src. This can be useful for streams where seeking is not
|
* read and discarded from @a src. This can be useful for streams where
|
||||||
* permitted. Additionally, @len may be the special value zero (0), in
|
* seeking is not permitted. Additionally, @a len may be the special
|
||||||
* which case fsendfile() will copy until %EOF is seen on @src.
|
* value zero (0), in which case fsendfile() copies until @c EOF is seen
|
||||||
|
* on @a src.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns The number of bytes copied. If an error is detected -1 is
|
||||||
* The number of bytes copied. If an error is detected -1 is returned
|
* returned and @a errno will be set accordingly.
|
||||||
* and @errno will be set accordingly.
|
|
||||||
*/
|
*/
|
||||||
ssize_t fsendfile(FILE *src, FILE *dst, size_t len)
|
ssize_t fsendfile(FILE *src, FILE *dst, size_t len)
|
||||||
{
|
{
|
||||||
|
|||||||
+15
-8
@@ -1,7 +1,7 @@
|
|||||||
/* Fastinit (finit) ifconfig() implementation.
|
/* Fastinit (finit) ifconfig() implementation.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2008-2010 Claudio Matsuoka <http://helllabs.org/finit/>
|
* Copyright (c) 2008-2010 Claudio Matsuoka <http://helllabs.org/finit/>
|
||||||
* Copyright (C) 2009-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (C) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -22,6 +22,14 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file ifconfig.c
|
||||||
|
* @author Claudio Matsuoka
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2008-2021
|
||||||
|
* @copyright MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
@@ -34,14 +42,13 @@
|
|||||||
extern size_t strlcpy(char *dst, const char *src, size_t siz);
|
extern size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ifconfig - Basic ifconfig like operations on an interface
|
* Basic ifconfig like operations on an interface
|
||||||
* @ifname: Name of interface to operate on
|
* @param ifname Name of interface to operate on
|
||||||
* @addr: If @up then set this optional IPv4 address
|
* @param addr If @p up then set this optional IPv4 address
|
||||||
* @mask: If @up and @addr, and @addr is not INADDR_ANY, then set netmask
|
* @param mask If @p up and @p addr, and @p addr is not @c INADDR_ANY, then set netmask
|
||||||
* @up: Control %IFF_UP flag on interface
|
* @param up Control @c IFF_UP flag on interface
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns POSIX OK(0) on success, or non-zero on error.
|
||||||
* POSIX OK(0) on success, or non-zero on error.
|
|
||||||
*/
|
*/
|
||||||
int ifconfig(const char *ifname, const char *addr, const char *mask, int up)
|
int ifconfig(const char *ifname, const char *addr, const char *mask, int up)
|
||||||
{
|
{
|
||||||
|
|||||||
+39
-36
@@ -1,6 +1,6 @@
|
|||||||
/* Parse UNIX /etc configuration files like /etc/protocols and /etc/services
|
/* Parse UNIX /etc configuration files like /etc/protocols and /etc/services
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2015-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,26 +15,33 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file lfile.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2015-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h> /* FILE */
|
#include <stdio.h> /* FILE */
|
||||||
#include <stdlib.h> /* atoi() */
|
#include <stdlib.h> /* atoi() */
|
||||||
#include <string.h> /* strlen(), strncmp(), strtok_r() */
|
#include <string.h> /* strlen(), strncmp(), strtok_r() */
|
||||||
#include <sys/param.h> /* MAX() */
|
#include <sys/param.h> /* MAX() */
|
||||||
|
|
||||||
|
/** @private for internal use only */
|
||||||
typedef struct lfile {
|
typedef struct lfile {
|
||||||
FILE *fp;
|
FILE *fp; /**< FILE pointer to current stream */
|
||||||
char buf[256];
|
char buf[256]; /**< Internal buffer, limted to 256 bytes per line */
|
||||||
char *save;
|
char *save; /**< Internal save pointer */
|
||||||
const char *sep;
|
const char *sep; /**< Record separator, from lfopen() */
|
||||||
} lfile_t;
|
} lfile_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lfopen - Open file and return parsing context
|
* Open file and return parsing context.
|
||||||
* @file: File to parse
|
* @param file File to parse
|
||||||
* @sep: Separator(s) to use in lftok()
|
* @param sep Separator(s) to use in lftok()
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns Pointer to an @a lfile_t parser context, or @c NULL on error.
|
||||||
* Pointer to a &lftile_t parser context, or %NULL on error.
|
|
||||||
*/
|
*/
|
||||||
lfile_t *lfopen(const char *file, const char *sep)
|
lfile_t *lfopen(const char *file, const char *sep)
|
||||||
{
|
{
|
||||||
@@ -62,8 +69,8 @@ lfile_t *lfopen(const char *file, const char *sep)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lfclose - Close a parser context
|
* Close a parser context.
|
||||||
* @lf: Pointer to &lfile_t context from lfopen()
|
* @param lf: Pointer to @a lfile_t parser context from lfopen()
|
||||||
*/
|
*/
|
||||||
void lfclose(lfile_t *lf)
|
void lfclose(lfile_t *lf)
|
||||||
{
|
{
|
||||||
@@ -76,12 +83,11 @@ void lfclose(lfile_t *lf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lftok - Get next token in file
|
* Get next token in file
|
||||||
* @lf: Pointer to &lfile_t context from lfopen()
|
* @param lf: Pointer to @a lfile_t parser context from lfopen()
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns Next token, read from file previously opened with lfopen(),
|
||||||
* Next token, read from file previously opened with lfopen(),
|
* or @c NULL if EOF.
|
||||||
* or %NULL if EOF.
|
|
||||||
*/
|
*/
|
||||||
char *lftok(lfile_t *lf)
|
char *lftok(lfile_t *lf)
|
||||||
{
|
{
|
||||||
@@ -110,18 +116,17 @@ char *lftok(lfile_t *lf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lfgetkey - Find key in file
|
* Find key in file
|
||||||
* @lf: Pointer to &lfile_t context from lfopen()
|
* @param lf Pointer to @a lfile_t parser context from lfopen()
|
||||||
* @key: Key to look for
|
* @param key Key to look for
|
||||||
*
|
*
|
||||||
* Locate @key from the current position in the file parser context
|
* Locate @a key from the current position in the file parser context
|
||||||
* returned from lfopen(). Please note, the search for @key does not
|
* returned from lfopen(). Please note, the search for @a key does not
|
||||||
* start from the beginning of the file, it searches from the current
|
* start from the beginning of the file, it searches from the current
|
||||||
* position. To restart search from the beginning use rewind() on the
|
* position. To restart search from the beginning use rewind() on the
|
||||||
* lf->fp.
|
* lf->fp.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns The value to @a key, or @c NULL if not found.
|
||||||
* The value to @key, or %NULL if not found.
|
|
||||||
*/
|
*/
|
||||||
char *lfgetkey(lfile_t *lf, const char *key)
|
char *lfgetkey(lfile_t *lf, const char *key)
|
||||||
{
|
{
|
||||||
@@ -139,15 +144,14 @@ char *lfgetkey(lfile_t *lf, const char *key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lfgetint - Same as lfgetkey() but returns an integer
|
* Same as lfgetkey() but returns an integer.
|
||||||
* @lf: Pointer to &lfile_t context from lfopen()
|
* @param lf Pointer to @a lfile_t parser context from lfopen()
|
||||||
* @key: Key to look for
|
* @param key Key to look for
|
||||||
*
|
*
|
||||||
* This function is the same as lfgetkey() but returns the positive
|
* This function is the same as lfgetkey() but returns the positive
|
||||||
* integer value for the matching @key, if found.
|
* integer value for the matching @a key, if found.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns The positive integer value for @a key, or -1 if not found.
|
||||||
* The positive integer value for @key, or -1 if not found.
|
|
||||||
*/
|
*/
|
||||||
int lfgetint(lfile_t *lf, const char *key)
|
int lfgetint(lfile_t *lf, const char *key)
|
||||||
{
|
{
|
||||||
@@ -160,16 +164,15 @@ int lfgetint(lfile_t *lf, const char *key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fgetint - Find the integer value for key in a file
|
* Find the integer value for key in a file.
|
||||||
* @file: File to search for @key
|
* @param file File to search for @a key
|
||||||
* @sep: Separator for tokens in @file
|
* @param sep Separator for tokens in @a file
|
||||||
* @key: Key to look for in @file
|
* @param key Key to look for in @a file
|
||||||
*
|
*
|
||||||
* This is a convenience wrapper for lfopen(), lfgetint(), and
|
* This is a convenience wrapper for lfopen(), lfgetint(), and
|
||||||
* lfclose().
|
* lfclose().
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns The positive integer value for @a key, or -1 if not found.
|
||||||
* The positive integer value for @key, or -1 if not found.
|
|
||||||
*/
|
*/
|
||||||
int fgetint(const char *file, const char *sep, const char *key)
|
int fgetint(const char *file, const char *sep, const char *key)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,5 +8,4 @@ Description: Frog DNA, basically
|
|||||||
Version: @VERSION@
|
Version: @VERSION@
|
||||||
Requires:
|
Requires:
|
||||||
Libs: -L${libdir} -lite
|
Libs: -L${libdir} -lite
|
||||||
Cflags: -I${includedir}
|
Cflags: -I${includedir} -D_LIBITE_LITE
|
||||||
|
|
||||||
+99
-27
@@ -1,7 +1,7 @@
|
|||||||
/* Collection of frog DNA
|
/* Collection of frog DNA
|
||||||
*
|
*
|
||||||
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
|
* Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
|
||||||
* Copyright (c) 2008-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2008-2023 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -22,17 +22,29 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection of frog DNA
|
||||||
|
* @file lite.h
|
||||||
|
* @author Claudio Matsuoka (2008-2010)
|
||||||
|
* @author Joachim Wiberg (2008-2023)
|
||||||
|
* @copyright MIT License
|
||||||
|
*
|
||||||
|
* The latest version of this manual and the libite (-lite) software
|
||||||
|
* library are available at https://github.com/troglobit/libite/
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LITE_H_
|
#ifndef LIBITE_LITE_H_
|
||||||
#define LITE_H_
|
#define LIBITE_LITE_H_
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h> /* Definition of AT_* constants for utimensat() */
|
#include <fcntl.h> /* Definition of AT_* constants for utimensat() */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdarg.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>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -43,33 +55,51 @@ extern "C"
|
|||||||
/*
|
/*
|
||||||
* fparseln() specific operation flags.
|
* fparseln() specific operation flags.
|
||||||
*/
|
*/
|
||||||
#define FPARSELN_UNESCESC 0x01
|
#define FPARSELN_UNESCESC 0x01 /**< Remove escape preceding an escaped comment. */
|
||||||
#define FPARSELN_UNESCCONT 0x02
|
#define FPARSELN_UNESCCONT 0x02 /**< Remove escape preceding an escaped continuation. */
|
||||||
#define FPARSELN_UNESCCOMM 0x04
|
#define FPARSELN_UNESCCOMM 0x04 /**< Remove escape preceding an escaped escape. */
|
||||||
#define FPARSELN_UNESCREST 0x08
|
#define FPARSELN_UNESCREST 0x08 /**< Remove escape preceding any other character. */
|
||||||
#define FPARSELN_UNESCALL 0x0f
|
#define FPARSELN_UNESCALL 0x0f /**< All of the above. */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* copyfile() and rsync() option flags
|
* copyfile() and rsync() option flags
|
||||||
*/
|
*/
|
||||||
#define LITE_FOPT_RSYNC_DELETE 0x01
|
#define LITE_FOPT_RSYNC_DELETE 0x01 /**< Prune files from destination that are not in source */
|
||||||
#define LITE_FOPT_COPYFILE_SYM 0x01
|
#define LITE_FOPT_COPYFILE_SYM 0x01 /**< Recreate symlink or follow to copy target */
|
||||||
#define LITE_FOPT_KEEP_MTIME 0x02
|
#define LITE_FOPT_KEEP_MTIME 0x02 /**< Preserve modification time */
|
||||||
|
|
||||||
typedef struct lfile lfile_t;
|
typedef struct lfile lfile_t; /**< Opqaue context struct for lfile APIs */
|
||||||
typedef struct sdbuf sdbuf_t;
|
typedef struct sdbuf sdbuf_t; /**< Opqaue context struct for telnet APIs */
|
||||||
|
|
||||||
char *chomp (char *str);
|
char *chomp (char *str);
|
||||||
|
|
||||||
|
int erasef (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||||
|
|
||||||
char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
|
char *fparseln (FILE *, size_t *, size_t *, const char[3], int);
|
||||||
|
|
||||||
int fexist (const char *file);
|
int fexist (const char *file);
|
||||||
|
int fexistf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));;
|
||||||
int fisdir (const char *path);
|
int fisdir (const char *path);
|
||||||
|
|
||||||
|
FILE *vfopenf (const char *mode, const char *fmt, va_list ap);
|
||||||
|
FILE *fopenf (const char *mode, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||||
|
int fremove (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||||
FILE *tempfile (void);
|
FILE *tempfile (void);
|
||||||
ssize_t copyfile (const char *src, const char *dst, int len, int opt);
|
ssize_t copyfile (const char *src, const char *dst, int len, int opt);
|
||||||
int movefile (const char *src, const char *dst);
|
int movefile (const char *src, const char *dst);
|
||||||
int fcopyfile (FILE *src, FILE *dst);
|
int fcopyfile (FILE *src, FILE *dst);
|
||||||
ssize_t fsendfile (FILE *src, FILE *dst, size_t len);
|
ssize_t fsendfile (FILE *src, FILE *dst, size_t len);
|
||||||
|
int truncatef (off_t length, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||||
|
|
||||||
|
char *vreadsnf (char *line, size_t len, const char *fmt, va_list ap);
|
||||||
|
char *readsnf (char *line, size_t len, const char *fmt, ...);
|
||||||
|
int writesf (const char *str, const char *mode, const char *fmt, ...);
|
||||||
|
|
||||||
|
int vreadllf (long long *value, const char *fmt, va_list ap);
|
||||||
|
int readllf (long long *value, const char *fmt, ...);
|
||||||
|
int readdf (int *value, const char *fmt, ...);
|
||||||
|
int writellf (long long value, const char *mode, const char *fmt, ...);
|
||||||
|
int writedf (int value, const char *mode, const char *fmt, ...);
|
||||||
|
|
||||||
int ifconfig (const char *ifname, const char *addr, const char *mask, int up);
|
int ifconfig (const char *ifname, const char *addr, const char *mask, int up);
|
||||||
|
|
||||||
@@ -80,12 +110,15 @@ char *lfgetkey (lfile_t *lf, const char *key);
|
|||||||
int lfgetint (lfile_t *lf, const char *key);
|
int lfgetint (lfile_t *lf, const char *key);
|
||||||
int fgetint (const char *file, const char *sep, const char *key);
|
int fgetint (const char *file, const char *sep, const char *key);
|
||||||
|
|
||||||
|
int fmkpath (mode_t mode, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||||
int mkpath (const char *dir, mode_t mode);
|
int mkpath (const char *dir, mode_t mode);
|
||||||
int makepath (const 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 opt, int (*filter) (const char *file));
|
int rsync (char *src, char *dst, int opt, int (*filter) (const char *file));
|
||||||
|
|
||||||
|
FILE *popenf (const char *type, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
||||||
|
|
||||||
int pidfile (const char *basename);
|
int pidfile (const char *basename);
|
||||||
int pidfile_signal(const char *pidfile, int signal);
|
int pidfile_signal(const char *pidfile, int signal);
|
||||||
pid_t pidfile_read (const char *pidfile);
|
pid_t pidfile_read (const char *pidfile);
|
||||||
@@ -96,12 +129,17 @@ void *reallocarray(void *optr, size_t nmemb, size_t size);
|
|||||||
void progress (int percent, int max_width);
|
void progress (int percent, int max_width);
|
||||||
void progress_simple(int percent);
|
void progress_simple(int percent);
|
||||||
|
|
||||||
|
int runbg (char *const cmd[], int delay);
|
||||||
|
int systemf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||||
|
|
||||||
sdbuf_t*telnet_open (int addr, short port);
|
sdbuf_t*telnet_open (int addr, short port);
|
||||||
int telnet_close (sdbuf_t *ctx);
|
int telnet_close (sdbuf_t *ctx);
|
||||||
int telnet_expect (sdbuf_t *ctx, char *script[], FILE *output);
|
int telnet_expect (sdbuf_t *ctx, char *script[], FILE *output);
|
||||||
int telnet_session (int addr, short port, char *script[], FILE *output);
|
int telnet_session (int addr, short port, char *script[], FILE *output);
|
||||||
|
|
||||||
int yorn (const char *fmt, ...);
|
int touchf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||||
|
|
||||||
|
int yorn (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||||
|
|
||||||
char *which (const char *cmd);
|
char *which (const char *cmd);
|
||||||
int whichp (const char *cmd);
|
int whichp (const char *cmd);
|
||||||
@@ -109,17 +147,34 @@ int whichp (const char *cmd);
|
|||||||
#ifndef touch
|
#ifndef touch
|
||||||
#include <sys/stat.h> /* utimensat() */
|
#include <sys/stat.h> /* utimensat() */
|
||||||
#include <sys/time.h> /* utimensat() on *BSD */
|
#include <sys/time.h> /* utimensat() on *BSD */
|
||||||
|
/**
|
||||||
|
* Create a file, ignoring errors for already existing files
|
||||||
|
* @param path Path to file to create.
|
||||||
|
*
|
||||||
|
* @returns POSIX OK(0), or non-zero on error.
|
||||||
|
*/
|
||||||
static inline int touch(const char *path)
|
static inline int touch(const char *path)
|
||||||
{
|
{
|
||||||
if (mknod((path), S_IFREG|0644, 0)) {
|
int fd;
|
||||||
if (errno == EEXIST)
|
|
||||||
return utimensat(AT_FDCWD, path, NULL, 0);
|
if (utimensat(AT_FDCWD, path, NULL, 0)) {
|
||||||
return -1;
|
if (errno != ENOENT)
|
||||||
|
return -1;
|
||||||
|
fd = creat(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
||||||
|
if (fd < 0)
|
||||||
|
return -1;
|
||||||
|
close(fd);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifndef makedir
|
#ifndef makedir
|
||||||
|
/**
|
||||||
|
* Create a directory, ignoring errors for already existing files
|
||||||
|
* @param path Path to directory to create.
|
||||||
|
*
|
||||||
|
* @returns POSIX OK(0), or non-zero on error.
|
||||||
|
*/
|
||||||
static inline int makedir(const char *path, mode_t mode)
|
static inline int makedir(const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
if (mkdir(path, mode) && errno != EEXIST)
|
if (mkdir(path, mode) && errno != EEXIST)
|
||||||
@@ -128,6 +183,12 @@ static inline int makedir(const char *path, mode_t mode)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifndef makefifo
|
#ifndef makefifo
|
||||||
|
/**
|
||||||
|
* Create a FIFO, ignoring errors for already existing files
|
||||||
|
* @param path Path to FIFO to create.
|
||||||
|
*
|
||||||
|
* @returns POSIX OK(0), or non-zero on error.
|
||||||
|
*/
|
||||||
static inline int makefifo(const char *path, mode_t mode)
|
static inline int makefifo(const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
if (mkfifo(path, mode) && errno != EEXIST)
|
if (mkfifo(path, mode) && errno != EEXIST)
|
||||||
@@ -136,6 +197,12 @@ static inline int makefifo(const char *path, mode_t mode)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifndef erase
|
#ifndef erase
|
||||||
|
/**
|
||||||
|
* Remove a file, ignoring errors for missing files
|
||||||
|
* @param path Path to file to remove.
|
||||||
|
*
|
||||||
|
* @returns POSIX OK(0), or non-zero on error.
|
||||||
|
*/
|
||||||
static inline int erase(const char *path)
|
static inline int erase(const char *path)
|
||||||
{
|
{
|
||||||
if (remove(path) && errno != ENOENT)
|
if (remove(path) && errno != ENOENT)
|
||||||
@@ -157,27 +224,32 @@ static inline int erase(const char *path)
|
|||||||
|
|
||||||
/* Unline isset(), setbit() et al, these work with integers/shorts/longwords/etc. */
|
/* Unline isset(), setbit() et al, these work with integers/shorts/longwords/etc. */
|
||||||
#ifndef ISCLR
|
#ifndef ISCLR
|
||||||
#define ISCLR(word,bit) ((word & (1 << (bit)) ? 0 : 1))
|
#define ISCLR(word,bit) ((word & (1 << (bit)) ? 0 : 1)) /**< Is bit cleared in word? */
|
||||||
#endif
|
#endif
|
||||||
#ifndef ISSET
|
#ifndef ISSET
|
||||||
#define ISSET(word,bit) ((word & (1 << (bit)) ? 1 : 0))
|
#define ISSET(word,bit) ((word & (1 << (bit)) ? 1 : 0)) /**< Is bit set in word? */
|
||||||
#endif
|
#endif
|
||||||
#ifndef ISOTHER
|
#ifndef ISOTHER
|
||||||
#define ISOTHER(word,bit) ((word & ~(1 << (bit)) ? 1 : 0)) /* Is any other bit set? */
|
#define ISOTHER(word,bit) ((word & ~(1 << (bit)) ? 1 : 0)) /**< Is any other bit set? */
|
||||||
#endif
|
#endif
|
||||||
#ifndef SETBIT
|
#ifndef SETBIT
|
||||||
#define SETBIT(word,bit) (word |= (1 << (bit)))
|
#define SETBIT(word,bit) (word |= (1 << (bit))) /**< Set bit in word. */
|
||||||
#endif
|
#endif
|
||||||
#ifndef CLRBIT
|
#ifndef CLRBIT
|
||||||
#define CLRBIT(word,bit) (word &= ~(1 << (bit)))
|
#define CLRBIT(word,bit) (word &= ~(1 << (bit))) /**< Clear bit in word. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* From The Practice of Programming, by Kernighan and Pike */
|
/* From The Practice of Programming, by Kernighan and Pike */
|
||||||
#ifndef NELEMS
|
#ifndef NELEMS
|
||||||
#define NELEMS(array) (sizeof(array) / sizeof(array[0]))
|
#define NELEMS(array) (sizeof(array) / sizeof(array[0])) /**< Number of elements in array. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Does directory end with a slash? */
|
/**
|
||||||
|
* Does directory end with a slash?
|
||||||
|
* @param dir Path string to check.
|
||||||
|
*
|
||||||
|
* @returns @c TRUE(1) or @c FALSE(0)
|
||||||
|
*/
|
||||||
static inline int fisslashdir(const char *dir)
|
static inline int fisslashdir(const char *dir)
|
||||||
{
|
{
|
||||||
if (!dir)
|
if (!dir)
|
||||||
@@ -191,10 +263,10 @@ static inline int fisslashdir(const 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) pidfile_read(file)
|
||||||
#define signal_pidfile(file, signo) pidfile_signal(file, signo)
|
#define signal_pidfile(file, signo) pidfile_signal(file, signo)
|
||||||
|
|
||||||
#endif /* LITE_H_ */
|
#endif /* LIBITE_LITE_H_ */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
+58
-17
@@ -1,6 +1,6 @@
|
|||||||
/* mkpath() -- Create all components leading up to a given directory
|
/* mkpath() -- Create all components leading up to a given directory
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013-2016 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2013-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,19 +15,27 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file makepath.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2013-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "lite.h"
|
#include "lite.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mkpath - Like makepath() but takes a mode_t argument
|
* makepath() but takes a mode_t argument.
|
||||||
* @dir: Directory to created, relative or absolute
|
* @param dir Directory to created, relative or absolute
|
||||||
* @mode: A &mode_t mode to create @dir with
|
* @param mode A &mode_t mode to create @a dir with
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns POSIX OK(0) on success, otherwise -1 with @a errno set.
|
||||||
* POSIX OK(0) on success, otherwise -1 with @errno set.
|
|
||||||
*/
|
*/
|
||||||
int mkpath(const char *dir, mode_t mode)
|
int mkpath(const char *dir, mode_t mode)
|
||||||
{
|
{
|
||||||
@@ -47,19 +55,52 @@ int mkpath(const char *dir, mode_t mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* makepath - Create all components of the specified directory.
|
* Formatted version of mkpath().
|
||||||
* @dir: Directory to create.
|
* @param mode A mode_t mode to create directories with
|
||||||
|
* @param fmt Formatted string to be composed into a pathname
|
||||||
*
|
*
|
||||||
* Comment:
|
* @note Notice the swapped arguments, compared to mkpath()!
|
||||||
* 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 with @a errno set.
|
||||||
* POSIX OK (0) on success, otherwise -1 and errno set appropriately.
|
*/
|
||||||
* This function returns EINVAL on bad argument, or ENOMEM when it
|
int fmkpath(mode_t mode, const char *fmt, ...)
|
||||||
* fails allocating temporary memory. For other error codes see the
|
{
|
||||||
* mkdir() syscall description.
|
va_list ap;
|
||||||
|
char *path;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
path = alloca(len + 1);
|
||||||
|
if (!path) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(path, len + 1, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return mkpath(path, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create all components of the specified directory.
|
||||||
|
* @param dir Directory to create.
|
||||||
|
*
|
||||||
|
* @note It is strongly recommended to use mkpath() over this function
|
||||||
|
* since it has the @a mode argument while this function default to
|
||||||
|
* 0777, which in most cases is insecure.
|
||||||
|
*
|
||||||
|
* @returns POSIX OK (0) on success, otherwise -1 and @a errno set
|
||||||
|
* appropriately.
|
||||||
|
*
|
||||||
|
* @exception EINVAL on bad argument, or
|
||||||
|
* @exception ENOMEM when it fails allocating temporary memory.
|
||||||
|
*
|
||||||
|
* For other error codes see the mkdir(2) syscall description.
|
||||||
*/
|
*/
|
||||||
int makepath(const char *dir)
|
int makepath(const char *dir)
|
||||||
{
|
{
|
||||||
|
|||||||
+19
-2
@@ -31,6 +31,13 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file pidfile.c
|
||||||
|
* @author NetBSD Foundation Inc.
|
||||||
|
* @date 1999
|
||||||
|
* @copyright 2-clause BSD License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <sys/stat.h> /* utimensat() */
|
#include <sys/stat.h> /* utimensat() */
|
||||||
#include <sys/time.h> /* utimensat() on *BSD */
|
#include <sys/time.h> /* utimensat() on *BSD */
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -50,8 +57,18 @@ const char *__pidfile_path = _PATH_VARRUN; /* Note: includes trailing slash '/'
|
|||||||
const char *__pidfile_name = NULL;
|
const char *__pidfile_name = NULL;
|
||||||
extern char *__progname;
|
extern char *__progname;
|
||||||
|
|
||||||
int
|
/**
|
||||||
pidfile(const char *basename)
|
* Create or update mtime of process PID file.
|
||||||
|
* @param basename Program name, or @c NULL, may start with '/'
|
||||||
|
*
|
||||||
|
* This function is intended to be used by UNIX daemons to save the PID of the main process
|
||||||
|
* responsible for handling signals. If @p basename is @c NULL the implicit @a __progname
|
||||||
|
* variable from the C-library is used. The @p basename may also start with '/', in which
|
||||||
|
* case it is interpreted as the absolute path to the PID file.
|
||||||
|
*
|
||||||
|
* @returns POSIX OK(0) on success, otherwise non-zero on error.
|
||||||
|
*/
|
||||||
|
int pidfile(const char *basename)
|
||||||
{
|
{
|
||||||
int save_errno;
|
int save_errno;
|
||||||
int atexit_already;
|
int atexit_already;
|
||||||
|
|||||||
+32
-23
@@ -1,6 +1,6 @@
|
|||||||
/* Functions for dealing with PID files (client side)
|
/* Functions for dealing with PID files (client side)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,6 +15,13 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file pidfilefn.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2009-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -24,16 +31,20 @@
|
|||||||
extern char *chomp(char *str);
|
extern char *chomp(char *str);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pidfile_read - Reads a PID value from a pidfile.
|
* Reads a PID value from a pidfile.
|
||||||
* @pidfile: File containing PID, usually in /var/run/<PROC>.pid
|
* @param pidfile File containing PID, usually in @c /var/run/PROCNAME.pid
|
||||||
*
|
*
|
||||||
* This function takes a @pidfile and returns the PID found therein.
|
* This function takes a @p pidfile and returns the PID found therein.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns On invalid @p pidfile, -1 with @a errno set. If the @p
|
||||||
* On invalid @pidfile -1 and errno set to %EINVAL, when @pidfile does not exist -1
|
* pidfile is empty, or when its contents cannot be translated, this
|
||||||
* and errno set to %ENOENT. When the pidfile is empty or when its contents cannot
|
* function returns zero (0), on success this function returns a PID
|
||||||
* be translated this function returns zero (0), on success this function returns
|
* value greater than one.
|
||||||
* a PID value greater than one. PID 1 is reserved for the system init process.
|
*
|
||||||
|
* @note PID 1 is reserved for the system init process.
|
||||||
|
*
|
||||||
|
* @exception EINVAL on invalid @p pidfile, or
|
||||||
|
* @exception ENOENT when @p pidfile does not exist.
|
||||||
*/
|
*/
|
||||||
pid_t pidfile_read(const char *pidfile)
|
pid_t pidfile_read(const char *pidfile)
|
||||||
{
|
{
|
||||||
@@ -66,15 +77,14 @@ pid_t pidfile_read(const char *pidfile)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pidfile_poll - Poll for the existence of a pidfile and return PID
|
* Poll for the existence of a pidfile and return PID.
|
||||||
* @pidfile: Path to pidfile to poll for
|
* @param pidfile Path to pidfile to poll for
|
||||||
*
|
*
|
||||||
* This function polls for the pidfile at @pidfile for at most 5 seconds
|
* This function polls for the pidfile at @p pidfile for at most 5
|
||||||
* before timing out. If the file is created within that time span the
|
* seconds before timing out. If the file is created within that time
|
||||||
* file is read and its PID contents returned.
|
* span the file is read and its PID contents returned.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns The PID read from @p pidfile, or zero on timeout.
|
||||||
* The PID read from @pidfile, or zero on timeout.
|
|
||||||
*/
|
*/
|
||||||
pid_t pidfile_poll(const char *pidfile)
|
pid_t pidfile_poll(const char *pidfile)
|
||||||
{
|
{
|
||||||
@@ -92,15 +102,14 @@ pid_t pidfile_poll(const char *pidfile)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pidfile_signal - Send signal to a PID and cleanup pidfile afterwards
|
* Send signal to a PID and cleanup pidfile afterwards.
|
||||||
* @pidfile: File containing PID, usually in /var/run/<PROC>.pid
|
* @param pidfile File containing PID, usually in @c /var/run/PROCNAME.pid
|
||||||
* @signal: Signal to send to PID found in @pidfile.
|
* @param signal Signal to send to PID found in @p pidfile.
|
||||||
*
|
*
|
||||||
* If @signal is any of %SIGTERM, %SIGKILL, or if kill() returns -1 the
|
* If @p signal is any of @c SIGTERM or @c SIGKILL, or if kill(2)
|
||||||
* @pidfile is removed.
|
* returns -1, the @p pidfile is removed.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns POSIX OK(0) on success, non-zero otherwise.
|
||||||
* POSIX OK(0) on success, non-zero otherwise.
|
|
||||||
*/
|
*/
|
||||||
int pidfile_signal(const char *pidfile, int signal)
|
int pidfile_signal(const char *pidfile, int signal)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/* Formatted popen()
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Tobias Waldekranz <tobias@waldekranz.com>
|
||||||
|
* Copyright (c) 2023 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formatted pipe stream to or from a process
|
||||||
|
* @param type A popen() type, "r" or "w", can also include "e" for @c O_CLOEXEC.
|
||||||
|
* @param fmt Formatted string to be composed into a shell command line.
|
||||||
|
*
|
||||||
|
* This function is an extension to popen(), lessening the burden of
|
||||||
|
* first having to compose the filename from parts in a seprate buffer.
|
||||||
|
*
|
||||||
|
* @returns Upon successful completion, popenf() returns a FILE pointer.
|
||||||
|
* Otherwise, @c NULL is returned and @a errno is set to indicate the
|
||||||
|
* error.
|
||||||
|
*/
|
||||||
|
FILE *popenf(const char *type, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *cmd;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
cmd = alloca(len + 1);
|
||||||
|
if (!cmd) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(cmd, len + 1, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return popen(cmd, type);
|
||||||
|
}
|
||||||
+229
@@ -0,0 +1,229 @@
|
|||||||
|
/* Reading and writing values/strings to/from /proc and /sys style files
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Tobias Waldekranz <tobias@waldekranz.com>
|
||||||
|
* Copyright (c) 2023 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file procval.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2023
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "lite.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Similar to readsnf() except it takes a @a va_list argument
|
||||||
|
* @param line Pointer to line buffer.
|
||||||
|
* @param len Size of line buffer.
|
||||||
|
* @param fmt Formatted string to be composed into a pathname.
|
||||||
|
* @param ap List of variable arguemnts from va_start().
|
||||||
|
*
|
||||||
|
* For details, see readsnf().
|
||||||
|
*
|
||||||
|
* @returns same as readsnf().
|
||||||
|
*/
|
||||||
|
char *vreadsnf(char *line, size_t len, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
va_list apc;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
va_copy(apc, ap);
|
||||||
|
fp = vfopenf("r", fmt, apc);
|
||||||
|
va_end(apc);
|
||||||
|
if (!fp)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!fgets(line, len, fp)) {
|
||||||
|
fclose(fp);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return chomp(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read first line from a file composed from fmt and optional args.
|
||||||
|
* @param line Pointer to line buffer.
|
||||||
|
* @param len Size of line buffer.
|
||||||
|
* @param fmt Formatted string to be composed into a pathname.
|
||||||
|
*
|
||||||
|
* @returns On success, this function returns the @p line read from the
|
||||||
|
* file, with any trailing '\n' chomp()ed out. On error, @c NULL.
|
||||||
|
*/
|
||||||
|
char *readsnf(char *line, size_t len, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *ln;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
ln = vreadsnf(line, len, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return ln;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a string buffer to a file composed from fmt and optional args.
|
||||||
|
* @param str Pointer to string buffer, may be multiple lines.
|
||||||
|
* @param mode An fopen() mode string, e.g. "w+".
|
||||||
|
* @param fmt Formatted string to be composed into a pathname.
|
||||||
|
*
|
||||||
|
* @returns result of operation, with @a errno set on error.
|
||||||
|
*/
|
||||||
|
int writesf(const char *str, const char *mode, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
fp = vfopenf(mode, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if (!fp)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
fprintf(fp, "%s\n", str);
|
||||||
|
return fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as readllf() except it takes a @a va_list argument.
|
||||||
|
*/
|
||||||
|
int vreadllf(long long *value, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
char line[0x100];
|
||||||
|
|
||||||
|
if (!vreadsnf(line, sizeof(line), fmt, ap))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
*value = strtoll(line, NULL, 0);
|
||||||
|
|
||||||
|
return errno ? -1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read 64-bit integer value from a file composed from fmt and optional args.
|
||||||
|
* @param value Pointer to where to store read 64-bit integer value.
|
||||||
|
* @param mode An fopen() mode string, e.g. "w+".
|
||||||
|
* @param fmt Formatted string to be composed into a pathname.
|
||||||
|
*
|
||||||
|
* @returns result of operation, with @a errno set on error.
|
||||||
|
*/
|
||||||
|
int readllf(long long *value, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
rc = vreadllf(value, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read integer value from a file composed from fmt and optional args.
|
||||||
|
* @param value Pointer to where to store read integer value.
|
||||||
|
* @param mode An fopen() mode string, e.g. "w+".
|
||||||
|
* @param fmt Formatted string to be composed into a pathname.
|
||||||
|
*
|
||||||
|
* @returns result of operation, with @a errno set on error.
|
||||||
|
*/
|
||||||
|
int readdf(int *value, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
long long tmp;
|
||||||
|
va_list ap;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
rc = vreadllf(&tmp, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
if (tmp < INT_MIN || tmp > INT_MAX) {
|
||||||
|
errno = ERANGE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*value = tmp;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write 64-bit integer value to a file composed from fmt and optional args.
|
||||||
|
* @param value 64-bit integer value to write.
|
||||||
|
* @param mode An fopen() mode string, e.g. "w+".
|
||||||
|
* @param fmt Formatted string to be composed into a pathname.
|
||||||
|
*
|
||||||
|
* @returns result of operation, with @a errno set on error.
|
||||||
|
*/
|
||||||
|
int writellf(long long value, const char *mode, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
fp = vfopenf(mode, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if (!fp)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
fprintf(fp, "%lld\n", value);
|
||||||
|
return fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write integer value to a file composed from fmt and optional args.
|
||||||
|
* @param value Integer value to write.
|
||||||
|
* @param mode An fopen() mode string, e.g. "w+".
|
||||||
|
* @param fmt Formatted string to be composed into a pathname.
|
||||||
|
*
|
||||||
|
* @returns result of operation, with @a errno set on error.
|
||||||
|
*/
|
||||||
|
int writedf(int value, const char *mode, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
fp = vfopenf(mode, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if (!fp)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
fprintf(fp, "%d\n", value);
|
||||||
|
return fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
+19
-8
@@ -1,6 +1,6 @@
|
|||||||
/* Simple termios based progress bar
|
/* Simple termios based progress bar
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2012-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,6 +15,13 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file progress.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2012-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <limits.h> /* INT_MAX */
|
#include <limits.h> /* INT_MAX */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -40,21 +47,21 @@ static char spinner(char *style)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* progress - Advanced ASCII progress bar with spinner
|
* Advanced ASCII progress bar with spinner
|
||||||
* @percent: Start first call with this set to 0, end with 100
|
* @param percent Start first call with this set to 0, end with 100
|
||||||
* @max_width: Max width of progress bar, in total characters.
|
* @param max_width Max width of progress bar, in total characters.
|
||||||
*
|
*
|
||||||
* This function draws an advanced ASCII progressbar at the current
|
* This function draws an advanced ASCII progressbar at the current
|
||||||
* line. It always start from the first column.
|
* line. It always start from the first column.
|
||||||
*
|
*
|
||||||
* The progress bar will hide the cursor if started with @percent 0 and
|
* The progress bar will hide the cursor if started with @p percent 0
|
||||||
* show it again at the end, when called with @percent 100.
|
* and show it again at the end, when called with @p percent 100.
|
||||||
*
|
*
|
||||||
* While being called with the same percentage the spinner will spin,
|
* While being called with the same percentage the spinner will spin,
|
||||||
* to show the user the process hasn't frozen.
|
* to show the user the process hasn't frozen.
|
||||||
*
|
*
|
||||||
* If the output TTY cannot interpret control characters, like \r, it is
|
* If the output TTY cannot interpret control characters, like `\r`, it
|
||||||
* advised to instead used the progress_simple() function.
|
* is advised to instead used the progress_simple() function.
|
||||||
*/
|
*/
|
||||||
void progress(int percent, int max_width)
|
void progress(int percent, int max_width)
|
||||||
{
|
{
|
||||||
@@ -85,6 +92,10 @@ void progress(int percent, int max_width)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alternative progress bar on systems where progress() doesn't work
|
||||||
|
* @param percent Start first call with this set to 0, end with 100
|
||||||
|
*/
|
||||||
void progress_simple(int percent)
|
void progress_simple(int percent)
|
||||||
{
|
{
|
||||||
static int last = 1;
|
static int last = 1;
|
||||||
|
|||||||
+6
-1
@@ -40,7 +40,12 @@ extern "C"
|
|||||||
#ifndef _SYS_QUEUE_H_
|
#ifndef _SYS_QUEUE_H_
|
||||||
#define _SYS_QUEUE_H_
|
#define _SYS_QUEUE_H_
|
||||||
|
|
||||||
/*
|
/**
|
||||||
|
* @file queue.h
|
||||||
|
* @author The Regents of the University of California
|
||||||
|
* @date 1991, 1993
|
||||||
|
* @copyright 3-clause BSD License
|
||||||
|
*
|
||||||
* This file defines five types of data structures: singly-linked lists,
|
* This file defines five types of data structures: singly-linked lists,
|
||||||
* lists, simple queues, tail queues and XOR simple queues.
|
* lists, simple queues, tail queues and XOR simple queues.
|
||||||
*
|
*
|
||||||
|
|||||||
+16
-2
@@ -15,6 +15,13 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file reallocarray.c
|
||||||
|
* @author Otto Moerbeek
|
||||||
|
* @date 2008
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -26,8 +33,15 @@
|
|||||||
*/
|
*/
|
||||||
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
|
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
|
||||||
|
|
||||||
void *
|
/**
|
||||||
reallocarray(void *optr, size_t nmemb, size_t size)
|
* Similar to realloc() but for an array of items, like calloc()
|
||||||
|
* @param optr Pointer to old (current) array
|
||||||
|
* @param nmemb Number of elements
|
||||||
|
* @param size Size of each element, in bytes
|
||||||
|
*
|
||||||
|
* @returns A pointer to the new array, or @c NULL on error.
|
||||||
|
*/
|
||||||
|
void *reallocarray(void *optr, size_t nmemb, size_t size)
|
||||||
{
|
{
|
||||||
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
|
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
|
||||||
nmemb > 0 && SIZE_MAX / nmemb < size) {
|
nmemb > 0 && SIZE_MAX / nmemb < size) {
|
||||||
|
|||||||
+37
-26
@@ -1,6 +1,6 @@
|
|||||||
/* Micro "rsync" implementation.
|
/* Micro "rsync" implementation.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2011-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2011-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,6 +15,13 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file rsync.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2011-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h> /* AT_* macros */
|
#include <fcntl.h> /* AT_* macros */
|
||||||
#include <stdlib.h> /* NULL, free() */
|
#include <stdlib.h> /* NULL, free() */
|
||||||
@@ -34,31 +41,31 @@ static int set_mtime(char *fn, struct stat *st);
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rsync - Synchronize contents and optionally remove non-existing backups
|
* Synchronize contents and optionally remove non-existing backups
|
||||||
* @src: Source directory
|
* @param src Source directory
|
||||||
* @dst: Destination directory
|
* @param dst Destination directory
|
||||||
* @opt: An option mask of %LITE_FOPT_RSYNC_DELETE, %LITE_FOPT_KEEP_MTIME
|
* @param opt An option mask of ::LITE_FOPT_RSYNC_DELETE, ::LITE_FOPT_KEEP_MTIME
|
||||||
* @filter: Optional filtering function for source directory.
|
* @param 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
|
||||||
* In fact, it is not even a true rsync since it copies all files from @src
|
* only. In fact, it is not even a true rsync since it copies all files
|
||||||
* to @dst. The @delete option is useful for creating backups, when set all
|
* from @p src to @p dst. The ::LITE_FOPT_RSYNC_DELETE @p opt flag is
|
||||||
* files removed from src since last backup are pruned from the destination
|
* useful for creating backups, when set all files removed from src
|
||||||
* (backup) directory.
|
* since last backup are pruned from the destination (backup) directory.
|
||||||
*
|
*
|
||||||
* The @opt parameter to rsync() is an option mask for the most common
|
* The @p opt parameter to rsync() is an option mask for the most common
|
||||||
* rsync(1) options. Previously this argument was called @delete and
|
* rsync(1) options. Previously this argument was called @p delete and
|
||||||
* to maintain backwards compatibility the value 1 is reserved:
|
* 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_RSYNC_DELETE: Prune files from @p dst that no longer exist in @p src.
|
||||||
* %LITE_FOPT_KEEP_MTIME: Preserve modification time
|
* %LITE_FOPT_KEEP_MTIME: Preserve modification time
|
||||||
*
|
*
|
||||||
* The filter callback, @filter, if provided, is used to determine what
|
* The filter callback, @p filter, if provided, is used to determine
|
||||||
* files to include from the source directory when backing up. If a
|
* what files to include from the source directory when backing up. If
|
||||||
* file is to be skipped the callback should simply return zero.
|
* 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 @a errno set on error.
|
||||||
*/
|
*/
|
||||||
int rsync(char *src, char *dst, int opt, int (*filter)(const char *file))
|
int rsync(char *src, char *dst, int opt, int (*filter)(const char *file))
|
||||||
{
|
{
|
||||||
@@ -70,7 +77,9 @@ int rsync(char *src, char *dst, int opt, int (*filter)(const char *file))
|
|||||||
char **files; /* Array of file names. */
|
char **files; /* Array of file names. */
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if (!fisdir(dst))
|
errno = 0;
|
||||||
|
|
||||||
|
if (stat(dst, &st) && fisslashdir(dst))
|
||||||
makedir(dst, 0755);
|
makedir(dst, 0755);
|
||||||
|
|
||||||
if (!fisdir(src)) {
|
if (!fisdir(src)) {
|
||||||
@@ -78,9 +87,9 @@ int rsync(char *src, char *dst, int opt, int (*filter)(const char *file))
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (copy(src, dst, keep_mtim))
|
if (copy(src, dst, keep_mtim))
|
||||||
result++;
|
return 1;
|
||||||
|
|
||||||
return errno;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy dir as well? */
|
/* Copy dir as well? */
|
||||||
@@ -107,20 +116,22 @@ int rsync(char *src, char *dst, int opt, 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;
|
struct stat sb;
|
||||||
|
|
||||||
strcat(source, "/");
|
strcat(source, "/");
|
||||||
if (stat(source, &st))
|
if (stat(source, &sb)) {
|
||||||
return 1;
|
result++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (mdir(dst2, sizeof(dst2), dst, files[i], &st)) {
|
if (mdir(dst2, sizeof(dst2), dst, files[i], &sb)) {
|
||||||
result++;
|
result++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
rsync(source, dst2, opt, filter);
|
rsync(source, dst2, opt, filter);
|
||||||
if (keep_mtim)
|
if (keep_mtim)
|
||||||
set_mtime(dst2, &st);
|
set_mtime(dst2, &sb);
|
||||||
|
|
||||||
continue; /* Next file/dir in @src to copy... */
|
continue; /* Next file/dir in @src to copy... */
|
||||||
}
|
}
|
||||||
|
|||||||
+93
@@ -0,0 +1,93 @@
|
|||||||
|
/* Run a command in the background: fork() + usleep() + execvp()
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file runbg.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2023
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run command in the background
|
||||||
|
* @param cmd NULL terminated list of command and optional arguments
|
||||||
|
* @param delay Microseconds after fork() to wait before calling cmd
|
||||||
|
*
|
||||||
|
* This function forks to run the given command @p cmd in the background.
|
||||||
|
* To ensure there are no lingering zombies the function actuall forks
|
||||||
|
* twice, and also calls setsid(), before it calls usleep() with the @p
|
||||||
|
* delay argument. The command @p cmd is handed over to execvp().
|
||||||
|
*
|
||||||
|
* Since it runs in the background it is not possible to get the return
|
||||||
|
* code of the command.
|
||||||
|
*
|
||||||
|
* @returns on successful (first) fork(), this function returns POSIX
|
||||||
|
* OK(0), otherwise -1 and @a errno is set to indicate the error.
|
||||||
|
*/
|
||||||
|
int runbg(char *const cmd[], int delay)
|
||||||
|
{
|
||||||
|
int pid = fork();
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (!pid) {
|
||||||
|
int fd, maxfd;
|
||||||
|
|
||||||
|
if (setsid() == -1)
|
||||||
|
_exit(errno);
|
||||||
|
|
||||||
|
/* reparent to init */
|
||||||
|
pid = fork();
|
||||||
|
if (pid == -1)
|
||||||
|
_exit(errno);
|
||||||
|
if (pid > 0)
|
||||||
|
_exit(0);
|
||||||
|
|
||||||
|
maxfd = sysconf(_SC_OPEN_MAX);
|
||||||
|
if (maxfd == -1)
|
||||||
|
maxfd = 8192;
|
||||||
|
for (fd = 0; fd < maxfd; fd++)
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
usleep(delay);
|
||||||
|
_exit(execvp(cmd[0], cmd));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pid == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (waitpid(pid, &rc, 0) == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (WIFEXITED(rc)) {
|
||||||
|
errno = WEXITSTATUS(rc);
|
||||||
|
if (errno)
|
||||||
|
rc = -1;
|
||||||
|
else
|
||||||
|
rc = 0;
|
||||||
|
} else if (WIFSIGNALED(rc)) {
|
||||||
|
errno = EINTR;
|
||||||
|
rc = -1;
|
||||||
|
} else
|
||||||
|
rc = -1;
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
+15
-3
@@ -24,13 +24,20 @@
|
|||||||
* ==========================================================================
|
* ==========================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file strdupa.h
|
||||||
|
* @author William Ahern
|
||||||
|
* @date 2009
|
||||||
|
* @copyright MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LITE_STRDUPA_H
|
#ifndef LIBITE_STRDUPA_H
|
||||||
#define LITE_STRDUPA_H
|
#define LIBITE_STRDUPA_H
|
||||||
|
|
||||||
#if !defined(HAVE_STRDUPA)
|
#if !defined(HAVE_STRDUPA)
|
||||||
#if defined(strdupa)
|
#if defined(strdupa)
|
||||||
@@ -43,6 +50,11 @@ extern "C"
|
|||||||
#include <stddef.h> /* size_t */
|
#include <stddef.h> /* size_t */
|
||||||
#include <string.h> /* memcpy(3) strlen(3) */
|
#include <string.h> /* memcpy(3) strlen(3) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Duplicate string on stack.
|
||||||
|
* @param src string to duplicate
|
||||||
|
* @returns the result of memcpy(3)
|
||||||
|
*/
|
||||||
#define strdupa(src) (__extension__ ({ \
|
#define strdupa(src) (__extension__ ({ \
|
||||||
size_t len_ = strlen(src); \
|
size_t len_ = strlen(src); \
|
||||||
char *dst_ = __builtin_alloca(len_ + 1); \
|
char *dst_ = __builtin_alloca(len_ + 1); \
|
||||||
@@ -55,7 +67,7 @@ extern "C"
|
|||||||
#endif /* __GNUC__ */
|
#endif /* __GNUC__ */
|
||||||
#endif /* !HAVE_STRDUPA */
|
#endif /* !HAVE_STRDUPA */
|
||||||
|
|
||||||
#endif /* LITE_STRDUPA_H */
|
#endif /* LIBITE_STRDUPA_H */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-6
@@ -16,16 +16,30 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file strlcat.c
|
||||||
|
* @author Todd C. Miller
|
||||||
|
* @date 1998, 2015
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifndef strlcat
|
#ifndef strlcat
|
||||||
/*
|
/**
|
||||||
* Appends src to string dst of size dsize (unlike strncat, dsize is the
|
* Safe version of strncat() from OpenBSD
|
||||||
* full size of dst, not space left). At most dsize-1 characters
|
* @param dst Destination string
|
||||||
* will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
|
* @param src Source string
|
||||||
* Returns strlen(src) + MIN(dsize, strlen(initial dst)).
|
* @param dsize Total maximum size of @p dst
|
||||||
* If retval >= dsize, truncation occurred.
|
*
|
||||||
|
* Appends @p src to string @p dst of size @p dsize (unlike strncat(),
|
||||||
|
* @p dsize is the full size of @p dst, not space left). At most
|
||||||
|
* dsize-1 characters will be copied. Always NUL terminates (unless
|
||||||
|
* dsize <= strlen(dst)).
|
||||||
|
*
|
||||||
|
* @returns strlen(src) + MIN(dsize, strlen(initial dst)).
|
||||||
|
* If retval >= dsize, truncation occurred.
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
strlcat(char *dst, const char *src, size_t dsize)
|
strlcat(char *dst, const char *src, size_t dsize)
|
||||||
|
|||||||
+19
-4
@@ -16,14 +16,29 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file strlcpy.c
|
||||||
|
* @author Todd C. Miller
|
||||||
|
* @date 1998, 2015
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifndef strlcpy
|
#ifndef strlcpy
|
||||||
/*
|
/**
|
||||||
* Copy string src to buffer dst of size dsize. At most dsize-1
|
* Safe version of strncpy() from OpenBSD
|
||||||
* chars will be copied. Always NUL terminates (unless dsize == 0).
|
* @param dst Destination string
|
||||||
* Returns strlen(src); if retval >= dsize, truncation occurred.
|
* @param src Source string
|
||||||
|
* @param dsize Total maximum size of @p dst
|
||||||
|
*
|
||||||
|
* This function copies string @p src to buffer @p dst of size @p dsize
|
||||||
|
* bytes. At most dsize-1 chars will be copied. Always NUL terminates
|
||||||
|
* (unless dsize==0).
|
||||||
|
*
|
||||||
|
* @returns strlen(src); if retval >= dsize, truncation occurred.
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
strlcpy(char *dst, const char *src, size_t dsize)
|
strlcpy(char *dst, const char *src, size_t dsize)
|
||||||
|
|||||||
+45
-12
@@ -1,6 +1,6 @@
|
|||||||
/* Collection of frog DNA
|
/* Collection of frog DNA
|
||||||
*
|
*
|
||||||
* Copyright (c) 2008-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2008-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -21,13 +21,20 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file strlite.h
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2008-2021
|
||||||
|
* @copyright MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LITE_STRING_H_
|
#ifndef LIBITE_STRING_H_
|
||||||
#define LITE_STRING_H_
|
#define LIBITE_STRING_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 <string.h>
|
#include <string.h>
|
||||||
@@ -38,6 +45,7 @@ extern "C"
|
|||||||
#include "strnlen.h"
|
#include "strnlen.h"
|
||||||
|
|
||||||
#ifndef min
|
#ifndef min
|
||||||
|
/** Geneirc min() macro, if a < b => a, else b */
|
||||||
#define min(a,b) \
|
#define min(a,b) \
|
||||||
({ \
|
({ \
|
||||||
__typeof__ (a) _a = (a); \
|
__typeof__ (a) _a = (a); \
|
||||||
@@ -46,6 +54,7 @@ extern "C"
|
|||||||
})
|
})
|
||||||
#endif
|
#endif
|
||||||
#ifndef max
|
#ifndef max
|
||||||
|
/** Geneirc max() macro, if a > b => a, else b */
|
||||||
#define max(a,b) \
|
#define max(a,b) \
|
||||||
({ \
|
({ \
|
||||||
__typeof__ (a) _a = (a); \
|
__typeof__ (a) _a = (a); \
|
||||||
@@ -67,7 +76,13 @@ size_t strlcat (char *dst, const char *src, size_t siz);
|
|||||||
long long strtonum (const char *numstr, long long minval, long long maxval, const char **errstrp);
|
long long strtonum (const char *numstr, long long minval, long long maxval, const char **errstrp);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Convert string to natural number (0-2147483647), returns -1 on error. */
|
char *strtrim (char *str);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert string to natural number (0-2147483647)
|
||||||
|
* @param str string to convert to number.
|
||||||
|
* @returns -1 on error.
|
||||||
|
*/
|
||||||
static inline int atonum(const char *str)
|
static inline int atonum(const char *str)
|
||||||
{
|
{
|
||||||
int val = -1;
|
int val = -1;
|
||||||
@@ -82,13 +97,22 @@ static inline int atonum(const char *str)
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Validate string, non NULL and not zero length */
|
/**
|
||||||
static inline int string_valid(const char *s)
|
* Validate string, non NULL and not zero length
|
||||||
|
* @param str string to validate
|
||||||
|
* @returns @c TRUE(1) or @c FALSE(0).
|
||||||
|
*/
|
||||||
|
static inline int string_valid(const char *str)
|
||||||
{
|
{
|
||||||
return s && strlen(s);
|
return str && strlen(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Relaxed comparison, e.g., sys_string_match("small", "smaller") => TRUE */
|
/**
|
||||||
|
* Relaxed comparison, e.g., sys_string_match("small", "smaller") => TRUE
|
||||||
|
* @param a first string
|
||||||
|
* @param b second string
|
||||||
|
* @returns @c TRUE(1) or @c FALSE(0).
|
||||||
|
*/
|
||||||
static inline int string_match(const char *a, const char *b)
|
static inline int string_match(const char *a, const char *b)
|
||||||
{
|
{
|
||||||
size_t min = MIN(strlen(a), strlen(b));
|
size_t min = MIN(strlen(a), strlen(b));
|
||||||
@@ -96,21 +120,30 @@ static inline int string_match(const char *a, const char *b)
|
|||||||
return !strncasecmp(a, b, min);
|
return !strncasecmp(a, b, min);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Strict comparison, e.g., sys_string_match("small", "smaller") => FALSE */
|
/**
|
||||||
|
* Strict comparison, e.g., sys_string_match("small", "smaller") => FALSE
|
||||||
|
* @param a first string
|
||||||
|
* @param b second string
|
||||||
|
* @returns @c TRUE(1) or @c FALSE(0).
|
||||||
|
*/
|
||||||
static inline int string_compare(const char *a, const char *b)
|
static inline int string_compare(const char *a, const char *b)
|
||||||
{
|
{
|
||||||
return strlen(a) == strlen(b) && !strcmp(a, b);
|
return strlen(a) == strlen(b) && !strcmp(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Strict comparison, like sys_string_compare(), but case insensitive,
|
/**
|
||||||
|
* Strict comparison, like sys_string_compare(), but case insensitive,
|
||||||
* e.g., sys_string_match("small", "SmAlL") => TRUE
|
* e.g., sys_string_match("small", "SmAlL") => TRUE
|
||||||
|
* @param a first string
|
||||||
|
* @param b second string
|
||||||
|
* @returns @c TRUE(1) or @c FALSE(0).
|
||||||
*/
|
*/
|
||||||
static inline int string_case_compare(const char *a, const char *b)
|
static inline int string_case_compare(const char *a, const char *b)
|
||||||
{
|
{
|
||||||
return strlen (a) == strlen (b) && !strcasecmp (a, b);
|
return strlen(a) == strlen(b) && !strcasecmp(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* LITE_STRING_H_ */
|
#endif /* LIBITE_STRING_H_ */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-20
@@ -1,6 +1,6 @@
|
|||||||
/* Simple string matcher function, finds partial matches.
|
/* Simple string matcher function, finds partial matches.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,24 +15,30 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file strmatch.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2009-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* strnmatch - Finds matching strings from a finite list
|
* Finds matching strings from a finite list
|
||||||
* @str: String to look for
|
* @param str String to look for
|
||||||
* @list: List of strings to search.
|
* @param list List of strings to search.
|
||||||
* @num: Number of entries in @list.
|
* @param num Number of entries in @p list.
|
||||||
*
|
*
|
||||||
* This function searches the @list of strings for @str. If a (partial) match
|
* This function searches the @p list of strings for @p str. If a
|
||||||
* is found it returns the index in the @list.
|
* (partial) match is found it returns the index in the @p list.
|
||||||
*
|
*
|
||||||
* Very similar in function to strmatch(), but works for sets of strings that
|
* Very similar in function to strmatch(), but works for sets of strings
|
||||||
* are not %NULL terminated.
|
* that are not @c NUL terminated.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns -1 on error, otherwise the index to the matching string.
|
||||||
* -1 on error, otherwise the index to the matching string.
|
|
||||||
*/
|
*/
|
||||||
int strnmatch(const char *str, const char **list, size_t num)
|
int strnmatch(const char *str, const char **list, size_t num)
|
||||||
{
|
{
|
||||||
@@ -53,18 +59,17 @@ int strnmatch(const char *str, const char **list, size_t num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* strmatch - Finds matching strings from a list
|
* Finds matching strings from a list
|
||||||
* @str: String to look for
|
* @param str String to look for.
|
||||||
* @list: %NULL terminated list of strings to search.
|
* @param list NUL terminated list of strings to search.
|
||||||
*
|
*
|
||||||
* This function searches the @list of strings for @str. If a (partial) match
|
* This function searches the @p list of strings for @p str. If a
|
||||||
* is found it returns the index in the @list.
|
* (partial) match is found it returns the index in the @p list.
|
||||||
*
|
*
|
||||||
* Please note, the @list MUST be terminated by a %NULL element. If that is
|
* Please note, the @p list MUST be terminated by a NUL element. If
|
||||||
* not possible for you, we recommend using strnmatch() instead.
|
* that is not possible, we recommend using strnmatch() instead.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns -1 on error, otherwise the index to the matching string.
|
||||||
* -1 on error, otherwise the index to the matching string.
|
|
||||||
*/
|
*/
|
||||||
int strmatch(const char *str, const char **list)
|
int strmatch(const char *str, const char **list)
|
||||||
{
|
{
|
||||||
|
|||||||
+16
-3
@@ -24,13 +24,20 @@
|
|||||||
* ==========================================================================
|
* ==========================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file strndupa.h
|
||||||
|
* @author William Ahern
|
||||||
|
* @date 2009
|
||||||
|
* @copyright MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LITE_STRNDUPA_H_
|
#ifndef LIBITE_STRNDUPA_H_
|
||||||
#define LITE_STRNDUPA_H_
|
#define LIBITE_STRNDUPA_H_
|
||||||
|
|
||||||
#if !defined(HAVE_STRNDUPA)
|
#if !defined(HAVE_STRNDUPA)
|
||||||
#if defined(strndupa)
|
#if defined(strndupa)
|
||||||
@@ -44,6 +51,12 @@ extern "C"
|
|||||||
#include <string.h> /* memcpy(3) */
|
#include <string.h> /* memcpy(3) */
|
||||||
#include "strnlen.h"
|
#include "strnlen.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Duplicate part of string on stack
|
||||||
|
* @param src string to duplicate
|
||||||
|
* @param lim number of bytes to dupliate
|
||||||
|
* @returns the result of memcpy(3)
|
||||||
|
*/
|
||||||
#define strndupa(src, lim) (__extension__ ({ \
|
#define strndupa(src, lim) (__extension__ ({ \
|
||||||
size_t len_ = strnlen(src, lim); \
|
size_t len_ = strnlen(src, lim); \
|
||||||
char *dst_ = __builtin_alloca(len_ + 1); \
|
char *dst_ = __builtin_alloca(len_ + 1); \
|
||||||
@@ -56,7 +69,7 @@ extern "C"
|
|||||||
#endif /* __GNUC__ */
|
#endif /* __GNUC__ */
|
||||||
#endif /* !HAVE_STRNDUPA */
|
#endif /* !HAVE_STRNDUPA */
|
||||||
|
|
||||||
#endif /* GNU_STRING_STRNDUPA_H */
|
#endif /* LIBITE_STRNDUPA_H */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-6
@@ -1,6 +1,6 @@
|
|||||||
/* strnlen.h - Re-implementation of GLIBC strnlen()
|
/* strnlen.h - Re-implementation of GLIBC strnlen()
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2016-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,13 +15,20 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file strnlen.h
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2016-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LITE_STRNLEN_H_
|
#ifndef LIBITE_STRNLEN_H_
|
||||||
#define LITE_STRNLEN_H_
|
#define LIBITE_STRNLEN_H_
|
||||||
|
|
||||||
#if !defined(HAVE_STRNLEN)
|
#if !defined(HAVE_STRNLEN)
|
||||||
#if defined(strnlen)
|
#if defined(strnlen)
|
||||||
@@ -32,20 +39,26 @@ extern "C"
|
|||||||
#if !HAVE_STRNLEN
|
#if !HAVE_STRNLEN
|
||||||
#include <stddef.h> /* size_t */
|
#include <stddef.h> /* size_t */
|
||||||
|
|
||||||
#define strnlen(str, lim) xstrnlen(str, lim)
|
#define strnlen(str, lim) xstrnlen(str, lim) /**< Wrapper for xstrnlen() */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reimplementation of GLIBC strnlen()
|
||||||
|
* @param str string to return length of
|
||||||
|
* @param lim max number of bytes to read
|
||||||
|
* @returns length of @p str in bytes, but at most @lim bytes.
|
||||||
|
*/
|
||||||
static inline size_t xstrnlen(const char *str, size_t lim)
|
static inline size_t xstrnlen(const char *str, size_t lim)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
while (str[i] && i < lim)
|
while (i < lim && str[i])
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* LITE_STRNLEN_H_ */
|
#endif /* LIBITE_STRNLEN_H_ */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
+42
-6
@@ -17,24 +17,60 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file strtonum.c
|
||||||
|
* @author Ted Unangst
|
||||||
|
* @author Todd Miller
|
||||||
|
* @date 2004
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifndef strtonum
|
#ifndef strtonum
|
||||||
#define INVALID 1
|
#define INVALID 1 /**< internal */
|
||||||
#define TOOSMALL 2
|
#define TOOSMALL 2 /**< internal */
|
||||||
#define TOOLARGE 3
|
#define TOOLARGE 3 /**< internal */
|
||||||
|
|
||||||
#ifndef LLONG_MAX
|
#ifndef LLONG_MAX
|
||||||
# define LLONG_MAX 0x7fffffffffffffffLL
|
# define LLONG_MAX 0x7fffffffffffffffLL /**< internal */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LLONG_MIN
|
#ifndef LLONG_MIN
|
||||||
# define LLONG_MIN (-0x7fffffffffffffffLL - 1)
|
# define LLONG_MIN (-0x7fffffffffffffffLL - 1) /**< internal */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reliably convert string value to an integer
|
||||||
|
* @param numstr String to convert to a number
|
||||||
|
* @param minval Lower bound to check number against
|
||||||
|
* @param maxval Upper bound to check number against
|
||||||
|
* @param errstrp Pointer to error string
|
||||||
|
*
|
||||||
|
* This function converts the string in @p numstr to a long long value.
|
||||||
|
* The function was designed to facilitate safe, robust programming and
|
||||||
|
* overcome the shortcomings of the atoi(3) and strtol(3) family of
|
||||||
|
* interfaces.
|
||||||
|
*
|
||||||
|
* The string may begin with an arbitrary amount of whitespace (as
|
||||||
|
* determined by isspace(3)) followed by a single optional ‘+’ or ‘-’
|
||||||
|
* sign.
|
||||||
|
*
|
||||||
|
* The remainder of the string is converted to a long long value
|
||||||
|
* according to base 10.
|
||||||
|
*
|
||||||
|
* The value obtained is then checked against the provided @p minval and
|
||||||
|
* @p maxval bounds. If @p errstrp is non-NULL, strtonum() stores an
|
||||||
|
* error string in @p *errstrp indicating the failure.
|
||||||
|
*
|
||||||
|
* @returns The result of the conversion, unless the value would exceed
|
||||||
|
* the provided bounds or is invalid. On error, 0 is returned, @a errno
|
||||||
|
* is set, and @p errstrp points to an error message. @p *errstr* is set
|
||||||
|
* to @c NULL on success; this fact can be used to differentiate a
|
||||||
|
* successful return of 0 from an error.
|
||||||
|
*/
|
||||||
long long
|
long long
|
||||||
strtonum(const char *numstr, long long minval, long long maxval,
|
strtonum(const char *numstr, long long minval, long long maxval,
|
||||||
const char **errstrp)
|
const char **errstrp)
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/* Trim a string from whitespace
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Mattias Walström <lazzer@gmail.com>
|
||||||
|
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file strtrim.c
|
||||||
|
* @author Mattias Walström
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2014,2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "lite.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strip leading and trailing whitespace from a string
|
||||||
|
* @param str The string to trim
|
||||||
|
*
|
||||||
|
* Trims a string from any leading and trailing white-space, returns the
|
||||||
|
* trimmed result in the same buffer.
|
||||||
|
*
|
||||||
|
* @returns If @p str is a valid, non-NULL string this function returns
|
||||||
|
* the same string stripped from whitespace. This function only returns
|
||||||
|
* @c NULL if @p str itself is @c NULL.
|
||||||
|
*/
|
||||||
|
char *strtrim(char *str)
|
||||||
|
{
|
||||||
|
char *start, *end;
|
||||||
|
|
||||||
|
if (!str) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
start = str;
|
||||||
|
while (isspace(*start))
|
||||||
|
start++;
|
||||||
|
|
||||||
|
if (*start == 0) {
|
||||||
|
str[0] = 0;
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
end = start + strlen(start) - 1;
|
||||||
|
while (end > start && isspace(*end))
|
||||||
|
end--;
|
||||||
|
*(++end) = 0;
|
||||||
|
|
||||||
|
memmove(str, start, end - start + 1);
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
/* Formatted system() which returns actual return status of command
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file systemf.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like system(), but takes a formatted string as argument.
|
||||||
|
* @param fmt printf style format list to command to run
|
||||||
|
*
|
||||||
|
* This system() wrapper greatly simplifies operations that usually
|
||||||
|
* consist of composing a command from parts into a dynamic buffer
|
||||||
|
* before calling it. The return value from system() is also parsed,
|
||||||
|
* checking for proper exit and signals.
|
||||||
|
*
|
||||||
|
* @returns If the command exits normally, the return code of the command
|
||||||
|
* is returned. Otherwise, if the command is signalled, the return code
|
||||||
|
* is -1 and @a errno is set to @c EINTR.
|
||||||
|
*/
|
||||||
|
int systemf(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *cmd;
|
||||||
|
int len;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
cmd = alloca(++len);
|
||||||
|
if (!cmd) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(cmd, len, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
rc = system(cmd);
|
||||||
|
if (rc == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (WIFEXITED(rc)) {
|
||||||
|
errno = 0;
|
||||||
|
rc = WEXITSTATUS(rc);
|
||||||
|
} else if (WIFSIGNALED(rc)) {
|
||||||
|
errno = EINTR;
|
||||||
|
rc = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
+54
-28
@@ -1,6 +1,6 @@
|
|||||||
/* Poor mans telnet expect in C.
|
/* Poor mans telnet expect in C.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2010-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,6 +15,13 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file telnet.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2010-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -33,18 +40,26 @@
|
|||||||
# define TELL(fmt, args...)
|
# define TELL(fmt, args...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** @private for internal use only */
|
||||||
struct sdbuf {
|
struct sdbuf {
|
||||||
int sd;
|
int sd;
|
||||||
char *buf;
|
char *buf;
|
||||||
} sdbuf;
|
};
|
||||||
|
|
||||||
/* Open telnet connection to @addr:@port and connect. */
|
/**
|
||||||
|
* Open telnet connection to addr:port and connect.
|
||||||
|
* @param addr Integer encoded IPv4 address in network byte order
|
||||||
|
* @param port Internet port number in network byte order
|
||||||
|
*
|
||||||
|
* @returns An @ref sdbuf_t socket buffer context.
|
||||||
|
*/
|
||||||
sdbuf_t *telnet_open(int addr, short port)
|
sdbuf_t *telnet_open(int addr, short port)
|
||||||
{
|
{
|
||||||
struct sockaddr_in *sin;
|
struct sockaddr_in *sin;
|
||||||
struct sockaddr s;
|
struct sockaddr s;
|
||||||
sdbuf_t *ctx;
|
sdbuf_t *ctx;
|
||||||
int saved_errno;
|
int saved;
|
||||||
|
int retries = 10;
|
||||||
|
|
||||||
ctx = (sdbuf_t *)malloc(sizeof(sdbuf_t));
|
ctx = (sdbuf_t *)malloc(sizeof(sdbuf_t));
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
@@ -61,24 +76,30 @@ sdbuf_t *telnet_open(int addr, short port)
|
|||||||
|
|
||||||
ctx->sd = socket(PF_INET, SOCK_STREAM, 0);
|
ctx->sd = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
if (-1 == ctx->sd) {
|
if (-1 == ctx->sd) {
|
||||||
saved_errno = errno;
|
saved = errno;
|
||||||
// perror ("Failed creating socket");
|
// perror ("Failed creating socket");
|
||||||
free(ctx->buf);
|
free(ctx->buf);
|
||||||
free(ctx);
|
free(ctx);
|
||||||
|
|
||||||
errno = saved_errno;
|
errno = saved;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retry:
|
||||||
sin = (struct sockaddr_in *)&s;
|
sin = (struct sockaddr_in *)&s;
|
||||||
sin->sin_family = AF_INET;
|
sin->sin_family = AF_INET;
|
||||||
sin->sin_port = port;
|
sin->sin_port = port;
|
||||||
sin->sin_addr.s_addr = addr;
|
sin->sin_addr.s_addr = addr;
|
||||||
if (-1 == connect(ctx->sd, &s, sizeof(s))) {
|
if (-1 == connect(ctx->sd, &s, sizeof(s))) {
|
||||||
saved_errno = errno;
|
if (ETIMEDOUT == errno && retries-- > 0) {
|
||||||
|
sleep(1);
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
|
|
||||||
|
saved = errno;
|
||||||
// perror ("Cannot connect to telnet daemon");
|
// perror ("Cannot connect to telnet daemon");
|
||||||
telnet_close(ctx);
|
telnet_close(ctx);
|
||||||
errno = saved_errno;
|
errno = saved;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -86,6 +107,12 @@ sdbuf_t *telnet_open(int addr, short port)
|
|||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close a telnet session previously opened with telnet_open()
|
||||||
|
* @param ctx An @ref sdbuf_t socket buffer context
|
||||||
|
*
|
||||||
|
* @returns Always returns POSIX OK(0).
|
||||||
|
*/
|
||||||
int telnet_close(sdbuf_t *ctx)
|
int telnet_close(sdbuf_t *ctx)
|
||||||
{
|
{
|
||||||
free(ctx->buf);
|
free(ctx->buf);
|
||||||
@@ -130,20 +157,19 @@ static int wait_substr(sdbuf_t *ctx, char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* telnet_expect - Poor man's telnet expect
|
* Poor man's telnet expect
|
||||||
* @ctx: Telnet session context from telnet_open()
|
* @param ctx Telnet session context from telnet_open()
|
||||||
* @script: %NULL terminated list of expect and response strings
|
* @param script @c NULL terminated list of expect and response strings
|
||||||
* @output: Optional output from session
|
* @param output Optional output from session
|
||||||
*
|
*
|
||||||
* Issues @script sequence on telnet session specified in @ctx, with
|
* Issues @p script sequence on telnet session specified in @p ctx, with
|
||||||
* optional @output from session.
|
* optional @p output from session.
|
||||||
*
|
*
|
||||||
* The @script consists of strings of expect and response pairs. For
|
* The @p script consists of strings of expect and response pairs. For
|
||||||
* example, expect "ogin: " followed by response "root\n", expect
|
* example, expect "ogin: " followed by response "root\n", expect
|
||||||
* "assword: "with response "secret\n", concluded by %NULL.
|
* "assword: "with response "secret\n", concluded by @c NULL.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns POSIX OK(0) or non-zero on error.
|
||||||
* POSIX OK(0) or non-zero on error.
|
|
||||||
*/
|
*/
|
||||||
int telnet_expect(sdbuf_t *ctx, char *script[], FILE *output)
|
int telnet_expect(sdbuf_t *ctx, char *script[], FILE *output)
|
||||||
{
|
{
|
||||||
@@ -251,20 +277,20 @@ int telnet_expect(sdbuf_t *ctx, char *script[], FILE *output)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* telnet_session - Very simple expect-like implementation for telnet.
|
* Very simple expect-like implementation for telnet.
|
||||||
* @addr: Must be in network byte order, use htonl().
|
* @param addr Integer encoded IPv4 address, in network byte order, use htonl().
|
||||||
* @port: IP port to connect to, use htons().
|
* @param port Internet port to connect to, in network byte order, use htons().
|
||||||
* @script: Expect like script of paired 'expect', 'response' strings.
|
* @param script Expect like script of paired 'expect', 'response' strings.
|
||||||
* @output: A &FILE pointer to a tmpfile() for output from the last command.
|
* @param output A FILE pointer to a tempfile() for output from the last command.
|
||||||
*
|
*
|
||||||
* This is a very simple expect-like implementation for querying and
|
* This is a very simple expect-like implementation for querying and
|
||||||
* operating daemons remotely over telnet.
|
* operating daemons remotely over telnet.
|
||||||
*
|
*
|
||||||
* The @script is a query-response type of list of strings leading up to
|
* The @p script is a query-response type of list of strings leading up
|
||||||
* a final command, which output is then written to the given @output file.
|
* to a final command, which output is then written to the given @p
|
||||||
|
* output file.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns POSIX OK(0), or non-zero with @a errno set on error.
|
||||||
* POSIX OK(0), or non-zero with errno set on error.
|
|
||||||
*/
|
*/
|
||||||
int telnet_session(int addr, short port, char *script[], FILE *output)
|
int telnet_session(int addr, short port, char *script[], FILE *output)
|
||||||
{
|
{
|
||||||
|
|||||||
+37
-10
@@ -1,6 +1,6 @@
|
|||||||
/* A secure tmpfile() replacement.
|
/* A secure tmpfile() replacement.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2015-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,23 +15,46 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file tempfile.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2015-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <fcntl.h> /* O_TMPFILE requires -D_GNU_SOURCE */
|
#include <fcntl.h> /* O_TMPFILE requires -D_GNU_SOURCE */
|
||||||
#include <stdio.h> /* fdopen() */
|
#include <stdio.h> /* fdopen() */
|
||||||
|
#include <stdlib.h> /* mkostemp() */
|
||||||
#include <sys/stat.h> /* umask() */
|
#include <sys/stat.h> /* umask() */
|
||||||
|
|
||||||
|
static FILE *fallback(void)
|
||||||
|
{
|
||||||
|
char nm[15] = _PATH_TMP "XXXXXXXX";
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = mkostemp(nm, O_CLOEXEC);
|
||||||
|
if (-1 == fd)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return fdopen(fd, "w+");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tempfile - A secure tmpfile() replacement
|
* A secure tmpfile() replacement
|
||||||
*
|
*
|
||||||
* This is the secure replacement for tmpfile() that does not exist in
|
* This is the secure replacement for tmpfile() that does not exist in
|
||||||
* GLIBC. The function uses the Linux specific %O_TMPFILE and %O_EXCL
|
* GLIBC. It uses the Linux specific @c O_TMPFILE and @c O_EXCL to hide
|
||||||
* for security. When the %FILE is fclose()'ed the file contents is
|
* the filename. When the @c FILE is fclose()'ed, the file contents is
|
||||||
* lost. The file is hidden in the %_PATH_TMP directory on the system.
|
* lost. The file is hidden in the @c _PATH_TMP ("/tmp") directory in
|
||||||
|
* the system.
|
||||||
*
|
*
|
||||||
* This function requires Linux 3.11, or later, due to %O_TMPFILE.
|
* This function requires Linux 3.11, or later, due to @c O_TMPFILE.
|
||||||
|
* Not all file systems support hidden inodes, in which case this
|
||||||
|
* function defaults to call tmpfile() as a fallback.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns An open @c FILE pointer, or @c NULL on error.
|
||||||
* An open %FILE pointer, or %NULL on error.
|
|
||||||
*/
|
*/
|
||||||
FILE *tempfile(void)
|
FILE *tempfile(void)
|
||||||
{
|
{
|
||||||
@@ -42,12 +65,16 @@ FILE *tempfile(void)
|
|||||||
oldmask = umask(0077);
|
oldmask = umask(0077);
|
||||||
fd = open(_PATH_TMP, O_TMPFILE | O_RDWR | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR);
|
fd = open(_PATH_TMP, O_TMPFILE | O_RDWR | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR);
|
||||||
umask(oldmask);
|
umask(oldmask);
|
||||||
if (-1 == fd)
|
if (-1 == fd) {
|
||||||
|
if (errno == EOPNOTSUPP)
|
||||||
|
return fallback();
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return fdopen(fd, "w+");
|
return fdopen(fd, "w+");
|
||||||
#else
|
#else
|
||||||
return tmpfile(); /* Fallback on older GLIBC/Linux and actual UNIX systems */
|
return fallback();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/* Formatted touch()
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file touchf.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "lite.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like touch() but with formatted string support
|
||||||
|
* @param fmt Formatted string to be composed into a pathname
|
||||||
|
*
|
||||||
|
* This is a wrapper for the touch() function in lite.h, lessening the
|
||||||
|
* burden of having to compose the filename from parts in a seprate
|
||||||
|
* buffer.
|
||||||
|
*
|
||||||
|
* @returns Upon successful completion touchf() returns POSIX OK(0),
|
||||||
|
* otherwise, -1 is returned and @a errno is set to indicate error.
|
||||||
|
*/
|
||||||
|
int touchf(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *file;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
file = alloca(len + 1);
|
||||||
|
if (!file) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(file, len + 1, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return touch(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
+6
-1
@@ -32,7 +32,12 @@ extern "C"
|
|||||||
#ifndef _SYS_TREE_H_
|
#ifndef _SYS_TREE_H_
|
||||||
#define _SYS_TREE_H_
|
#define _SYS_TREE_H_
|
||||||
|
|
||||||
/*
|
/**
|
||||||
|
* @file tree.h
|
||||||
|
* @author Niels Provos
|
||||||
|
* @date 2002
|
||||||
|
* @copyright 2-clause BSD License
|
||||||
|
*
|
||||||
* This file defines data structures for different types of trees:
|
* This file defines data structures for different types of trees:
|
||||||
* splay trees and red-black trees.
|
* splay trees and red-black trees.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/* Formatted truncate()
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file truncatef.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Truncate a file based on the formatted string
|
||||||
|
* @param length Size in bytes to truncate file to, zero to empty it
|
||||||
|
* @param fmt Formatted string to be composed into a pathname
|
||||||
|
*
|
||||||
|
* This is an extension to the truncate() family, lessening the burden
|
||||||
|
* of having to compose the filename from parts in a seprate buffer.
|
||||||
|
*
|
||||||
|
* @returns Upon successful completion truncate() returns POSIX OK(0),
|
||||||
|
* otherwise, -1 is returned and @a errno is set to indicate error.
|
||||||
|
*/
|
||||||
|
int truncatef(off_t length, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *file;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
file = alloca(len + 1);
|
||||||
|
if (!file) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(file, len + 1, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return truncate(file, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
+18
-5
@@ -1,6 +1,6 @@
|
|||||||
/* C implementation of UNIX which(1)
|
/* C implementation of UNIX which(1)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2017-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,6 +15,13 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file which.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2017-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h> /* snprintf() */
|
#include <stdio.h> /* snprintf() */
|
||||||
@@ -38,8 +45,11 @@ static char *strip_args(char *path)
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Like which(1), returns a malloc'ed path to cmd on success, or NULL
|
* Like which(1), or `command -v foo`
|
||||||
|
* @param cmd Command to look for in $PATH
|
||||||
|
*
|
||||||
|
* @returns A malloc()'ed path to @a cmd on success, or @c NULL.
|
||||||
*/
|
*/
|
||||||
char *which(const char *cmd)
|
char *which(const char *cmd)
|
||||||
{
|
{
|
||||||
@@ -103,8 +113,11 @@ char *which(const char *cmd)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Like which(), above, but only answers TRUE(1)/FALSE(0)
|
* Predicate variant of which()
|
||||||
|
* @param cmd Command to look for in $PATH
|
||||||
|
*
|
||||||
|
* @returns @c TRUE(1) or @c FALSE(0) if @p cmd exists in $PATH.
|
||||||
*/
|
*/
|
||||||
int whichp(const char *cmd)
|
int whichp(const char *cmd)
|
||||||
{
|
{
|
||||||
|
|||||||
+11
-5
@@ -1,6 +1,6 @@
|
|||||||
/* Safe yes-or-no with prompt
|
/* Safe yes-or-no with prompt
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009-2020 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2009-2021 Joachim Wiberg <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -15,6 +15,13 @@
|
|||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file yorn.c
|
||||||
|
* @author Joachim Wiberg
|
||||||
|
* @date 2009-2021
|
||||||
|
* @copyright ISC License
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdio_ext.h> /* __fpurge() */
|
#include <stdio_ext.h> /* __fpurge() */
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@@ -56,14 +63,13 @@ static char rawgetch(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* yorn - Pose a a Yes or No question and return answer
|
* Pose a a Yes or No question and return answer
|
||||||
* @fmt: Standard printf() style argument(s).
|
* @param fmt Standard printf() style argument(s).
|
||||||
*
|
*
|
||||||
* This function prints the given question on screen, waits for user
|
* This function prints the given question on screen, waits for user
|
||||||
* input in the form of yes or no.
|
* input in the form of yes or no.
|
||||||
*
|
*
|
||||||
* Returns:
|
* @returns TRUE(1) or FALSE(0). True if the answer is yes.
|
||||||
* True(1) or False(0). True if the answer is yes.
|
|
||||||
*/
|
*/
|
||||||
int yorn(const char *fmt, ...)
|
int yorn(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
*.o
|
||||||
|
*.log
|
||||||
|
*.trs
|
||||||
|
.deps/
|
||||||
|
/chomp
|
||||||
|
/copyfile
|
||||||
|
/dir
|
||||||
|
/fexist
|
||||||
|
/fisdir
|
||||||
|
/fopenf
|
||||||
|
/fsendfile
|
||||||
|
/lfile
|
||||||
|
/makepath
|
||||||
|
/pidfile
|
||||||
|
/printhdr
|
||||||
|
/progress
|
||||||
|
/rsync
|
||||||
|
/runbg
|
||||||
|
/str
|
||||||
|
/strmatch
|
||||||
|
/systemf
|
||||||
|
/tempfile
|
||||||
|
/touch
|
||||||
|
/tree
|
||||||
|
/which
|
||||||
|
/yorn
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
# Ignore warnings about unused result, in e.g. write()
|
||||||
|
AM_CFLAGS = -W -Wall -Wextra -Wno-unused-result
|
||||||
|
AM_CPPFLAGS = -D_GNU_SOURCE
|
||||||
|
AM_LDFLAGS = -L../src/ ../src/libite.la -static
|
||||||
|
|
||||||
|
EXTRA_DIST = check.h data/fexist/dir/.placeholder data/fexist/executable
|
||||||
|
EXTRA_DIST += data/fexist/link data/fexist/regular data/lfile/fstab
|
||||||
|
EXTRA_DIST += data/lfile/group data/lfile/passwd data/lfile/protocols
|
||||||
|
EXTRA_DIST += data/lfile/services data/which/executable
|
||||||
|
EXTRA_DIST += data/which/executable-link data/which/regular
|
||||||
|
|
||||||
|
CLEANFILES = *~ *.trs *.log
|
||||||
|
|
||||||
|
TESTS_ENVIRONMENT = ([ -d data ] || ln -sf $(srcdir)/data) &&
|
||||||
|
|
||||||
|
clean-local:
|
||||||
|
-find -type l -name data -exec rm {} \;
|
||||||
|
|
||||||
|
TESTS =
|
||||||
|
TESTS += chomp
|
||||||
|
TESTS += copyfile
|
||||||
|
TESTS += dir
|
||||||
|
TESTS += fexist
|
||||||
|
TESTS += fisdir
|
||||||
|
TESTS += fopenf
|
||||||
|
TESTS += fsendfile
|
||||||
|
TESTS += lfile
|
||||||
|
TESTS += makepath
|
||||||
|
TESTS += pidfile
|
||||||
|
TESTS += printhdr
|
||||||
|
TESTS += progress
|
||||||
|
TESTS += rsync
|
||||||
|
TESTS += runbg
|
||||||
|
TESTS += str
|
||||||
|
TESTS += strmatch
|
||||||
|
TESTS += systemf
|
||||||
|
TESTS += touch
|
||||||
|
TESTS += tempfile
|
||||||
|
TESTS += which
|
||||||
|
TESTS += yorn
|
||||||
|
|
||||||
|
check_PROGRAMS = $(TESTS)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef LITE_TESTS_CHECK_H_
|
#ifndef LIBLITE_TESTS_CHECK_H_
|
||||||
#define LITE_TESTS_CHECK_H_
|
#define LIBLITE_TESTS_CHECK_H_
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -78,4 +78,4 @@ static inline char *timespec2str(struct timespec *ts, char *buf, size_t len)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* LITE_TESTS_CHECK_H_ */
|
#endif /* LIBLITE_TESTS_CHECK_H_ */
|
||||||
File renamed without changes.
+131
@@ -0,0 +1,131 @@
|
|||||||
|
#include <err.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include "check.h"
|
||||||
|
|
||||||
|
#define ERR(fmt, args...) { printf(fmt ": %s\n", ##args, strerror(errno)); rc = 1; }
|
||||||
|
#define ERRX(fmt, args...) { printf(fmt "\n", ##args); rc = 1; }
|
||||||
|
|
||||||
|
static char *files[] = {
|
||||||
|
"/etc/passwd", "/tmp/mypwd", "/tmp/mypwd",
|
||||||
|
"/etc/passwd", "/tmp/", "/tmp/passwd",
|
||||||
|
"/etc/passwd", "/tmp", "/tmp/passwd",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
static int one_sz(const char *src, const char *dst, int sz)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
ssize_t len;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
len = copyfile(src, dst, sz, 0);
|
||||||
|
if (!len) {
|
||||||
|
ERR("failed copying any bytes from %s", src);
|
||||||
|
} else {
|
||||||
|
if (stat(dst, &st))
|
||||||
|
ERR("copied but cannot find destination %s", dst);
|
||||||
|
|
||||||
|
if (st.st_size != sz)
|
||||||
|
ERR("file only %ld bytes, expected %d", st.st_size, sz);
|
||||||
|
|
||||||
|
if (len != st.st_size)
|
||||||
|
ERRX("copied expected data %d, but copyfile() says %ld", sz, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int _sz()
|
||||||
|
{
|
||||||
|
const int sz = 32768;
|
||||||
|
|
||||||
|
return test(one_sz("/dev/zero", "/tmp/zeroes", sz), "copyfile(/dev/zero, %d)", sz);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fcopyfile_one(const char *src, const char *dst, const char *expected)
|
||||||
|
{
|
||||||
|
FILE *from, *to;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
from = fopen(src, "r");
|
||||||
|
to = fopen(dst, "w");
|
||||||
|
|
||||||
|
rc = fcopyfile(from, to);
|
||||||
|
|
||||||
|
if (from)
|
||||||
|
fclose(from);
|
||||||
|
if (to)
|
||||||
|
fclose(to);
|
||||||
|
|
||||||
|
if (rc) {
|
||||||
|
if (!src || !dst)
|
||||||
|
rc = 0; /* expected */
|
||||||
|
else if (fisdir(dst))
|
||||||
|
rc = 0; /* expected */
|
||||||
|
} else {
|
||||||
|
if (fexist(expected)) {
|
||||||
|
if (systemf("diff -q %s %s", src, expected))
|
||||||
|
rc = 1;
|
||||||
|
} else
|
||||||
|
ERR("cannot find %s", expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
erase(expected);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int _fcopyfile()
|
||||||
|
{
|
||||||
|
int i, rc = 0;
|
||||||
|
|
||||||
|
for (i = 0; files[i]; i += 3) {
|
||||||
|
char *src = files[i];
|
||||||
|
char *dst = files[i + 1];
|
||||||
|
char *res = files[i + 2];
|
||||||
|
|
||||||
|
rc += test(fcopyfile_one(src, dst, res), "fcopyfile(%s, %s)", src, dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* only checks success, correct file size verified by _sz() */
|
||||||
|
static int copyfile_one(const char *src, const char *dst, const char *expected)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = copyfile(src, dst, 0, 0);
|
||||||
|
if (!rc)
|
||||||
|
rc = 1;
|
||||||
|
else if (!fexist(expected))
|
||||||
|
rc = 1;
|
||||||
|
else
|
||||||
|
rc = 0;
|
||||||
|
|
||||||
|
erase(expected);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int _copyfile()
|
||||||
|
{
|
||||||
|
int i, rc = 0;
|
||||||
|
|
||||||
|
for (i = 0; files[i]; i += 3) {
|
||||||
|
char *src = files[i];
|
||||||
|
char *dst = files[i + 1];
|
||||||
|
char *res = files[i + 2];
|
||||||
|
|
||||||
|
rc += test(copyfile_one(src, dst, res), "copyfile(%s, %s)", src, dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
return _fcopyfile() ||
|
||||||
|
_copyfile() ||
|
||||||
|
_sz();
|
||||||
|
}
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
nonexistence
|
||||||
Whitespace-only changes.
Executable
Whitespace-only changes.
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
regular
|
||||||
Whitespace-only changes.
@@ -0,0 +1,3 @@
|
|||||||
|
UUID=xxxxxxxxxx / xfs defaults 0 1
|
||||||
|
/dev/sda1 /boot/efi vfat umask=0077 0 1
|
||||||
|
/dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
root:x:0:
|
||||||
|
daemon:x:1:
|
||||||
|
bin:x:2:
|
||||||
|
sys:x:3:
|
||||||
|
adm:x:4:
|
||||||
|
tty:x:5:
|
||||||
|
disk:x:6:
|
||||||
|
lp:x:7:
|
||||||
|
mail:x:8:
|
||||||
|
news:x:9:
|
||||||
|
uucp:x:10:
|
||||||
|
man:x:12:
|
||||||
|
proxy:x:13:
|
||||||
|
kmem:x:15:
|
||||||
|
dialout:x:20:
|
||||||
|
fax:x:21:
|
||||||
|
voice:x:22:
|
||||||
|
cdrom:x:24:
|
||||||
|
floppy:x:25:
|
||||||
|
tape:x:26:
|
||||||
|
sudo:x:27:
|
||||||
|
audio:x:29:
|
||||||
|
dip:x:30:
|
||||||
|
www-data:x:33:
|
||||||
|
backup:x:34:
|
||||||
|
operator:x:37:
|
||||||
|
list:x:38:
|
||||||
|
irc:x:39:
|
||||||
|
src:x:40:
|
||||||
|
gnats:x:41:
|
||||||
|
shadow:x:42:
|
||||||
|
utmp:x:43:
|
||||||
|
video:x:44:
|
||||||
|
sasl:x:45:
|
||||||
|
plugdev:x:46:
|
||||||
|
staff:x:50:
|
||||||
|
games:x:60:
|
||||||
|
users:x:100:
|
||||||
|
nogroup:x:65534:
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
root:x:0:0:root:/root:/bin/bash
|
||||||
|
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
|
||||||
|
bin:x:2:2:bin:/bin:/usr/sbin/nologin
|
||||||
|
sys:x:3:3:sys:/dev:/usr/sbin/nologin
|
||||||
|
sync:x:4:65534:sync:/bin:/bin/sync
|
||||||
|
games:x:5:60:games:/usr/games:/usr/sbin/nologin
|
||||||
|
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
|
||||||
|
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
|
||||||
|
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
|
||||||
|
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
|
||||||
|
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
|
||||||
|
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
|
||||||
|
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
|
||||||
|
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
|
||||||
|
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
|
||||||
|
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
|
||||||
|
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
|
||||||
|
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
# Internet (IP) protocols
|
||||||
|
#
|
||||||
|
# Updated from http://www.iana.org/assignments/protocol-numbers and other
|
||||||
|
# sources.
|
||||||
|
# New protocols will be added on request if they have been officially
|
||||||
|
# assigned by IANA and are not historical.
|
||||||
|
# If you need a huge list of used numbers please install the nmap package.
|
||||||
|
|
||||||
|
ip 0 IP # internet protocol, pseudo protocol number
|
||||||
|
hopopt 0 HOPOPT # IPv6 Hop-by-Hop Option [RFC1883]
|
||||||
|
icmp 1 ICMP # internet control message protocol
|
||||||
|
igmp 2 IGMP # Internet Group Management
|
||||||
|
ggp 3 GGP # gateway-gateway protocol
|
||||||
|
ipencap 4 IP-ENCAP # IP encapsulated in IP (officially ``IP'')
|
||||||
|
st 5 ST # ST datagram mode
|
||||||
|
tcp 6 TCP # transmission control protocol
|
||||||
|
egp 8 EGP # exterior gateway protocol
|
||||||
|
igp 9 IGP # any private interior gateway (Cisco)
|
||||||
|
pup 12 PUP # PARC universal packet protocol
|
||||||
|
udp 17 UDP # user datagram protocol
|
||||||
|
hmp 20 HMP # host monitoring protocol
|
||||||
|
xns-idp 22 XNS-IDP # Xerox NS IDP
|
||||||
|
rdp 27 RDP # "reliable datagram" protocol
|
||||||
|
iso-tp4 29 ISO-TP4 # ISO Transport Protocol class 4 [RFC905]
|
||||||
|
dccp 33 DCCP # Datagram Congestion Control Prot. [RFC4340]
|
||||||
|
xtp 36 XTP # Xpress Transfer Protocol
|
||||||
|
ddp 37 DDP # Datagram Delivery Protocol
|
||||||
|
idpr-cmtp 38 IDPR-CMTP # IDPR Control Message Transport
|
||||||
|
ipv6 41 IPv6 # Internet Protocol, version 6
|
||||||
|
ipv6-route 43 IPv6-Route # Routing Header for IPv6
|
||||||
|
ipv6-frag 44 IPv6-Frag # Fragment Header for IPv6
|
||||||
|
idrp 45 IDRP # Inter-Domain Routing Protocol
|
||||||
|
rsvp 46 RSVP # Reservation Protocol
|
||||||
|
gre 47 GRE # General Routing Encapsulation
|
||||||
|
esp 50 IPSEC-ESP # Encap Security Payload [RFC2406]
|
||||||
|
ah 51 IPSEC-AH # Authentication Header [RFC2402]
|
||||||
|
skip 57 SKIP # SKIP
|
||||||
|
ipv6-icmp 58 IPv6-ICMP # ICMP for IPv6
|
||||||
|
ipv6-nonxt 59 IPv6-NoNxt # No Next Header for IPv6
|
||||||
|
ipv6-opts 60 IPv6-Opts # Destination Options for IPv6
|
||||||
|
rspf 73 RSPF CPHB # Radio Shortest Path First (officially CPHB)
|
||||||
|
vmtp 81 VMTP # Versatile Message Transport
|
||||||
|
eigrp 88 EIGRP # Enhanced Interior Routing Protocol (Cisco)
|
||||||
|
ospf 89 OSPFIGP # Open Shortest Path First IGP
|
||||||
|
ax.25 93 AX.25 # AX.25 frames
|
||||||
|
ipip 94 IPIP # IP-within-IP Encapsulation Protocol
|
||||||
|
etherip 97 ETHERIP # Ethernet-within-IP Encapsulation [RFC3378]
|
||||||
|
encap 98 ENCAP # Yet Another IP encapsulation [RFC1241]
|
||||||
|
# 99 # any private encryption scheme
|
||||||
|
pim 103 PIM # Protocol Independent Multicast
|
||||||
|
ipcomp 108 IPCOMP # IP Payload Compression Protocol
|
||||||
|
vrrp 112 VRRP # Virtual Router Redundancy Protocol [RFC5798]
|
||||||
|
l2tp 115 L2TP # Layer Two Tunneling Protocol [RFC2661]
|
||||||
|
isis 124 ISIS # IS-IS over IPv4
|
||||||
|
sctp 132 SCTP # Stream Control Transmission Protocol
|
||||||
|
fc 133 FC # Fibre Channel
|
||||||
|
mobility-header 135 Mobility-Header # Mobility Support for IPv6 [RFC3775]
|
||||||
|
udplite 136 UDPLite # UDP-Lite [RFC3828]
|
||||||
|
mpls-in-ip 137 MPLS-in-IP # MPLS-in-IP [RFC4023]
|
||||||
|
manet 138 # MANET Protocols [RFC5498]
|
||||||
|
hip 139 HIP # Host Identity Protocol
|
||||||
|
shim6 140 Shim6 # Shim6 Protocol [RFC5533]
|
||||||
|
wesp 141 WESP # Wrapped Encapsulating Security Payload
|
||||||
|
rohc 142 ROHC # Robust Header Compression
|
||||||
@@ -0,0 +1,417 @@
|
|||||||
|
# Network services, Internet style
|
||||||
|
#
|
||||||
|
# Note that it is presently the policy of IANA to assign a single well-known
|
||||||
|
# port number for both TCP and UDP; hence, officially ports have two entries
|
||||||
|
# even if the protocol doesn't support UDP operations.
|
||||||
|
#
|
||||||
|
# Updated from https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml .
|
||||||
|
#
|
||||||
|
# New ports will be added on request if they have been officially assigned
|
||||||
|
# by IANA and used in the real-world or are needed by a debian package.
|
||||||
|
# If you need a huge list of used numbers please install the nmap package.
|
||||||
|
|
||||||
|
tcpmux 1/tcp # TCP port service multiplexer
|
||||||
|
echo 7/tcp
|
||||||
|
echo 7/udp
|
||||||
|
discard 9/tcp sink null
|
||||||
|
discard 9/udp sink null
|
||||||
|
systat 11/tcp users
|
||||||
|
daytime 13/tcp
|
||||||
|
daytime 13/udp
|
||||||
|
netstat 15/tcp
|
||||||
|
qotd 17/tcp quote
|
||||||
|
chargen 19/tcp ttytst source
|
||||||
|
chargen 19/udp ttytst source
|
||||||
|
ftp-data 20/tcp
|
||||||
|
ftp 21/tcp
|
||||||
|
fsp 21/udp fspd
|
||||||
|
ssh 22/tcp # SSH Remote Login Protocol
|
||||||
|
telnet 23/tcp
|
||||||
|
smtp 25/tcp mail
|
||||||
|
time 37/tcp timserver
|
||||||
|
time 37/udp timserver
|
||||||
|
whois 43/tcp nicname
|
||||||
|
tacacs 49/tcp # Login Host Protocol (TACACS)
|
||||||
|
tacacs 49/udp
|
||||||
|
domain 53/tcp # Domain Name Server
|
||||||
|
domain 53/udp
|
||||||
|
bootps 67/udp
|
||||||
|
bootpc 68/udp
|
||||||
|
tftp 69/udp
|
||||||
|
gopher 70/tcp # Internet Gopher
|
||||||
|
finger 79/tcp
|
||||||
|
http 80/tcp www # WorldWideWeb HTTP
|
||||||
|
kerberos 88/tcp kerberos5 krb5 kerberos-sec # Kerberos v5
|
||||||
|
kerberos 88/udp kerberos5 krb5 kerberos-sec # Kerberos v5
|
||||||
|
iso-tsap 102/tcp tsap # part of ISODE
|
||||||
|
acr-nema 104/tcp dicom # Digital Imag. & Comm. 300
|
||||||
|
pop3 110/tcp pop-3 # POP version 3
|
||||||
|
sunrpc 111/tcp portmapper # RPC 4.0 portmapper
|
||||||
|
sunrpc 111/udp portmapper
|
||||||
|
auth 113/tcp authentication tap ident
|
||||||
|
nntp 119/tcp readnews untp # USENET News Transfer Protocol
|
||||||
|
ntp 123/udp # Network Time Protocol
|
||||||
|
epmap 135/tcp loc-srv # DCE endpoint resolution
|
||||||
|
netbios-ns 137/tcp # NETBIOS Name Service
|
||||||
|
netbios-ns 137/udp
|
||||||
|
netbios-dgm 138/tcp # NETBIOS Datagram Service
|
||||||
|
netbios-dgm 138/udp
|
||||||
|
netbios-ssn 139/tcp # NETBIOS session service
|
||||||
|
netbios-ssn 139/udp
|
||||||
|
imap2 143/tcp imap # Interim Mail Access P 2 and 4
|
||||||
|
snmp 161/tcp # Simple Net Mgmt Protocol
|
||||||
|
snmp 161/udp
|
||||||
|
snmp-trap 162/tcp snmptrap # Traps for SNMP
|
||||||
|
snmp-trap 162/udp snmptrap
|
||||||
|
cmip-man 163/tcp # ISO mgmt over IP (CMOT)
|
||||||
|
cmip-man 163/udp
|
||||||
|
cmip-agent 164/tcp
|
||||||
|
cmip-agent 164/udp
|
||||||
|
mailq 174/tcp # Mailer transport queue for Zmailer
|
||||||
|
xdmcp 177/udp # X Display Manager Control Protocol
|
||||||
|
bgp 179/tcp # Border Gateway Protocol
|
||||||
|
smux 199/tcp # SNMP Unix Multiplexer
|
||||||
|
qmtp 209/tcp # Quick Mail Transfer Protocol
|
||||||
|
z3950 210/tcp wais # NISO Z39.50 database
|
||||||
|
ipx 213/udp # IPX [RFC1234]
|
||||||
|
ptp-event 319/udp
|
||||||
|
ptp-general 320/udp
|
||||||
|
pawserv 345/tcp # Perf Analysis Workbench
|
||||||
|
zserv 346/tcp # Zebra server
|
||||||
|
rpc2portmap 369/tcp
|
||||||
|
rpc2portmap 369/udp # Coda portmapper
|
||||||
|
codaauth2 370/tcp
|
||||||
|
codaauth2 370/udp # Coda authentication server
|
||||||
|
clearcase 371/udp Clearcase
|
||||||
|
ldap 389/tcp # Lightweight Directory Access Protocol
|
||||||
|
ldap 389/udp
|
||||||
|
svrloc 427/tcp # Server Location
|
||||||
|
svrloc 427/udp
|
||||||
|
https 443/tcp # http protocol over TLS/SSL
|
||||||
|
snpp 444/tcp # Simple Network Paging Protocol
|
||||||
|
microsoft-ds 445/tcp # Microsoft Naked CIFS
|
||||||
|
microsoft-ds 445/udp
|
||||||
|
kpasswd 464/tcp
|
||||||
|
kpasswd 464/udp
|
||||||
|
submissions 465/tcp ssmtp smtps urd # Submission over TLS [RFC8314]
|
||||||
|
saft 487/tcp # Simple Asynchronous File Transfer
|
||||||
|
isakmp 500/udp # IPSEC key management
|
||||||
|
rtsp 554/tcp # Real Time Stream Control Protocol
|
||||||
|
rtsp 554/udp
|
||||||
|
nqs 607/tcp # Network Queuing system
|
||||||
|
asf-rmcp 623/udp # ASF Remote Management and Control Protocol
|
||||||
|
qmqp 628/tcp
|
||||||
|
ipp 631/tcp # Internet Printing Protocol
|
||||||
|
#
|
||||||
|
# UNIX specific services
|
||||||
|
#
|
||||||
|
exec 512/tcp
|
||||||
|
biff 512/udp comsat
|
||||||
|
login 513/tcp
|
||||||
|
who 513/udp whod
|
||||||
|
shell 514/tcp cmd syslog # no passwords used
|
||||||
|
syslog 514/udp
|
||||||
|
printer 515/tcp spooler # line printer spooler
|
||||||
|
talk 517/udp
|
||||||
|
ntalk 518/udp
|
||||||
|
route 520/udp router routed # RIP
|
||||||
|
gdomap 538/tcp # GNUstep distributed objects
|
||||||
|
gdomap 538/udp
|
||||||
|
uucp 540/tcp uucpd # uucp daemon
|
||||||
|
klogin 543/tcp # Kerberized `rlogin' (v5)
|
||||||
|
kshell 544/tcp krcmd # Kerberized `rsh' (v5)
|
||||||
|
dhcpv6-client 546/udp
|
||||||
|
dhcpv6-server 547/udp
|
||||||
|
afpovertcp 548/tcp # AFP over TCP
|
||||||
|
nntps 563/tcp snntp # NNTP over SSL
|
||||||
|
submission 587/tcp # Submission [RFC4409]
|
||||||
|
ldaps 636/tcp # LDAP over SSL
|
||||||
|
ldaps 636/udp
|
||||||
|
tinc 655/tcp # tinc control port
|
||||||
|
tinc 655/udp
|
||||||
|
silc 706/tcp
|
||||||
|
kerberos-adm 749/tcp # Kerberos `kadmin' (v5)
|
||||||
|
#
|
||||||
|
domain-s 853/tcp # DNS over TLS [RFC7858]
|
||||||
|
domain-s 853/udp # DNS over DTLS [RFC8094]
|
||||||
|
rsync 873/tcp
|
||||||
|
ftps-data 989/tcp # FTP over SSL (data)
|
||||||
|
ftps 990/tcp
|
||||||
|
telnets 992/tcp # Telnet over SSL
|
||||||
|
imaps 993/tcp # IMAP over SSL
|
||||||
|
pop3s 995/tcp # POP-3 over SSL
|
||||||
|
#
|
||||||
|
# From ``Assigned Numbers'':
|
||||||
|
#
|
||||||
|
#> The Registered Ports are not controlled by the IANA and on most systems
|
||||||
|
#> can be used by ordinary user processes or programs executed by ordinary
|
||||||
|
#> users.
|
||||||
|
#
|
||||||
|
#> Ports are used in the TCP [45,106] to name the ends of logical
|
||||||
|
#> connections which carry long term conversations. For the purpose of
|
||||||
|
#> providing services to unknown callers, a service contact port is
|
||||||
|
#> defined. This list specifies the port used by the server process as its
|
||||||
|
#> contact port. While the IANA can not control uses of these ports it
|
||||||
|
#> does register or list uses of these ports as a convienence to the
|
||||||
|
#> community.
|
||||||
|
#
|
||||||
|
socks 1080/tcp # socks proxy server
|
||||||
|
proofd 1093/tcp
|
||||||
|
rootd 1094/tcp
|
||||||
|
openvpn 1194/tcp
|
||||||
|
openvpn 1194/udp
|
||||||
|
rmiregistry 1099/tcp # Java RMI Registry
|
||||||
|
lotusnote 1352/tcp lotusnotes # Lotus Note
|
||||||
|
ms-sql-s 1433/tcp # Microsoft SQL Server
|
||||||
|
ms-sql-s 1433/udp
|
||||||
|
ms-sql-m 1434/tcp # Microsoft SQL Monitor
|
||||||
|
ms-sql-m 1434/udp
|
||||||
|
ingreslock 1524/tcp
|
||||||
|
datametrics 1645/tcp old-radius
|
||||||
|
datametrics 1645/udp old-radius
|
||||||
|
sa-msg-port 1646/tcp old-radacct
|
||||||
|
sa-msg-port 1646/udp old-radacct
|
||||||
|
kermit 1649/tcp
|
||||||
|
groupwise 1677/tcp
|
||||||
|
l2f 1701/udp l2tp
|
||||||
|
radius 1812/tcp
|
||||||
|
radius 1812/udp
|
||||||
|
radius-acct 1813/tcp radacct # Radius Accounting
|
||||||
|
radius-acct 1813/udp radacct
|
||||||
|
cisco-sccp 2000/tcp # Cisco SCCP
|
||||||
|
nfs 2049/tcp # Network File System
|
||||||
|
nfs 2049/udp # Network File System
|
||||||
|
gnunet 2086/tcp
|
||||||
|
gnunet 2086/udp
|
||||||
|
rtcm-sc104 2101/tcp # RTCM SC-104 IANA 1/29/99
|
||||||
|
rtcm-sc104 2101/udp
|
||||||
|
gsigatekeeper 2119/tcp
|
||||||
|
gris 2135/tcp # Grid Resource Information Server
|
||||||
|
cvspserver 2401/tcp # CVS client/server operations
|
||||||
|
venus 2430/tcp # codacon port
|
||||||
|
venus 2430/udp # Venus callback/wbc interface
|
||||||
|
venus-se 2431/tcp # tcp side effects
|
||||||
|
venus-se 2431/udp # udp sftp side effect
|
||||||
|
codasrv 2432/tcp # not used
|
||||||
|
codasrv 2432/udp # server port
|
||||||
|
codasrv-se 2433/tcp # tcp side effects
|
||||||
|
codasrv-se 2433/udp # udp sftp side effect
|
||||||
|
mon 2583/tcp # MON traps
|
||||||
|
mon 2583/udp
|
||||||
|
dict 2628/tcp # Dictionary server
|
||||||
|
f5-globalsite 2792/tcp
|
||||||
|
gsiftp 2811/tcp
|
||||||
|
gpsd 2947/tcp
|
||||||
|
gds-db 3050/tcp gds_db # InterBase server
|
||||||
|
icpv2 3130/tcp icp # Internet Cache Protocol
|
||||||
|
icpv2 3130/udp icp
|
||||||
|
isns 3205/tcp # iSNS Server Port
|
||||||
|
isns 3205/udp # iSNS Server Port
|
||||||
|
iscsi-target 3260/tcp
|
||||||
|
mysql 3306/tcp
|
||||||
|
ms-wbt-server 3389/tcp
|
||||||
|
nut 3493/tcp # Network UPS Tools
|
||||||
|
nut 3493/udp
|
||||||
|
distcc 3632/tcp # distributed compiler
|
||||||
|
distcc 3632/udp
|
||||||
|
daap 3689/tcp # Digital Audio Access Protocol
|
||||||
|
daap 3689/udp
|
||||||
|
svn 3690/tcp subversion # Subversion protocol
|
||||||
|
svn 3690/udp subversion
|
||||||
|
suucp 4031/tcp # UUCP over SSL
|
||||||
|
suucp 4031/udp
|
||||||
|
sysrqd 4094/tcp # sysrq daemon
|
||||||
|
sysrqd 4094/udp
|
||||||
|
sieve 4190/tcp # ManageSieve Protocol
|
||||||
|
epmd 4369/tcp # Erlang Port Mapper Daemon
|
||||||
|
epmd 4369/udp
|
||||||
|
remctl 4373/tcp # Remote Authenticated Command Service
|
||||||
|
remctl 4373/udp
|
||||||
|
f5-iquery 4353/tcp # F5 iQuery
|
||||||
|
f5-iquery 4353/udp
|
||||||
|
ipsec-nat-t 4500/udp # IPsec NAT-Traversal [RFC3947]
|
||||||
|
iax 4569/tcp # Inter-Asterisk eXchange
|
||||||
|
iax 4569/udp
|
||||||
|
mtn 4691/tcp # monotone Netsync Protocol
|
||||||
|
mtn 4691/udp
|
||||||
|
radmin-port 4899/tcp # RAdmin Port
|
||||||
|
radmin-port 4899/udp
|
||||||
|
sip 5060/tcp # Session Initiation Protocol
|
||||||
|
sip 5060/udp
|
||||||
|
sip-tls 5061/tcp
|
||||||
|
sip-tls 5061/udp
|
||||||
|
xmpp-client 5222/tcp jabber-client # Jabber Client Connection
|
||||||
|
xmpp-server 5269/tcp jabber-server # Jabber Server Connection
|
||||||
|
cfengine 5308/tcp
|
||||||
|
mdns 5353/udp # Multicast DNS
|
||||||
|
postgresql 5432/tcp postgres # PostgreSQL Database
|
||||||
|
freeciv 5556/tcp rptp # Freeciv gameplay
|
||||||
|
amqps 5671/tcp # AMQP protocol over TLS/SSL
|
||||||
|
amqp 5672/tcp
|
||||||
|
amqp 5672/udp
|
||||||
|
amqp 5672/sctp
|
||||||
|
x11 6000/tcp x11-0 # X Window System
|
||||||
|
x11-1 6001/tcp
|
||||||
|
x11-2 6002/tcp
|
||||||
|
x11-3 6003/tcp
|
||||||
|
x11-4 6004/tcp
|
||||||
|
x11-5 6005/tcp
|
||||||
|
x11-6 6006/tcp
|
||||||
|
x11-7 6007/tcp
|
||||||
|
gnutella-svc 6346/tcp # gnutella
|
||||||
|
gnutella-svc 6346/udp
|
||||||
|
gnutella-rtr 6347/tcp # gnutella
|
||||||
|
gnutella-rtr 6347/udp
|
||||||
|
sge-qmaster 6444/tcp sge_qmaster # Grid Engine Qmaster Service
|
||||||
|
sge-execd 6445/tcp sge_execd # Grid Engine Execution Service
|
||||||
|
mysql-proxy 6446/tcp # MySQL Proxy
|
||||||
|
babel 6696/udp # Babel Routing Protocol
|
||||||
|
ircs-u 6697/tcp # Internet Relay Chat via TLS/SSL
|
||||||
|
afs3-fileserver 7000/tcp bbs # file server itself
|
||||||
|
afs3-fileserver 7000/udp bbs
|
||||||
|
afs3-callback 7001/tcp # callbacks to cache managers
|
||||||
|
afs3-callback 7001/udp
|
||||||
|
afs3-prserver 7002/tcp # users & groups database
|
||||||
|
afs3-prserver 7002/udp
|
||||||
|
afs3-vlserver 7003/tcp # volume location database
|
||||||
|
afs3-vlserver 7003/udp
|
||||||
|
afs3-kaserver 7004/tcp # AFS/Kerberos authentication
|
||||||
|
afs3-kaserver 7004/udp
|
||||||
|
afs3-volser 7005/tcp # volume managment server
|
||||||
|
afs3-volser 7005/udp
|
||||||
|
afs3-errors 7006/tcp # error interpretation service
|
||||||
|
afs3-errors 7006/udp
|
||||||
|
afs3-bos 7007/tcp # basic overseer process
|
||||||
|
afs3-bos 7007/udp
|
||||||
|
afs3-update 7008/tcp # server-to-server updater
|
||||||
|
afs3-update 7008/udp
|
||||||
|
afs3-rmtsys 7009/tcp # remote cache manager service
|
||||||
|
afs3-rmtsys 7009/udp
|
||||||
|
font-service 7100/tcp xfs # X Font Service
|
||||||
|
http-alt 8080/tcp webcache # WWW caching service
|
||||||
|
puppet 8140/tcp # The Puppet master service
|
||||||
|
bacula-dir 9101/tcp # Bacula Director
|
||||||
|
bacula-fd 9102/tcp # Bacula File Daemon
|
||||||
|
bacula-sd 9103/tcp # Bacula Storage Daemon
|
||||||
|
xmms2 9667/tcp # Cross-platform Music Multiplexing System
|
||||||
|
nbd 10809/tcp # Linux Network Block Device
|
||||||
|
zabbix-agent 10050/tcp # Zabbix Agent
|
||||||
|
zabbix-trapper 10051/tcp # Zabbix Trapper
|
||||||
|
amanda 10080/tcp # amanda backup services
|
||||||
|
dicom 11112/tcp
|
||||||
|
hkp 11371/tcp # OpenPGP HTTP Keyserver
|
||||||
|
db-lsp 17500/tcp # Dropbox LanSync Protocol
|
||||||
|
dcap 22125/tcp # dCache Access Protocol
|
||||||
|
gsidcap 22128/tcp # GSI dCache Access Protocol
|
||||||
|
wnn6 22273/tcp # wnn6
|
||||||
|
|
||||||
|
#
|
||||||
|
# Datagram Delivery Protocol services
|
||||||
|
#
|
||||||
|
rtmp 1/ddp # Routing Table Maintenance Protocol
|
||||||
|
nbp 2/ddp # Name Binding Protocol
|
||||||
|
echo 4/ddp # AppleTalk Echo Protocol
|
||||||
|
zip 6/ddp # Zone Information Protocol
|
||||||
|
|
||||||
|
#=========================================================================
|
||||||
|
# The remaining port numbers are not as allocated by IANA.
|
||||||
|
#=========================================================================
|
||||||
|
|
||||||
|
# Kerberos (Project Athena/MIT) services
|
||||||
|
kerberos4 750/udp kerberos-iv kdc # Kerberos (server)
|
||||||
|
kerberos4 750/tcp kerberos-iv kdc
|
||||||
|
kerberos-master 751/udp kerberos_master # Kerberos authentication
|
||||||
|
kerberos-master 751/tcp
|
||||||
|
passwd-server 752/udp passwd_server # Kerberos passwd server
|
||||||
|
krb-prop 754/tcp krb_prop krb5_prop hprop # Kerberos slave propagation
|
||||||
|
zephyr-srv 2102/udp # Zephyr server
|
||||||
|
zephyr-clt 2103/udp # Zephyr serv-hm connection
|
||||||
|
zephyr-hm 2104/udp # Zephyr hostmanager
|
||||||
|
iprop 2121/tcp # incremental propagation
|
||||||
|
supfilesrv 871/tcp # Software Upgrade Protocol server
|
||||||
|
supfiledbg 1127/tcp # Software Upgrade Protocol debugging
|
||||||
|
|
||||||
|
#
|
||||||
|
# Services added for the Debian GNU/Linux distribution
|
||||||
|
#
|
||||||
|
poppassd 106/tcp # Eudora
|
||||||
|
poppassd 106/udp
|
||||||
|
moira-db 775/tcp moira_db # Moira database
|
||||||
|
moira-update 777/tcp moira_update # Moira update protocol
|
||||||
|
moira-ureg 779/udp moira_ureg # Moira user registration
|
||||||
|
spamd 783/tcp # spamassassin daemon
|
||||||
|
skkserv 1178/tcp # skk jisho server port
|
||||||
|
predict 1210/udp # predict -- satellite tracking
|
||||||
|
rmtcfg 1236/tcp # Gracilis Packeten remote config server
|
||||||
|
xtel 1313/tcp # french minitel
|
||||||
|
xtelw 1314/tcp # french minitel
|
||||||
|
support 1529/tcp # GNATS
|
||||||
|
cfinger 2003/tcp # GNU Finger
|
||||||
|
frox 2121/tcp # frox: caching ftp proxy
|
||||||
|
zebrasrv 2600/tcp # zebra service
|
||||||
|
zebra 2601/tcp # zebra vty
|
||||||
|
ripd 2602/tcp # ripd vty (zebra)
|
||||||
|
ripngd 2603/tcp # ripngd vty (zebra)
|
||||||
|
ospfd 2604/tcp # ospfd vty (zebra)
|
||||||
|
bgpd 2605/tcp # bgpd vty (zebra)
|
||||||
|
ospf6d 2606/tcp # ospf6d vty (zebra)
|
||||||
|
ospfapi 2607/tcp # OSPF-API
|
||||||
|
isisd 2608/tcp # ISISd vty (zebra)
|
||||||
|
afbackup 2988/tcp # Afbackup system
|
||||||
|
afbackup 2988/udp
|
||||||
|
afmbackup 2989/tcp # Afmbackup system
|
||||||
|
afmbackup 2989/udp
|
||||||
|
fax 4557/tcp # FAX transmission service (old)
|
||||||
|
hylafax 4559/tcp # HylaFAX client-server protocol (new)
|
||||||
|
distmp3 4600/tcp # distmp3host daemon
|
||||||
|
munin 4949/tcp lrrd # Munin
|
||||||
|
enbd-cstatd 5051/tcp # ENBD client statd
|
||||||
|
enbd-sstatd 5052/tcp # ENBD server statd
|
||||||
|
pcrd 5151/tcp # PCR-1000 Daemon
|
||||||
|
noclog 5354/tcp # noclogd with TCP (nocol)
|
||||||
|
noclog 5354/udp # noclogd with UDP (nocol)
|
||||||
|
hostmon 5355/tcp # hostmon uses TCP (nocol)
|
||||||
|
hostmon 5355/udp # hostmon uses UDP (nocol)
|
||||||
|
rplay 5555/udp # RPlay audio service
|
||||||
|
nrpe 5666/tcp # Nagios Remote Plugin Executor
|
||||||
|
nsca 5667/tcp # Nagios Agent - NSCA
|
||||||
|
mrtd 5674/tcp # MRT Routing Daemon
|
||||||
|
bgpsim 5675/tcp # MRT Routing Simulator
|
||||||
|
canna 5680/tcp # cannaserver
|
||||||
|
syslog-tls 6514/tcp # Syslog over TLS [RFC5425]
|
||||||
|
sane-port 6566/tcp sane saned # SANE network scanner daemon
|
||||||
|
ircd 6667/tcp # Internet Relay Chat
|
||||||
|
zope-ftp 8021/tcp # zope management by ftp
|
||||||
|
tproxy 8081/tcp # Transparent Proxy
|
||||||
|
omniorb 8088/tcp # OmniORB
|
||||||
|
omniorb 8088/udp
|
||||||
|
clc-build-daemon 8990/tcp # Common lisp build daemon
|
||||||
|
xinetd 9098/tcp
|
||||||
|
mandelspawn 9359/udp mandelbrot # network mandelbrot
|
||||||
|
git 9418/tcp # Git Version Control System
|
||||||
|
zope 9673/tcp # zope server
|
||||||
|
webmin 10000/tcp
|
||||||
|
kamanda 10081/tcp # amanda backup services (Kerberos)
|
||||||
|
amandaidx 10082/tcp # amanda backup services
|
||||||
|
amidxtape 10083/tcp # amanda backup services
|
||||||
|
smsqp 11201/tcp # Alamin SMS gateway
|
||||||
|
smsqp 11201/udp
|
||||||
|
xpilot 15345/tcp # XPilot Contact Port
|
||||||
|
xpilot 15345/udp
|
||||||
|
sgi-cmsd 17001/udp # Cluster membership services daemon
|
||||||
|
sgi-crsd 17002/udp
|
||||||
|
sgi-gcd 17003/udp # SGI Group membership daemon
|
||||||
|
sgi-cad 17004/tcp # Cluster Admin daemon
|
||||||
|
isdnlog 20011/tcp # isdn logging system
|
||||||
|
isdnlog 20011/udp
|
||||||
|
vboxd 20012/tcp # voice box system
|
||||||
|
vboxd 20012/udp
|
||||||
|
binkp 24554/tcp # binkp fidonet protocol
|
||||||
|
asp 27374/tcp # Address Search Protocol
|
||||||
|
asp 27374/udp
|
||||||
|
csync2 30865/tcp # cluster synchronization tool
|
||||||
|
dircproxy 57000/tcp # Detachable IRC Proxy
|
||||||
|
tfido 60177/tcp # fidonet EMSI over telnet
|
||||||
|
fido 60179/tcp # fidonet EMSI over TCP
|
||||||
|
|
||||||
|
# Local services
|
||||||
Executable
Whitespace-only changes.
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
executable
|
||||||
Whitespace-only changes.
File renamed without changes.
@@ -5,10 +5,13 @@ int main(void)
|
|||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
struct { char *file; int exist; } arr[] = {
|
struct { char *file; int exist; } arr[] = {
|
||||||
{ "/etc/passwd", 1 },
|
{ "data/fexist/regular", 1 },
|
||||||
{ "/etc/kalle", 0 },
|
{ "data/fexist/executable", 1 },
|
||||||
{ "/sbin/init", 1 },
|
{ "data/fexist/link", 1 },
|
||||||
{ "/dev/null", 1 },
|
{ "data/fexist/nonexistence", 0 },
|
||||||
|
{ "data/fexist/broken-link", 0 },
|
||||||
|
{ "data/fexist/dir", 1 },
|
||||||
|
{ "/dev/null", 1 },
|
||||||
{ NULL, 0 },
|
{ NULL, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
File renamed without changes.
@@ -0,0 +1,25 @@
|
|||||||
|
#include "check.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
char *dir = "/tmp";
|
||||||
|
char *file = "__foo__";
|
||||||
|
|
||||||
|
printf("Pass 1/2: fopenf() ===========================\n");
|
||||||
|
fp = fopenf("w", "%s/%s", dir, file);
|
||||||
|
if (fp) {
|
||||||
|
fputs("foo", fp);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
fail_unless(fexist("/tmp/__foo__"));
|
||||||
|
|
||||||
|
printf("Pass 2/2: fremove() ==========================\n");
|
||||||
|
fremove("%s/%s", dir, file);
|
||||||
|
fail_unless(!fexist("/tmp/__foo__"));
|
||||||
|
|
||||||
|
printf("DONE =========================================\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
File renamed without changes.
@@ -1,7 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
#define FSTAB "/etc/fstab"
|
#define FSTAB "data/lfile/fstab"
|
||||||
|
|
||||||
static int fstab(void)
|
static int fstab(void)
|
||||||
{
|
{
|
||||||
@@ -42,28 +42,28 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
val = fgetint("/etc/protocols", " \n\t", "udp");
|
val = fgetint("data/lfile/protocols", " \n\t", "udp");
|
||||||
if (val == -1) {
|
if (val == -1) {
|
||||||
perror("Failed locating 'udp' protocol");
|
perror("Failed locating 'udp' protocol");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printf("udp has proto %d\n", val);
|
printf("udp has proto %d\n", val);
|
||||||
|
|
||||||
val = fgetint("/etc/services", " /\n\t", "ftp");
|
val = fgetint("data/lfile/services", " /\n\t", "ftp");
|
||||||
if (val == -1) {
|
if (val == -1) {
|
||||||
perror("Failed locating 'ftp' service");
|
perror("Failed locating 'ftp' service");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printf("ftp is inet port %d\n", val);
|
printf("ftp is inet port %d\n", val);
|
||||||
|
|
||||||
val = fgetint("/etc/group", "x:\n", "utmp");
|
val = fgetint("data/lfile/group", "x:\n", "utmp");
|
||||||
if (val == -1) {
|
if (val == -1) {
|
||||||
perror("Failed locating group 'utmp'");
|
perror("Failed locating group 'utmp'");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printf("utmp is gid %d\n", val);
|
printf("utmp is gid %d\n", val);
|
||||||
|
|
||||||
val = fgetint("/etc/passwd", "x:\n", "nobody");
|
val = fgetint("data/lfile/passwd", "x:\n", "nobody");
|
||||||
if (val == -1) {
|
if (val == -1) {
|
||||||
perror("Failed locating user 'nobody'");
|
perror("Failed locating user 'nobody'");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
|
#define BASEDIR "/tmp/libite-test"
|
||||||
|
|
||||||
int checkpath(const char *dir)
|
int checkpath(const char *dir)
|
||||||
{
|
{
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
@@ -32,28 +34,48 @@ int test_makepath(const char *dir)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int test_fmkpath(const char *subdir)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = fmkpath(0755, "%s/%s", BASEDIR, subdir);
|
||||||
|
if (!ret) {
|
||||||
|
char tmp[256];
|
||||||
|
|
||||||
|
snprintf(tmp, sizeof(tmp), "%s/%s", BASEDIR, subdir);
|
||||||
|
ret = checkpath(tmp);
|
||||||
|
} else
|
||||||
|
perror("Failed");
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int i, ret = 0;
|
int i, ret = 0;
|
||||||
char *list[] = {
|
char *list[] = {
|
||||||
"/tmp/libite-test/tok/",
|
BASEDIR "/tok/",
|
||||||
"/tmp/libite-test/tok2",
|
BASEDIR "/tok2",
|
||||||
"/tmp/libite-test/ab",
|
BASEDIR "/ab",
|
||||||
"/tmp/libite-test/b",
|
BASEDIR "/b",
|
||||||
"/tmp/libite-test/a/",
|
BASEDIR "/a/",
|
||||||
"/tmp/libite-test/a/b",
|
BASEDIR "/a/b",
|
||||||
"/tmp/libite-test/a/c/",
|
BASEDIR "/a/c/",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
printf("Testing makepath() ...\n");
|
mkdir(BASEDIR, 0755);
|
||||||
mkdir("/tmp/libite-test", 0755);
|
|
||||||
|
|
||||||
|
printf("Pass 1/2: makepath() =========================\n");
|
||||||
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("Pass 2/2: fmkpath() ==========================\n");
|
||||||
system("rm -rf /tmp/libite-test");
|
for (i = 0; list[i] && !ret; i++)
|
||||||
|
ret |= test_fmkpath(list[i] + strlen(BASEDIR) + 1);
|
||||||
|
|
||||||
|
printf("Done: Cleaning up ============================\n");
|
||||||
|
system("rm -rf " BASEDIR);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -17,12 +17,16 @@ static struct stat before, after;
|
|||||||
|
|
||||||
static void sigterm_handler(int signo)
|
static void sigterm_handler(int signo)
|
||||||
{
|
{
|
||||||
|
(void)signo;
|
||||||
|
|
||||||
PRINT("Exiting ...\n");
|
PRINT("Exiting ...\n");
|
||||||
remove(PIDFILE);
|
remove(PIDFILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sigalrm_handler(int signo)
|
static void sigalrm_handler(int signo)
|
||||||
{
|
{
|
||||||
|
(void)signo;
|
||||||
|
|
||||||
PRINT("Calling pidfile(%s)\n", pidfile_arg ?: "NULL");
|
PRINT("Calling pidfile(%s)\n", pidfile_arg ?: "NULL");
|
||||||
if (pidfile(pidfile_arg))
|
if (pidfile(pidfile_arg))
|
||||||
err(1, "failed creating1 %s", pidfile_arg);
|
err(1, "failed creating1 %s", pidfile_arg);
|
||||||
@@ -37,7 +41,7 @@ static int mtime()
|
|||||||
char buf[80];
|
char buf[80];
|
||||||
|
|
||||||
/* 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);
|
sleep(2);
|
||||||
|
|
||||||
PRINT("Calling pidfile() again to update mtime ...\n");
|
PRINT("Calling pidfile() again to update mtime ...\n");
|
||||||
if (pidfile(pidfile_arg))
|
if (pidfile(pidfile_arg))
|
||||||
File renamed without changes.
File renamed without changes.
Loaded 100 of 113 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user