# This file is part of bish-bosh. It is subject to the licence terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/raphaelcohn/bish-bosh/master/COPYRIGHT. No part of bish-bosh, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
# Copyright © 2014-2015 The developers of bish-bosh. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/raphaelcohn/bish-bosh/master/COPYRIGHT.


core_dependency_oneOf '*' ls stat

bishbosh_filesize_ls()
{
	# dateBitsAndFileName are not portable
	# permissions may have a '@' on the end if it is Mac OS X ls
	local permissions links uid gid size dateBitsAndFileName
	IFS=' ' read permissions links uid gid size dateBitsAndFileName <<-EOF
		$(ls -L -l -n "$1")
	EOF

	echo $size
}

bishbosh_filesize_GNUAndBusyBoxStat()
{
	stat -L -c '%s' "$1"
}

bishbosh_filesize_BSDStat()
{
	# Note  stat -x "$1"  makes output similar to GNU  stat "$1"
	stat -L -f '%z' "$1"
}

# Toybox stat is useless, because it doesn't have '-L' to resolve symlinks to actual files
# and so reports symlink size
bishbosh_filesize_ToyboxStat()
{
	stat -c '%s' "$1"
}