Questions tagged [lseek]

A linux C API function that repositions the offset of the open file associated with the file descriptor to the argument offset according to the directive.

81 questions
1
vote
3 answers

return value of lseek()

I got confused about lseek()'s return value(which is new file offset) I have the text file (Its name is prwtest). Its contents are written to a to z. And, the code what I wrote is following, 1 #include 2 #include 3…
A.Cho
  • 571
  • 1
  • 6
  • 17
1
vote
1 answer

POSIX read() function does not read any bytes when lseek() is called

I have the following program #include #include #include #include #include int main(int argc, char* argv[]) { int fd; char buffer[100]; // open notes file fd =…
M F
  • 323
  • 1
  • 3
  • 15
1
vote
1 answer

mmap offset when using a struct

I've got this struct: typedef struct ip_row { sem_t row_lock; char row_name[NAME_SIZE]; char row_address4[NAME_SIZE]; // IPv4 address name char row_address6[NAME_SIZE]; // IPv6 address name } ip_row_t; I would like to use the struct…
qsorted
  • 51
  • 1
  • 7
1
vote
1 answer

C deleting parts of a large binary with lseek/read/write

My aim is to delete one ore more parts inside a binary file. I do this by only copying the needed parts to a second file. I have got two methods. The first one should append count bytes from File1 (with offset skip) to File2. void copyAPart(struct…
reencode
  • 33
  • 4
1
vote
1 answer

How to create files with holes using lseek?

I am learning, on how to create holes in files using lseek. This is the code that I have written thus far... #include #include #include #include #include #include int main() { int…
Swaroop
  • 1,219
  • 3
  • 16
  • 32
1
vote
0 answers

hard disk acces fseeko and fread vs lseek and read

is there any difference between using fseeko with fread vs lseek with read if I want to do Hard disk access ? My program checks for certain patterns on a raw harddisk (/dev/sdX). My program currently uses fseeko and fread. Platform is linux.
user2882307
1
vote
3 answers

Remove bytes from a file - c

How can I remove from a file, bytes from i to i. Example: "today me and my roomates went to a party"; if i = 3, I want to remove the 3rd byte, the 6th, the 9th... etc I tried using lseek and fgets but I didn't know how to do the whole thing. What…
MathMe
  • 101
  • 5
  • 13
1
vote
1 answer

lseek() on /dev/watchdog causes system crash

I'm new to this forum and I would like to ask the experts a question. I wrote the following program ( part of a bigger thing, but this is the code that causes me trouble) #include #include int main() { int fd; fd =…
Alex
  • 635
  • 6
  • 15
0
votes
1 answer

What if lseek() pass beyond the beginning of the file?

As the documentation highlighted, the lseek() function allows the file offset to be set beyond the end of the file. But what if I set it beyond the beginning of the file? Let the current offset be 5, What will actually happen when I try lseek(fd,…
Harry
  • 21
  • 3
0
votes
1 answer

How can I use lseek() to get to the midpoint of a file?

So I have a textfile with 10 words with 5 characters each, and I want to get to the midpoint of that file without having to call read multiple times so I wanted to use lseek. As I understand, lseek only uses the SET, CUR, and END flags. So If I have…
0
votes
0 answers

List all the hole and data segments in a sparse file

I am trying to implement a program which can print all the hole and data segments in a regular sparse file using lseek(2) and its arguments SEEK_DATA and SEEK_HOLE, which is something like: $ ./list_hold_and_data_segs sparse_file This file has 100…
Steve Lau
  • 658
  • 7
  • 13
0
votes
0 answers

the return value of file operations

I tried to use the lseek function in the next program to read from any position. Although the return value of close () is specifically ignored in the event of an error (where we should probably just omit closing the descriptor and let the operating…
Lorand
  • 29
  • 4
0
votes
2 answers

compilation warnings in the program that uses lseek for reading

My program opens a read-write file with the append flag to read from any position specified with lseek. But I'm getting some compilation warnings and I'd like you to help me remove them. What is the problem? #include "lab.h" #include…
user19013657
0
votes
1 answer

fopen() returns NULL but open() syscall returns proper file descriptor?

I've been trying to run this very simple C code on Ubuntu 20.04LTS #include #include int main() { FILE *f; f=fopen("tree.txt","r"); if(f==NULL){ perror("fopen"); exit(1); } …
Mor010101
  • 9
  • 2
0
votes
2 answers

Finding a string in a file using the lseek command in C

I have a file storing data of students in the following order: id (space) name (space) address Below is the content of the file: 10 john manchester 11 sam springfield 12 samuel glasgow Each data is stored in a newline. I want to search the…