# Does FreeBSD support API which is better than POSIX?



## jronald (May 4, 2013)

Before learning FreeBSD, I have this question, because I don't feel very comfortable with the POSIX API. So does FreeBSD have its own API?


----------



## fonz (May 4, 2013)

Not really. There might be a few slight exceptions here and there and some additional calls exist that aren't specified in/by the POSIX standard, but essentially FreeBSD is POSIX compliant.


----------



## ta0kira (May 5, 2013)

I haven't had any serious problems running POSIX-compliant code, but here are some things to keep in mind:
The interpretation of POSIX can vary. For example, I had a problem running Linux code on FreeBSD that assumed a particular member order of struct flock. I was using a compound literal to initialize, so I had to change it to explicit member initialization.
There might be some differences in what's supported by a system call. For example, in FreeBSD you can't put an advisory lock (fcntl+F_SETLK) on a socket or pipe, but in Linux you can. There isn't anything in the documentation that says that; you just need to find out the hard way, or assume that it's not supported.
FreeBSD has the MAC framework that can change the expected behavior of file and process access. If it's enabled, it's possible to: 1) see a file in a directory but not be able to stat it; 2) not be able to access information about the parent (or a child) of the current process; 3) have a process running as root, yet not have access to certain files, processes, and system calls.
A process that's jailed won't have access to certain system calls related to mounting, auditing, kernel modules, etc.
In summary, allow for absolutely every system call to fail, even if it seems like it shouldn't fail (e.g. stating a file in a directory you can r-x,) and don't assume a POSIX-ambiguous behavior will be the same between operating systems.

Kevin Barry


----------

