The function uses (size_t) -1 as its failure return.
(Of course, some of us think that's a case for using ssize_t as return type ...)