# 关于/usr/include/下各种unistd的区别

unistd是unix standard的简称，主要封装了一些glibc函数和系统调用相关的定义（个人理解）。具体参考这里：https://zh.wikipedia.org/wiki/Unistd.h

/usr/include/unistd.h  1

/usr/include/linux/unistd.h 2

/usr/include/asm/unistd.h  3

/usr/include/asm/unistd_32.h  4

/usr/include/asm/unistd_64.h 5

/usr/include/bits/unistd.h  6

1中include了6，如果编译时开了FORTIFY，那么会用6中的函数，对危险函数做一个wrapper。1 6 这些是和glibc有关的。

2中仅仅是include了3。3中根据OS的bits选择是4还是5。2 3 4 5 这些都是从kernel来的。

stackoverflow的介绍言简意赅：

linux/unistd.h actually points to asm/unistd.h, which in turn points to either asm/unistd_32.h or asm/unistd_64.h, which is where system call numbers are defined and presented to user space depending on the system's architecture. These come from the kernel.

bits/unistd.h is a collection of macros that augment unistd.h (mostly stuff to help prevent buffer overflows), which is conditionally included via:

/* Define some macros helping to catch buffer overflows.  */
#if __USE_FORTIFY_LEVEL > 0 && defined __extern_always_inline
# include <bits/unistd.h>
#endif
In essence, the only POSIX required header is in fact, just unistd.h, the rest are either extensions, or definitions from the kernel. So, just including unistd.h is all you have to worry about doing, everything you need will be pulled in depending on your architecture and whatever build options you've selected.

https://stackoverflow.com/questions/2948696/what-is-the-difference-between-the-various-unistd-h-under-usr-include-in-linux/2949262#2949262