`
Linpro
  • 浏览: 3264 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
最近访客 更多访客>>
社区版块
存档分类
最新评论

linux下文件操作函数小结(1)

阅读更多
一、不带缓存的文件I/O操作函数
----------------------------------------------------------------------------------
1.creat

Fuction:create a file.

Header file:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

Prototype:
int create(const char *pathname,mode_t mode);

Parameter:
pathname:the path of file.
mode:   S_I(R/W/X)(USER/GRP/OTH)
S_IRUSR:owner read right.
S_IWUSR:owner write right.
S_IXUSR:owner execute right.

S_IRGRP:group member ~
S_IWGRP:
S_IXGRP:

S_IROTH:others ~
S_IWOTH:
S_IXOTH:

Return value:
success:return 0
failed:return -1
----------------------------------------------------------------------------------
2.open

Function:open a exist file or create a new file.

Header file:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

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

Parameter:
pathname:the path of file.
flags:
O_RDONLY:read only mode.
O_WRONLY:write mode.
O_RDWR:read and write mode.
O_APPEND:add to file end mode.
O_TRUNG:clean file to zero.
O_CREAT:create file.
O_EXCL:together with O_CREATE,if file exist,error.

Return value:
success:return a integer(file descriptor).
failed:return -1.
----------------------------------------------------------------------------------
3.close

Fuction:close the file.

Header file:
#include <unistd.h>

Prototype:
int close(int fd);

Parameter:
fd:file descriptor.

Return value:
success: return 0
failed:return -1
----------------------------------------------------------------------------------
4.read

Fuction:read the file.

Header file:#include <unistd.h>

Prototype:
ssize_t read(int fd,void *buf,size_t count);

Parameter:
fd:file descriptor.
buf:a point to buffer.
count:bytes of content.

Return value:
success:return the number of bytes read.
failed:return -1.
----------------------------------------------------------------------------------
5.write

Fuction:write to a file descriptor.

Header file:#include <unistd.h>

Prototype:
ssize_t write(int fd, const void *buf, size_t count);

Parameter:
fd:file descriptor.
buf:a point to buffer.
count:the max number of bytes write in.

Return value:
success:the number of bytes written.
failed:-1.
----------------------------------------------------------------------------------
分享到:
评论

相关推荐

    LINUX操作系统(电子教案,参考答案)

    本章主要介绍了Linux的文件结构、目录结构,同时还介绍了链接,并用大量的实例形象生动地说明了Linux下各种文件的操作。 第4章:文本编辑。本章主要介绍了Linux下的文本编辑器,这是使用Linux的一些基本技能。学好本...

    Linux环境下段错误的产生原因及调试方法小结

    借此机会系统学习了一下,这里对Linux环境下的段错误做个小结,方便以后同类问题的排查与解决。 1. 段错误是什么 一句话来说,段错误是指访问的内存超出了系统给这个程序所设定的内存空间,例如访问了不存在的内存...

    linux网络编程-宋敬彬-part3

    第1章 Linux操作系统概述 2 1.1 Linux发展历史 2 1.1.1 Linux的诞生和发展 2 1.1.2 Linux名称的由来 3 1.2 Linux的发展要素 3 1.2.1 UNIX操作系统 4 1.2.2 Minix操作系统 4 1.2.3 POSIX 标准 4 1.3 ...

    linux网络编程-宋敬彬-part2

    第1章 Linux操作系统概述 2 1.1 Linux发展历史 2 1.1.1 Linux的诞生和发展 2 1.1.2 Linux名称的由来 3 1.2 Linux的发展要素 3 1.2.1 UNIX操作系统 4 1.2.2 Minix操作系统 4 1.2.3 POSIX 标准 4 1.3 ...

    操作系统课程设计-文件系统的模拟设计.doc

    流程图如图 1.4所示: (4)运行结果分析 程序结果如图1.5-1.7所示 图1.5 图1.6 图1.7 (5)设计小结 操作系统课程设计是本课程重要的实践教学环节。课程设计的目的,一方面使学生 更透彻地理解操作系统的基本概念和...

    Linux程序设计 第4版.haozip01

    3.1 linux文件结构 78 3.1.1 目录 79 3.1.2 文件和设备 79 3.2 系统调用和设备驱动程序 80 3.3 库函数 81 3.4 底层文件访问 82 3.4.1 write系统调用 82 3.4.2 read系统调用 83 3.4.3 open系统调用 84 3.4.4...

    Linux程序设计中文第4版.part1

     3.1 Linux文件结构8  3. 1.1 目录9  3. 1.2 文件和设备9  3.2 系统调用和设备驱动程序 80  3.3 库函数 81  3.4 底层文件访问 82  3.4.1 write系统调用 82  3.4.2 read系统调用 83  3.4.3 ...

    Linux程序设计 第4版.haozip02

    3.1 linux文件结构 78 3.1.1 目录 79 3.1.2 文件和设备 79 3.2 系统调用和设备驱动程序 80 3.3 库函数 81 3.4 底层文件访问 82 3.4.1 write系统调用 82 3.4.2 read系统调用 83 3.4.3 open系统调用 84 3.4.4...

    RED HAT LINUX 6大全

    1.5 小结 4 第2章 Red Hat系统的安装 5 2.1 准备,认真准备 5 2.2 安装Red Hat Linux 6 2.2.1 创建引导盘和辅助盘 6 2.2.2 不利用引导软盘进行安装 7 2.2.3 虚拟控制台 7 2.2.4 对话框 7 2.3 一步步地安装 7 2.3.1 ...

    Linux程序设计中文第4版.part2

     3.1 Linux文件结构8  3. 1.1 目录9  3. 1.2 文件和设备9  3.2 系统调用和设备驱动程序 80  3.3 库函数 81  3.4 底层文件访问 82  3.4.1 write系统调用 82  3.4.2 read系统调用 83 ...

    linux网络编程-宋敬彬-part1

    第1章 Linux操作系统概述 2 1.1 Linux发展历史 2 1.1.1 Linux的诞生和发展 2 1.1.2 Linux名称的由来 1.2 Linux的发展要素 3 1.2.1 UNIX操作系统 4 1.2.2 Minix操作系统 4 1.2.3 POSIX 标准 4 1.3 Linux与...

    嵌入式Linux C编程入门(第2版) PPT

    9.2 arm linux文件i/o系统概述 258 9.2.1 虚拟文件系统(vfs) 258 9.2.2 通用文件模型 259 9.2.3 arm linux的设备文件 264 9.3 文件i/o操作 265 9.3.1 不带缓存的文件i/o操作 265 9.3.2 标准i/o...

    Linux程序设计中文第4版.part3

     3.1 Linux文件结构8  3. 1.1 目录9  3. 1.2 文件和设备9  3.2 系统调用和设备驱动程序 80  3.3 库函数 81  3.4 底层文件访问 82  3.4.1 write系统调用 82  3.4.2 read系统调用 83 ...

    LINUX与UNIX SHELL编程指南(很全)

    1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 16 2.1.3 忽略某个目录 16 2.1.4 使用user和nouser选项 16 2.1.5 使用group和nogroup选项 16 2.1.6 按照更改...

    Linux shell编程指南

    1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 16 2.1.3 忽略某个目录 16 2.1.4 使用user和nouser选项 16 2.1.5 使用group和nogroup选项 16 2.1.6 按照更改...

    Linux与unix shell编程指南

    1.10 小结 13 第2章 使用find和xargs 14 2.1 find命令选项 14 2.1.1 使用name选项 15 2.1.2 使用perm选项 16 2.1.3 忽略某个目录 16 2.1.4 使用user和nouser选项 16 2.1.5 使用group和nogroup选项 16 2.1.6 按照更改...

    uClinux源代码中Make文件完全解析

    &lt;br&gt;目录: 前言 第1章 基于ARM的μClinux简介 1.1 嵌入式系统  1.2 嵌入式系统与Unux  1.3 Linux、μClinux与ARM  1.4 Make文件的学习实验环境  1.5 小结  1.6 习题 第2章 ...

    linux programming instances网络编程教程 附源代码

    为了适应不同读者的需要,本书从最基本的Linux系统操作到网络技术的基本理念,逐步深入至Linux/UNIX下具体的编程实践,结合大量具体实例和编程经验,为读者展现Linux平台下网络编程的魅力。 全书由13章组成,内容...

Global site tag (gtag.js) - Google Analytics