diff options
author | Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de> | 2020-03-12 08:56:34 +0000 |
---|---|---|
committer | Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de> | 2020-03-12 08:56:34 +0000 |
commit | 0d1c4f95c4c2d2d7c1a01f6a46502b7c49c06647 (patch) | |
tree | 10fa5a00d57bc448c56af4b7ccdb69d4721e045b /subr/rtl_complex.subr | |
parent | 72e7c3318ee19b81bfe532750bb467f1391ee1fb (diff) | |
download | midipix_build-0d1c4f95c4c2d2d7c1a01f6a46502b7c49c06647.tar.bz2 midipix_build-0d1c4f95c4c2d2d7c1a01f6a46502b7c49c06647.tar.xz |
Reduce awk(1), grep(1), seq(1), and stat(1) usage.
subr/build_init.subr:buildp_init_files(): replace timestamp w/ running total log filename suffix.
subr/build_init.subr:buildp_init_prereqs(): ensure sed(1) supports -i option.
subr/rtl_complex.subr:rtl_{get_cpu_count,is_newer}(): initial implementation.
subr/rtl_string.subr:rtl_match(): initial implementation.
Diffstat (limited to 'subr/rtl_complex.subr')
-rw-r--r-- | subr/rtl_complex.subr | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/subr/rtl_complex.subr b/subr/rtl_complex.subr index 41f0b2b4..01e373ea 100644 --- a/subr/rtl_complex.subr +++ b/subr/rtl_complex.subr @@ -87,6 +87,21 @@ rtl_filter_vars() { echo "${_vars}"; }; +rtl_get_cpu_count() { + local _line="" _ncpus=0 _rc=0 _sname="$(uname -s 2>/dev/null)"; _status=""; + case "${_sname}" in + Linux) if [ ! -e "/proc/cpuinfo" ]; then + _rc=1; _status="Error: /proc/cpuinfo non-existent."; + else while read -r _line; do + if rtl_match "${_line}" "processor*:"; then + : $((_ncpus+=1)); + fi; + done < /proc/cpuinfo; echo "${_ncpus}"; + fi; ;; + *) _rc=1; _status="Error: unknown platform \`${_sname}'."; ;; + esac; return "${_rc}"; +}; + rtl_get_var_unsafe() { local _vname=""; if [ "x${1}" = "x-u" ]; then @@ -109,6 +124,15 @@ rtl_head() { echo "${_s}"; }; +rtl_is_newer() { + local _new_fname="${1}" _old_fname="${2}"; + if [ -n "$(find -name "${_new_fname}" -newer "${_old_fname}" 2>/dev/null)" ]; then + return 0; + else + return 1; + fi; +}; + rtl_kill_tree() { local _pid="${1}" _signal="${2:-TERM}" _pid_child="" _pids=""; if _pids="$(pgrep -P "${_pid}")"\ |