From 9121c715872144fa3bb6f6b9c7961191650b0809 Mon Sep 17 00:00:00 2001 From: merakor Date: Mon, 4 Jan 2021 10:20:53 +0000 Subject: docs: add portability functions FossilOrigin-Name: 86f635837ee62d81b8742fe845239233dd0f31f8cc763e35e7e699efc0631dbd --- docs/cpt.org | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/cpt.org b/docs/cpt.org index 9b475a8..b1d3c0c 100644 --- a/docs/cpt.org +++ b/docs/cpt.org @@ -48,6 +48,7 @@ manual for *Carbs Packaging Tools*. For development logs see [[https://git.carbs - [[#option-parsing][Option parsing]] - [[#message-functions][Message functions]] - [[#text-functions][Text functions]] + - [[#portability-functions][Portability functions]] - [[#system-functions][System Functions]] * Copying @@ -945,7 +946,48 @@ sepchar mystring # g #+end_src -** System Functions +** Portability functions +:PROPERTIES: +:DESCRIPTION: Functions to replace non-POSIX commands +:END: + +These helper functions are used so that we don't depend on non-POSIX programs for +certain functionality. They are prefixed with the =_= character. + +*** =_seq()= +:PROPERTIES: +:DESCRIPTION: 'seq(1)' but no newline +:END: + +This function is similar to =seq(1)= except that it only takes a single argument +and doesn't print any newlines. It is suitable to be used in =for= loops. + +#+begin_src sh +_seq 5 +# Prints: +# 1 2 3 4 5 +#+end_src + +*** =_stat()= +:PROPERTIES: +:DESCRIPTION: stat %U replacement +:END: + +This function imitates =stat %U=. =stat= isn't defined by POSIX, and this is +also a GNU extension. This function returns the owner of a file. If the owner +cannot be found, it will return =root=. + +*** =_readlinkf()= +:PROPERTIES: +:DESCRIPTION: 'readlink -f' replacement +:END: + +This function was taken from [[github:ko1nksm/readlinkf][POSIX sh readlinkf library by Koichi Nakashima]]. +=readlink= is also not defined by POSIX, so this function uses =ls= to follow +symbolic links until it reaches the actual file. + +** TODO System Functions +- [ ] Add description *** =as_root()= :PROPERTIES: :DESCRIPTION: Run a command as the root user -- cgit v1.2.3