首页 > 其他分享 >系统调用IO-11-read,write,lseek及mycpy的实现

系统调用IO-11-read,write,lseek及mycpy的实现

时间:2023-06-14 22:25:42浏览次数:32  
标签:11 lseek read bytes count file offset

1. 概述

read

NAME
       read - read from a file descriptor

SYNOPSIS
       #include <unistd.h>
       //从fd中读,读到buf中去,读count个字节
       ssize_t read(int fd, void *buf, size_t count);

DESCRIPTION
       read() attempts to read up to count bytes from file descriptor fd into the buffer starting at buf.

       If  count  is  zero, read() returns zero and has no other results.  If count is greater than SSIZE_MAX, the result is unspeci‐
       fied.

RETURN VALUE
       //如果成功,那么返回成功读取到的字节数;如果读到文件尾了,那么返回的是0个字节
       On success, the number of bytes read is returned (zero indicates end of file),
       //失败,返回-1,
       On error, -1 is returned, and errno is set appropriately. 

write

NAME
       write - write to a file descriptor

SYNOPSIS
       #include <unistd.h>
       //将buf中的内容,写到fd中去,数据的个数为count个字节
       ssize_t write(int fd, const void *buf, size_t count);

DESCRIPTION
       write() writes up to count bytes from the buffer pointed buf to the file referred to by the file descriptor fd.
RETURN VALUE
       On success, the number of bytes written is returned (zero indicates nothing was written).  On error, -1 is returned, and errno
       is set appropriately.

lseek

NAME
       lseek - reposition read/write file offset

SYNOPSIS
       #include <sys/types.h>
       #include <unistd.h>

       off_t lseek(int fd, off_t offset, int whence);

DESCRIPTION
       The  lseek()  function  repositions  the offset of the open file associated with the file descriptor fd to the argument offset
       according to the directive whence as follows:

       SEEK_SET
              The offset is set to offset bytes.

       SEEK_CUR
              The offset is set to its current location plus offset bytes.

       SEEK_END
              The offset is set to the size of the file plus offset bytes.

       The lseek() function allows the file offset to be set beyond the end of the file (but this does not change  the  size  of  the
       file).   If  data  is later written at this point, subsequent reads of the data in the gap (a "hole") return null bytes ('\0')
       until data is actually written into the gap.

RETURN VALUE
       Upon successful completion, lseek() returns the resulting offset location as measured in bytes from the beginning of the file.
       Otherwise, a value of (off_t) -1 is returned and errno is set to indicate the error.

 

标签:11,lseek,read,bytes,count,file,offset
From: https://www.cnblogs.com/-glb/p/17481504.html

相关文章

  • 分散输入和集中输出------readv() 、 writev()
    参考:https://blog.csdn.net/zhizhengguan/article/details/117173049//功能:将数据从文件描述符读到分散的内存块中,即分散读。ssize_treadv(intfd,conststructiovec*iov,intiovcnt);//iovcnt代表选择iov中的几块内存,而不是选择第几块内存//功能:将多块分散的内存数......
  • Win11 更改文件资源管理器中列的大小
    一、更改列的宽度  将鼠标移到“名称”一栏,鼠标右键点击然后出现新的弹窗,再点击其他: 修改“选中列的宽度”值为合适值后点击确定,然后就可以看到效果。二、保存设置 点击“查看更多(...)”,再点击“选项”,出现新的弹窗: 先点击“查看”,然后点击“应用到文件夹”,最后点......
  • 【Netty】Netty部分源码分析(启动流程,EventLoop,accept流程,read流程)
    源码分析Netty源码中调用链特别长,且涉及到线程切换等步骤,令人头大:)1启动剖析我们就来看看netty中对下面的代码是怎样进行处理的//1netty中使用NioEventLoopGroup(简称nioboss线程)来封装线程和selectorSelectorselector=Selector.open();//2创建NioServerSo......
  • 11-指令流水
    三、指令周期一、如何提高机器速度提高访存速度高速芯片Cache多体并行提高I/O和主机之间的传送速度中断DMA通道I/O处理机多总线提高运算速度高速芯片改进算法快速进位链提高整机处理能力高速器件改进系统结构,开发系统的并行性二、系统的并行性并行的概念......
  • 1111
    classGet_gradient_nopadding(nn.Module):def__init__(self):super(Get_gradient_nopadding,self).__init__()kernel_v=[[0,-1,0],[0,0,0],[0,1,0]]kernel_h=[[0,0,0],......
  • Dapr v1.11 版本已发布
    Dapr是一套开源、可移植的事件驱动型运行时,允许开发人员轻松立足云端与边缘位置运行弹性、微服务、无状态以及有状态等应用程序类型。Dapr能够确保开发人员专注于编写业务逻辑,而不必分神于解决分布式系统难题,由此显著提高生产力并缩短开发时长。Dapr是用于构建云原生应用程序的开......
  • WPF在win10/11上启用模糊特效 适配Dark/Light Mode
    先看效果图win11:win10: 大佬们已经总结了许多在WPF上开启亚克力效果的方法,本文只是做一些填坑和适配工作.正文开始先来看看部分版本Windows的模糊效果和我的适配方案:1).早期Windows10:SetWindowCompositionAttribute方法参照:在Windows10上为WPF窗口添加模糊特......
  • POJ2117 Electricity 题解 tarjan点双连通分量 割点
    题目链接:http://poj.org/problem?id=2117题目大意:给定一个由\(n\)个点\(m\)条边构成的无向图,请你求出该图删除一个点之后,连通块最多有多少。解题思路:tarjan,判断\(u\)的子节点有几个\(v\)满足\(low[v]\gedfn[u]\)就是答案,但是同时如果\(u\)不是这个dfs树的根节......
  • win11更改鼠标右键菜单栏
    **右键菜单改回Win10(展开)**1.新建记事本:(格式为.txt)2.填写脚本内容regadd"HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"/f/vetaskkill/f/imexplorer.exe&startexplorer.exe3.保存文件,记事本后缀.txt改为.bat确定4.......
  • 2015年11月Xcode7.1(7B91b)打包发布苹果iOS应用指南
    2015年11月Xcode7.1(7B91b)打包发布苹果iOS应用指南 第1步:配置项目的开发授权证书(图1)如图1,选择TARGETS下的项目名称。(图2)如图2,选择BuildSettings,然后找到ProvisioningProfile. (图3)如图3,选择distribution的开发授权证书。这个distribution的开发授权证书来自苹果开发者后台配置......