三、Linux系統程式設計-檔案和IO(一)檔案的開啟和關閉
阿新 • • 發佈:2019-01-26
檢視能開啟最大描述符的個數:ulimit -n#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <unistd.h> #define ERR_EXIT(m) \//巨集要求是一條語句,do while邏輯上是一條語句 do \ { \ perror(m); \ exit(EXIT_FAILURE); \ }while(0) int main() { umask(0); int fd; fd = open("aa.txt",O_WRONLY | O_CREAT | O_EXCL,0655); if (fd == -1) ERR_EXIT("open error"); printf("open succ\n"); close(fd); return 0; }