在运行我的测试时,我遇到了一个valgrind错误:
==14280== Syscall param open(mode) contains uninitialised byte(s) ==14280== at 0x4111084: open64 (open64.c:42)并且open的返回值是-2
Errno设置为13 (Permission denied)
pathname缓冲区包含:
0x68 0x72 0x32 0x2E 0x66 0x61 0x0关于我的系统的信息:
$ ls -la drwxr-xr-x 7 rzetterberg zed 4096 Jul 4 13:56 . $ id uid=1000(rzetterberg) gid=1000(rzetterberg) groups=1000(rzetterberg), ... etc $ sudo file -Ls /dev/sda1 /dev/sda1: sticky Linux rev 1.0 ext3 filesystem data, UUID=XXXX (needs journal recovery) (large files) $ uname -a Linux xxxx 3.2.0-4-686-pae #1 SMP Debian 3.2.46-1 i686 GNU/Linux标题包括:
#include <stdio.h> #include <stdint.h> #include <assert.h> #include <errno.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h>我不明白如何mode可以有单位字节和为什么我得到一个Permission denied 。 对我来说这似乎很奇怪!
fd = open(pathname, O_WRONLY | O_LARGEFILE | O_APPEND | O_CREAT);When running my tests I encounter a valgrind error:
==14280== Syscall param open(mode) contains uninitialised byte(s) ==14280== at 0x4111084: open64 (open64.c:42)And the return value of open is -2
Errno is set to 13 (Permission denied)
The pathname buffer contains:
0x68 0x72 0x32 0x2E 0x66 0x61 0x0Info about my system:
$ ls -la drwxr-xr-x 7 rzetterberg zed 4096 Jul 4 13:56 . $ id uid=1000(rzetterberg) gid=1000(rzetterberg) groups=1000(rzetterberg), ... etc $ sudo file -Ls /dev/sda1 /dev/sda1: sticky Linux rev 1.0 ext3 filesystem data, UUID=XXXX (needs journal recovery) (large files) $ uname -a Linux xxxx 3.2.0-4-686-pae #1 SMP Debian 3.2.46-1 i686 GNU/LinuxHeaders included:
#include <stdio.h> #include <stdint.h> #include <assert.h> #include <errno.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h>I don't understand how mode can have unitialised bytes and why I'm getting a Permission denied. It seems very strange to me!
最满意答案
如果您提供O_CREAT标志为open() ,则必须提供第三个参数。 这是一个整数,表示应用于创建文件的权限(由当前umask修改)。
If you supply the O_CREAT flag to open(), you must supply a third argument. This is an integer which represents the permissions to apply to the created file (modified by the current umask).
更多推荐
发布评论