Skip to Content
LINUX系統程式設計 第二版
book

LINUX系統程式設計 第二版

by Robert Love
December 2013
Intermediate to advanced
496 pages
8h 57m
Chinese
GoTop Information, Inc.
Content preview from LINUX系統程式設計 第二版
34
|
第二章
int fd;
fd = open (file, O_WRONLY | O_CREAT | O_TRUNC, 0664);
if (fd ==
1)
/* 錯誤 */
creat() 函式
由於
O_WRONLY | O_CREAT | O_TRUNC
的組合太常見了,所以存在一個系統呼叫專門提供此
行為:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int creat (const char *name, mode_t mode);
沒錯,函式的名字漏掉了一個「e」。 Unix 的創造者 Ken Thompson 曾經
開玩笑地說,設計 Unix 的當時漏掉字母是他最大的遺憾。
下面是典型的
creat()
呼叫用法:
int fd;
fd = creat (filename, 0644);
if (fd ==
1)
/* 錯誤 */
其行為如同下面的程式碼:
int fd;
fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd ==
1)
/* 錯誤 */
多數 Linux 架構上,
3
creat()
是一個系統呼叫,儘管在用戶空間中實作它很容易:
int creat (const char *name, int mode)
{
return open (name, O_WRONLY | O_CREAT | O_TRUNC, mode);
}
3
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

優雅的SciPy|Python科學研究的美學

優雅的SciPy|Python科學研究的美學

Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9789862769812