Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

write some functions in C #301

Closed
wants to merge 3 commits into from
Closed

Conversation

aabacchus
Copy link

Below is one way of integrating some C programs into the package manager. At the moment they are individual binaries but in the future the main functions of each program could be used as self contained functions in a library. See https://github.com/kisslinux/website/blob/68db287bdf5b12e78d50c4b17f9a27c6a3d4eec6/site/blog/20210711a.txt#L261-L275 for one of Dylan's ideas.

I have not implemented the opt-in/out idea but this could be achieved with a simple environment variable check.

With these patches, the package manager expects the binaries to be found in /usr/lib/kiss/. A patch to support this for the kiss build file in repo is below. Either the directory /usr/lib/kiss/ can be prepended to $PATH, or absolute paths could be used when the programs are called. Maybe it would be best to call the binaries kiss_owner etc rather than just owner and use them in /usr/lib/kiss prepended to $PATH.

I have started with two C programs; each replaces one instance of parsing ls. This fixes the problem in #289 and should be a bit faster.

Both C programs are written in ISO C90 (-std=c89) and use only libc functions from POSIX.

diff --git a/core/kiss/build b/core/kiss/build
index 08d78cbf..b61bbb52 100755
--- a/core/kiss/build
+++ b/core/kiss/build
@@ -2,7 +2,8 @@
 
 mkdir -p \
     "$1/usr/bin" \
-    "$1/usr/share/doc/kiss"
+    "$1/usr/lib/kiss" \
+    "$1/usr/share/doc/kiss/lib"
 
 cp -f  kiss contrib/*  "$1/usr/bin"
 cp -f  docs/site/*.txt "$1/usr/share/doc/kiss"
@@ -12,3 +13,10 @@ rm -f \
     "$1/usr/share/doc/kiss/README.txt" \
     "$1/usr/share/doc/kiss/post.txt" \
     "$1/usr/share/doc/kiss/tidbits.txt"
+
+# Disable warning as CFLAGS must work this way.
+# shellcheck disable=2086
+for bin in owner rwx; do
+    "$CC" -o "$1/usr/lib/kiss/$bin" "bin/$bin.c" $CFLAGS -static
+    cp -f "bin/$bin.c" "$1/usr/share/doc/kiss/lib/$bin.c"
+done

Thoughts are welcome, this is just one idea of an improvement.

Replace parsing the output of "ls -ld" to a small program which just
prints the username of the owner of a file. Parsing ls(1) sometimes
caused truncation at 8 characters. The C file must be compiled when kiss
is installed and the binary is expected to be in /usr/lib/kiss. This
directory is prepended to $PATH and the new PATH is exported, so that
the tools can also be used from hooks.
parsing ls is a bit hacky and this should be quite a bit faster.
This is much faster and also more accurate. This version prints sizes
under 1KB in bytes, B.
@dylanaraps dylanaraps closed this Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants