當我嘗試覆蓋現有文件時,出現「權限被拒絕」錯誤。 我注意到創建的文件具有「只讀」屬性集。當我手動取消設置時,我可以覆蓋文件。是否有一些我可以傳遞給open()的標誌,當我創建一個文件時它會自動取消設置?使用MinGW如何創建沒有隻讀文件屬性的文件?
下面是一個簡單的例子,說明了這個問題。第一次運行,但第二次產生「權限被拒絕」錯誤。
感謝, 扎克(新來的MingW/Windows 7中)
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
int main(int argc, char ** argv) {
int fid;
double data = 12.0;
if ((fid = open("junk.data", O_WRONLY | O_CREAT | O_BINARY)) == -1) {
printf("ERROR opening.\n\terror is:%s\n", strerror(errno));
return 1;
}
write(fid, &data, sizeof(double));
close(fid);
return 0;
}
我很確定我已經嘗試過這個(作爲第三個參數),但是我想我一定是用舊版本的可執行文件進行了測試。它現在似乎在工作。 -謝謝 – Zach 2011-04-01 18:22:22