unix环境高级编程 FILE I/O笔记
来源:互联网 发布:性喜剧 知乎 编辑:程序博客网 时间:2024/05/23 10:52
/* * Default file access permissions for new files.
*/
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
FILE_MODE是在apue.h中定义的宏变量
文件所有者(owner)有读、写全新;文件组成员只读权限和其他用户只读
S_IRUSR等的header file为 sys/stat.h
S_IRUSR 00400 owner has read permission S_IWUSR 00200 owner has write permission S_IXUSR 00100 owner has execute permission S_IRWXG 00070 mask for group permissions S_IRGRP 00040 group has read permission S_IWGRP 00020 group has write permission S_IXGRP 00010 group has execute permission S_IRWXO 00007 mask for permissions for others (not in group) S_IROTH 00004 others have read permission S_IWOTH 00002 others have write permission S_IXOTH 00001 others have execute permission#include<fcntl.h>#include<sys/stat.h>#include<stdio.h>#include<stdlib.h>char buf1[]="abcdefghij";char buf2[]="ABCDEFGHIJ";#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)int main(void){ //file descriptor int fd; if((fd=creat("file.hole",FILE_MODE))<0) printf("create error\n"); if(write(fd,buf1,10)!=10) printf("buf1 write error\n"); /*offset now=10 */ if(lseek(fd,16384,SEEK_SET)==-1) printf("lseek error"); /*offset now =16384 */ if(write(fd,buf2,10)!=10) printf("buf2,write error\n"); /*offset now =16394 */ exit(0);}od -c file.hole
0000000 a b c d e f g h i j \0 \0 \0 \0 \0 \0
0000020 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
*
0040000 A B C D E F G H I J
0040012每一行输出的前七位为八进制表示40000表示成10进制 (40000)oct=4*(8^4)=2^14=16384
od command:
Write an unambiguous representation, octal bytes by default, of FILE to standard output. With more than one FILE argument, concatenate them in the listed order to form the input. With no FILE, or when FILE is -, read standard input
0 0
- unix环境高级编程 FILE I/O笔记
- unix环境高级编程 FILE I/O笔记
- UNIX环境高级编程笔记之高级I/O
- UNIX环境高级编程----文件I/O
- UNIX环境高级编程----标准I/O
- 《unix高级环境编程》文件I/O
- 《unix高级环境编程》文件I/O
- Unix环境高级编程---文件I/O
- UNIX环境高级编程--标准I/O
- 《unix高级环境编程》标准I/O——FILE对象
- 《unix高级环境编程》标准I/O——FILE对象
- UNIX环境高级编程--高级I/O(三)
- UNIX环境高级编程第十四章 高级I/O 总结
- 《UNIX环境高级编程》十四高级I/O读书笔记
- 《UNIX环境高级编程》笔记--无缓存I/O操作和标准I/O文件操作区别
- 《UNIX环境高级编程》笔记0--无缓存I/O操作和标准I/O文件操作区别
- 《UNIX环境高级编程》学习笔记之标准I/O库
- UNIX环境高级编程第三章文件I/O 读后笔记
- ajax发送get、post请求
- 初级linux中常遇到的问题整理
- (3)html列表
- Python开发——字符串format
- 在使用vector的push_back函数时,Release版下运行会出错的一个原因
- unix环境高级编程 FILE I/O笔记
- Observer(观察者)模式的代码演示
- FZOJ 2166 inversion 逆序数对 模拟
- 利用wait notify 实现线程互斥通知
- 《Java解惑》系列——01表达式之谜——谜题04:初级问题
- C++第8周(春)项目4 扩充String类
- 网络地址169开头的简单修复
- iOS内存管理
- 用中断方式在嵌入式操作系统μC/OS-Ⅱ上实现多任务通信