Per discussion with nickm, the `dir` argument should be a int rather than a signed char. Fixes bug #14764.