在 Ubuntu 10.04 上编译时未声明 PATH_MAX

发布于 2024-10-04 04:04:51 字数 186 浏览 8 评论 0原文

我正在尝试在 Ubuntu 10.04 中为 8.04 编译一个 C 程序。它失败是因为我们使用了 PATH_MAX 和其他应在 limits.h 中定义的常量。根据各种资源,它应该是 POSIX 兼容 C 库的一部分。

这是 Ubuntu 10.04 中的错误还是有解决此问题的正确方法?

I am trying to compile a C program in Ubuntu 10.04 made for 8.04. It fails because we have used PATH_MAX and other constants that should be defined in limits.h. According to various resources, it should be part of a POSIX compatible C library.

Is this a bug in Ubuntu 10.04 or is there a proper way of solving this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野味少女 2024-10-11 04:04:51

POSIX 定义了许多这样的限制是可选的。如果 limits.h 中未定义限制 FOO,则意味着系统可能没有此类限制,或者该限制可能会在运行时发生变化,或者取决于其所应用的路径名。在这些情况下,您可以使用 pathconffpathconfsysconf 函数以及 _PC_*_SC_* 宏,如:

path_max = pathconf("/", _PC_PATH_MAX);

或:

page_size = sysconf(_SC_PAGE_SIZE);

不幸的是,GNU(GNU C 库)将许多限制定义为运行时变量,而实际上它们在 Linux 上是恒定的,在某些人(在我看来,非常误导)希望有一天限制将被取消,应用程序将立即能够利用限制的取消。然而,对于应用程序和内核的鲁棒性来说,只要它们足够大(如 Linux 限制),设置固定限制实际上会更好。

POSIX defines many such limits to be optional. If a limit FOO is not defined in limits.h, it means the system may have no such limit or the limit might vary at runtime or dependent upon the pathname it's applied to. In these cases, you use the pathconf, fpathconf, or sysconf functions and the _PC_* and _SC_* macros, as in:

path_max = pathconf("/", _PC_PATH_MAX);

or:

page_size = sysconf(_SC_PAGE_SIZE);

Unfortunately GNU (the GNU C library) defines many limits as runtime-variable when they're actually constant on Linux, in some (in my opinion, very misguided) hope that someday the limits will be removed and applications will immediately be able to take advantage of the removal of the limits. However, for application and kernel robustness, it's actually much better to have fixed limits as long as they're sufficiently large (as the Linux limits are).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文