standards/186028: incorrect return values for posix_fallocate()

Gennady Proskurin gpr at
Thu Jan 23 09:00:01 UTC 2014

>Number:         186028
>Category:       standards
>Synopsis:       incorrect return values for posix_fallocate()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-standards
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 23 09:00:00 UTC 2014
>Originator:     Gennady Proskurin
>Release:        FreeBSD 11.0-CURRENT
FreeBSD 11.0-CURRENT FreeBSD 11.0-CURRENT #0 r260472+743aa78(svn_head): Fri Jan 10 05:28:05 MSK 2014     gpr at  amd64
In case of error, posix_fallocate() should return error code itself, but in FreeBSD it returns -1 and sets errno.

Quote from standard:
    Upon successful completion, posix_fallocate() shall return zero; otherwise, an error number shall be returned to indicate the error.

Quote from freebsd man:
     If successful, posix_fallocate() returns zero.  It returns -1 on failure,
     and sets errno to indicate the error.

test program attached

Patch attached with submission follows:

#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>

int main()
	int ret;
	int err;

	errno = 0;
	ret = posix_fallocate(-1 /* emulate EBADF error */, 0, 1);
	err = errno;
	printf("return value : %i   strerror: %s\n", ret, strerror(ret));
	printf("errno        : %i   strerror: %s\n", err, strerror(err));


More information about the freebsd-standards mailing list