mknod(2) 需要 FreeBSD 上的超级用户,用什么来代替?
我正在从 Linux 移植到 FreeBSD,并且遇到了 ::mknod() 失败并显示 errno:
[EINVAL] Creating anything else than a block or character spe-
cial file (or a whiteout) is not supported.
但我也看到它在手册页的前面指出:
The mknod() system call requires super-user privileges.
那么什么是一个可以在 Linux 和 FreeBSD 上工作的良好替代调用?
我的代码片段发生这种情况:
mode_t mode
= S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
if (::mknod(_resolvedName, mode, 0)) {
我的目标是创建一个具有正确权限的空文件。
I am porting from Linux to FreeBSD and have run into ::mknod() failing with errno:
[EINVAL] Creating anything else than a block or character spe-
cial file (or a whiteout) is not supported.
But I also see it states earlier on the man page:
The mknod() system call requires super-user privileges.
So what would be a good replacement call to use that will work on both Linux and FreeBSD?
My code snippet where this occurs:
mode_t mode
= S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
if (::mknod(_resolvedName, mode, 0)) {
My objective is to create an empty file with the correct permissions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据
mknod(2)
的 Linux 手册页:因此,您以这种方式使用它是不可移植的,并且不推荐。
然而,
open(2)
似乎具有您需要的功能,并且会创建一个可移植的大小为零的文件。它接受mode_t
类型的第三个参数,您可以使用该参数设置权限。According to the Linux man page for
mknod(2)
:So your use of it in this manner is non-portable and not recommended.
open(2)
, however, seems to have the functionality you need, and will create a file with zero size, portably. It accepts a third parameter of typemode_t
, with which you can set permissions.为什么不:
Why not: