作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是一个简单的演示:
#include <sys/stat.h>
#include <aio.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
#ifdef _SC_AIO_MAX
printf("_SC_AIO_MAX is defined\n");
if (sysconf(_SC_AIO_MAX) == -1)
{
printf("unsupported\n");
printf("_SC_AIO_MAX = %d\n", _SC_AIO_MAX);
printf("sysconf(_SC_AIO_MAX) = %d\n", sysconf(_SC_AIO_MAX));
}
#else
printf("_SC_AIO_MAX is undefined\n");
#endif
return 0;
}
输出:
_SC_AIO_MAX is defined unsupported _SC_AIO_MAX = 24 sysconf(_SC_AIO_MAX) = -1
现场演示:https://wandbox.org/permlink/7GDzyvEUgRwMHX95
如您所见,_SC_AIO_MAX
定义为 24
,但 sysconf(_SC_AIO_MAX)
返回 -1
>。根据man 3 sysconf
* If name corresponds to a maximum or minimum limit, and that limit is indeterminate, -1 is re‐
turned and errno is not changed. (To distinguish an indeterminate limit from an error, set er‐
rno to zero before the call, and then check whether errno is nonzero when -1 is returned.)
但是限制已经定义为24
,为什么sysconf仍然返回-1
?
最佳答案
_SC_AIO_MAX = 24
不是限制的值,而是您要访问的限制的标识符。
getconf(24) == -1
表示:
有错误(检查errno
以查看是否有错误);或
该限制是不确定的。
一些文档提到,在调用 getconf
之前,您应该将 errno
设置为 0
,以确保您可以区分这两种情况。
(2) 可能会在功能可用但已被禁用等情况下发生。
关于c - 为什么 _SC_AIO_MAX 定义明确,而 sysconf(_SC_AIO_MAX) 返回 -1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59168164/
这是一个简单的演示: #include #include #include #include #include #include #include #include #include
我是一名优秀的程序员,十分优秀!