当前位置: 首页 > news >正文

深圳怎么做网站外链网站推荐几个

深圳怎么做网站,外链网站推荐几个,镇巴作风建设网站,广东新闻频道直播1.引言 为了学习linux系统下的app开发&#xff0c;记载了学习文件编程的笔记 2.open函数 功能 打开一个文件 头文件 #include<sys/stat.h> #include<fcntl.h> 函数形式 int open(const char* pathname, int flags, mode_t mode); 返回值 如果调用成功&#xff0c…

1.引言

为了学习linux系统下的app开发,记载了学习文件编程的笔记

2.open函数

功能

        打开一个文件

头文件

        #include<sys/stat.h> #include<fcntl.h>

函数形式

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

返回值

        如果调用成功,则返回文件描述符号,标识文件资源,后续会使用。 如果调用出错,则会返回-1

参数

        pathname:打开的文件名(含路径)。

        flags: 文件访问模式的bit mask。

        mode: 文件权限模式

3. 使用案例

copy文件的案例

文件如下,名字:copy_file.c

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h> 
#include <errno.h>#define BUFFER_SIZE 1024 int main(int argc,char *argv[]) 
{ int from_fd,to_fd; int bytes_read,bytes_write; char buffer[BUFFER_SIZE]; char *ptr; //参数防卫,命令选项必须输入3个参数if(argc!=3) { fprintf(stderr,"Usage:%s fromfile tofile/n/a",argv[0]); exit(1); } //以只读的方式打开第一个参数(文件路径)if((from_fd=open(argv[1],O_RDONLY))==-1) { //打开失败fprintf(stderr,"Open %s Error:%s/n",argv[1],strerror(errno)); exit(1); } // Constant Octal	value	Permission	bit
// S_ISUID	04000	Set-user-ID
// S_ISGID	02000	Set-group-ID
// S_ISVTX	01000	Sticky
// S_IRUSR	0400	User-read
// S_IWUSR	0200	User-write
// S_IXUSR	0100	User-execute
// S_IRGRP	040	    Group-read
// S_IWGRP	020	    Group-write
// S_IXGRP	010	    Group-execute
// S_IROTH	04	    Other-read
// S_IWOTH	02	    Other-write
// S_IXOTH	01	    Other-execute// Flag         describtion
// O_RDONLY     Open for reading only v3
// O_WRONLY     Open for writing only v3
// O_RDWR       Open for reading and writing v3
// O_CLOEXEC    Set the close-on-exec flag (since Linux 2.6.23) v4
// O_CREAT      Create file if it doesn’t already exist v3
// O_DIRECT     File I/O bypasses buffer cache
// O_DIRECTORY  Fail if pathname is not a directory v4
// O_EXCL       With O_CREAT: create file exclusively v3
// O_LARGEFILE  Used on 32-bit systems to open large files
// O_NOATIME    Don’t update file last access time on read() (since Linux 2.6.8)
// O_NOCTTY     Don’t let pathname become the controlling terminal v3
// O_NOFOLLOW   Don’t dereference symbolic links v4
// O_TRUNC      Truncate existing file to zero length v3
// O_APPEND     Writes are always appended to end of file v3
// O_ASYNC      Generate a signal when I/O is possible
// O_DSYNC      Provide synchronized I/O data integrity (since Linux 2.6.33) v3
// O_NONBLOCK   Open in nonblocking mode v3
// O_SYNC       Make file writes synchronousif((to_fd=open(argv[2],O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR))==-1) { fprintf(stderr,"Open %s Error:%s/n",argv[2],strerror(errno)); exit(1); } while(bytes_read=read(from_fd, buffer, BUFFER_SIZE)) { if((bytes_read==-1)&&(errno!=EINTR)) {break;}    else if(bytes_read > 0) { ptr = buffer; while(bytes_write=write(to_fd,ptr,bytes_read)) { if((bytes_write==-1)&&(errno!=EINTR))break; else if(bytes_write==bytes_read)break; else if(bytes_write>0) { ptr+=bytes_write; bytes_read-=bytes_write; } } if(bytes_write==-1)break; } } close(from_fd); close(to_fd); exit(0); 
} 

编译用Makefile

TARGET := app
#src file
SRC := copy_file.call:$(TARGET)@echo "make successfull"$(TARGET): $(SRC)@echo $(SRC)gcc  $^ -I. -o $@clean:rm $(TARGET).PHONY:all,clean

ubuntu系统下使用gcc编译通过,运行实例如下

终端命令:./app copy_file.c a.c
结果展示命令: ll
total 41
drwxrwxrwx 1 root root  4096 May 25 23:05 ./
drwxrwxrwx 1 root root     0 Mar  8 21:31 ../
-rwxrwxrwx 1 root root  3165 May 25 23:05 a.c*    --->(复制成功的新文件)
-rwxrwxrwx 1 root root 17056 May 25 23:04 app*
-rwxrwxrwx 1 root root  3165 May 25 23:04 copy_file.c*

http://www.sczhlp.com/news/35370/

相关文章:

  • 河南怎么样做网站周口网站建设公司
  • 芜湖哪些公司做公司网站讯展网站优化推广
  • 网站栏目及内容网站seo培训
  • 重庆做的好的房产网站好百度网盘优化
  • 做收藏品的网站长沙seo优化哪家好
  • 如何用frontpage做网站长春百度seo排名
  • 做商城网站那个好怎么在百度上发布广告
  • 高新园区规划建设局网站百度帐号登录入口
  • 网站文件怎么做网络营销推广的要点
  • 高端开发网站哪家专业百度热搜榜历史
  • 代理做网站的合同十大营销策划公司排名
  • 网站开发入股合作分配比例网店推广有哪些
  • 线上平台怎么推广广州关键词优化外包
  • 网站插件代码大全武汉网站推广
  • 团购网站 备案问题seo关键词排名优化方法
  • 怎么做能打不开漫画网站网站点击排名优化
  • 北京通信管理局网站备案处营销活动推广策划
  • 机加工网站全国疫情高峰感染进度查询
  • 成都专业网站建设百度一下百度搜索官网
  • wordpress手机端主题插件下载失败洛阳seo网站
  • 瑞安 网站建设培训网站怎么才能被百度收录
  • 广州h5网站开发竞价
  • 插画素材网站有哪些百度首页 百度一下
  • 给国外做网站怎样申请网站
  • 网站建设对图片有哪些要求优化网站排名费用
  • 邢台 网站建设手机百度网址大全首页
  • 做鸭加盟最火的网站百度地图关键词优化
  • 帮别人做网站服务器如何做企业网页
  • 做网站的哪家比较好宁德市政府
  • 建个网站费用离我最近的广告公司