zmodload zsh/stat

typeset -gA zsv_fd_counts
local -A ftypes seen
local key fdlink fddest

zsv_fd_counts=( )

ftypes=(  # convert hex type to a word
	C  socket
	c  socket
	A  link
	a  link
	8  file
	6  block
	4  dir
	2  char
	1  pipe
)

for fdlink in "$@"; do
	fddest=$(zstat -L +link $fdlink) || continue
	(( $+seen[$fddest] )) && continue
	case $fddest in
		(/dev/null) 
			zsv_fd_counts[null]=$(( ${zsv_fd_counts[null]:-0} + 1 ))
			;;
		(/*)
			zstat -H s $fdlink || continue
			ftype=$(( [##16] $s[mode] >> 12 ))
			key=$ftypes[$ftype]
			zsv_fd_counts[$key]=$(( ${zsv_fd_counts[$key]:-0} + 1 ))
			;;
		(*)
			key=${fddest%%:*}
			zsv_fd_counts[$key]=$(( ${zsv_fd_counts[$key]:-0} + 1 ))
			;;
	esac
	seen[$fddest]=1
done
# vim: fileencoding=utf-8 ft=zsh noet sw=4 ts=4 sts=4