Index: portability.eclass =================================================================== RCS file: /var/cvsroot/gentoo-x86/eclass/portability.eclass,v retrieving revision 1.24 diff -u -B -r1.24 portability.eclass --- portability.eclass 4 Jan 2012 05:57:19 -0000 1.24 +++ portability.eclass 13 May 2013 11:00:33 -0000 @@ -132,6 +132,34 @@ done } +# @FUNCTION: estat +# @USAGE: <'%a'> +# @DESCRIPTION: +# Portable version of GNU stat -c. See GNU stat(1) manpage. +# Its usage is limited to format specifiers that are actually implemented in a +# portable way. +# It supports only one format specifier, meaning "$(estat '%a%b' file)" is not +# allowed but "$(estat '%a' file)$(estat '%b' file)" should be used instead. +# estat currently implements the following specifiers from GNU stat: %a. +estat() { + local stat_version="unknown" + if $(stat --help 2>&1 | grep -q GNU) ; then + stat_version="GNU" + fi + + local fmt=$1; shift + + case ${fmt} in + %a) + if [ "${stat_version}" = "GNU" ] ; then + stat -c "${fmt}" "$@" + else + find "$@" -maxdepth 0 -printf '%m' + fi;; + *) die "unhandled form";; + esac +} + _dead_portability_user_funcs() { die "if you really need this, please file a bug for base-system@gentoo.org"; } is-login-disabled() { _dead_portability_user_funcs; }