C

int open(const char *pathname, int flags, mode_t mode);

如果flags里面有O_CREAT (64),那么就要求有mode。如果没有mode,发现创建的文件permission是不确定的。虽然POSIX.1-2008中没有明确说undefined,但应该就是。

Python Style

#include <errno.h>

#include <stdio.h>

#include <sys/types.h>

#include <string.h>

int main(int argc, char* argv[]) {

int fd = open("xxx");

if ( fd == -1) {

static char* error;

error = strerror(errno);

printf("%d:%s\n", errno, error);

perror("open"); }

printf("%d\n", getppid());

printf("%d\n", getpid()); }

我想尝试这样的C缩进风格。把{}都写在行末,严格遵守缩进,就像Python一样。这个方案不需要任何别的程序(PythoidC),不需要代码额外的修改,用最简单的方法来实现Python风格的C。可惜Vim对这种代码进行缩进后会改变上面的样子。

这个实现更好。;)