当前位置:网站首页>C language lseek() function: move the read and write location of the file
C language lseek() function: move the read and write location of the file
2022-07-26 04:34:00 【___ Bozi mi pro】
Correlation function :dup, open, fseek
The header file :#include <sys/types.h> #include <unistd.h>
Defined function :off_t lseek(int fildes, off_t offset, int whence);
Function description :
Every open file has a read / write location , When a file is opened, its read / write position usually points to the beginning of the file , If you open the file as an attachment ( Such as O_APPEND), Then the read / write position will point to the end of the file . When read() or write() when , The reading and writing positions will increase ,lseek() It is used to control the reading and writing position of the file . Parameters fildes Describe a word for an open file , Parameters offset Is based on the parameter whence To move the displacement of the read-write position .
Parameters whence It's one of the following :
- SEEK_SET Parameters offset It's the new read-write location .
- SEEK_CUR Increase from the current reading and writing position offset Displacement .
- SEEK_END Point the read / write position to the end of the file and add offset Displacement . When whence The value is SEEK_CUR or SEEK_END when , Parameters offet Allow negative values .
Here are some special ways to use :
- To move the read / write position to the beginning of the file :lseek(int fildes, 0, SEEK_SET);
- To move the read / write position to the end of the file :lseek(int fildes, 0, SEEK_END);
- When you want to get the current file location :lseek(int fildes, 0, SEEK_CUR);
Return value : When the call is successful, the current read / write position will be returned , That is, how many bytes from the beginning of the file . If there is an error, return -1, errno Will store error codes .
Additional notes :Linux System not allowed lseek() Yes tty Device function , This action will make lseek() return ESPIPE.
边栏推荐
- Postman 导入curl 、导出成curl、导出成对应语言代码
- 人脸数据库收集总结
- 软考回顾及计划
- Li Kou daily question - day 42 -661. Picture smoother
- Solve the error string value: '\xf0\x9f\x98\xad',... 'for column' commentcontent 'at row 1
- MapReduce中分区数与ReduceTask个数关系比较
- Page pull-up refresh and pull-down loading
- 机器学习之桑基图(用于用户行为分析)
- The auxiliary role of rational cognitive educational robot in teaching and entertainment
- 第三篇如何使用SourceTree提交代码
猜你喜欢

嵌入式实操----基于RT1170 FreeRTOS实现CPU使用率统计(二十四)

An SQL server queries the latest records as of a certain date

UE4 two ways to obtain player control

FFmpeg 视频编码

Matlab drawing

Unable to find sygwin.s file during vscode debugging

MySQL - multi table query - Cartesian product sum, correct multi table query, equivalent connection and unequal connection, inner connection and outer connection

Wu Enda's machine learning after class exercises - linear regression

Acwing_ 12. Find a specific solution for the knapsack problem_ dp

Authentication Encyclopedia (cookies, sessions, tokens, JWT, single sign on), in-depth understanding and understanding of authentication
随机推荐
使用百度飞桨EasyDL完成垃圾分类
MySQL log classification: error log, binary log, query log, slow query log
Rotate array minimum number
[C language foundation] 13 preprocessor
[learning notes] agc041
Why is mongodb fast
数组排序1
Build a maker Education Laboratory for teenagers
数组排序3
mongoDB为什么快
Use Baidu PaddlePaddle easydl to complete garbage classification
Weights & Biases (二)
Comparison of the relationship between the number of partitions and the number of reducetask in MapReduce
Throttling anti shake function of JS handwritten function
Embedded practice -- CPU utilization statistics based on rt1170 FreeRTOS (24)
AWS Support Plan
1. Mx6u system migration-6-uboot graphical configuration
UE4 controls the rotation of objects by pressing keys
7、 Restful
10、 Interceptor