linux之creat函数解析
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash

·
creat函数完全可以被open函数替代:
open(pathname, O_WRONLY | O_CREAT | O_TRUNC, mode);
[lingyun@localhost create]$ vim creat.c
+ creat.c/*********************************************************************************
* Copyright: (C) 2013 fulinux<fulinux@sina.com>
* All rights reserved.
*
* Filename: creat.c
* Description: This file
*
* Version: 1.0.0(07/28/2013~)
* Author: fulinux <fulinux@sina.com>
* ChangeLog: 1, Release initial version on "07/28/2013 01:05:30 PM"
*
********************************************************************************/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PERM 0755
int main(void)
{
static char filename[] = "file.txt";
int fd;
fd = creat(filename,PERM);
if(fd < 0)
printf("[%s] create fail !!!\n",filename);
else
printf("[%s] open success !\n",filename);
exit(0);
}
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~/apue/creat/creat.c[+] CWD: /usr/local/src/lingyun/apue/creat Line: 17/33:18
"create.c" 33L, 869C written
[lingyun@localhost creat]$ gcc creat.c
[lingyun@localhost creat]$ ./a.out
[file.txt] open success !
[lingyun@localhost creat]$ ls
a.out creat.c file.txt




A beautiful web dashboard for Linux
最近提交(Master分支:1 个月前 )
186a802e
added ecosystem file for PM2 5 年前
5def40a3
Add host customization support for the NodeJS version 5 年前

新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。
更多推荐
所有评论(0)