[英]Wrong O_CREAT definition
我包括以下標題:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
我的open("file", O_CREAT || O_RDWR)
將 errno 設置為ENOENT 。 在 gdb 我看到這個:
Breakpoint 1, xxx() at xxx.c:130
130 fd = open("file", O_CREAT || O_RDWR);
(gdb) s
__libc_open64 (file=0x55555555604e "file", oflag=1) at ../sysdeps/unix/sysv/linux/open64.c:37
37 ../sysdeps/unix/sysv/linux/open64.c: No such file or directory.
(gdb)
我看到了這個答案: 系統調用“打開”無法創建帶有 O_CREAT 標志的文件,這似乎很可能,但是我的O_CREAT被定義為 0x40 和O_RDWR為 0x2,這是谷歌最受歡迎的選擇(我嘗試將O_CREAT設置為 0x100,但它沒有幫助)。
有沒有辦法找出我的 open() 期望的價值是什么?
您需要使用包含位或運算符|
,帶着你的旗幟。 邏輯或運算符||
, 當被視為數值時,將始終等於 1 或 0。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.