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.
Questions tagged [lseek]
81 questions
0
votes
1 answer
lseek SEEK_END doesn't get last character
FIXED (SEE FINAL EDIT)
I am trying to get the last character of a file using lseek and read. The file I'm opening is this (no '\n' at the end):
the quick brown fox jumps over the lazy dog
I want the output to be 'd'. For some reason, doing…

Ryoma
- 11
- 5
0
votes
1 answer
lseek()'s offset and large block devices
For fun and as practice I tried to create a program that writes a bit pattern to a specific sector of a hard drive. My idea was to be able to supply a specific sector number (in LBA format) and have the program try to write to it and then read from…

neko
- 3
- 2
0
votes
0 answers
Does lseek in C provide some modification in data structures?
I know that open and close modify the OS general file table, process file table and inode table.
But what does lseek modify and how??

tiziocaio
- 3
- 5
0
votes
1 answer
lseek beyond EOF on an MTD
The manual page for lseek() says:
lseek() 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…

ZeppRock
- 988
- 1
- 10
- 22
0
votes
1 answer
Store strings in binary file without them being overwritten
So first of all, here is the relevant part of my code and I will then proceed to explain.
scanf("%d", &option);
fflush (stdin);
//Insert
if(option==1){
printf("enter name\n");
fgets(name,MAX_SIZE,stdin);
…

riverwastaken
- 285
- 6
- 19
0
votes
1 answer
mmap file not syncing
Hello I am trying to back up a vector by mmap.
However, I have tried msync then munmap but it doesn't work. After I write to the (char *) then munmap the file, the file has no content. The mmap file is also created with flag MAP_SHARED. Would really…

Erin
- 83
- 1
- 9
0
votes
1 answer
Reading and printing last N characters
I have a program that I want to use to read a file and output its last N characters (could be 50 or whatever that I have coded). From my piece of code, I get output that is question marks in diamond boxes,(unsupported unicode?)
I'm using lseek to…

JackPeters667
- 3
- 5
0
votes
1 answer
Write() to file descriptor disappearing when read()
So I'm working on the server side of my program right now, and I want to do the following:
1) open a file in read/write mode
2) append a word (WORD) to the end of the file
3) [I believe I have all of this part down already] open a pipe, create a…

purpledots
- 77
- 1
- 1
- 8
0
votes
0 answers
Memory mapped files used as logging program data in c
I'm trying to log the activity of my program using memory mapped files. The file is created fine, and i can't write to it as well, however i've encountered two problems:
When i re run the program, the file either resets or is written on top of
The…

jonelearn
- 13
- 2
- 9
0
votes
1 answer
assembly Move File Pointer
How to calculate CX:DX value?
I don't know what that means
somebody help me

송영조
- 71
- 1
- 1
- 4
0
votes
0 answers
fseek performance drop over NFS
I'm a Matlab user analyzing electrophysiology data.
Recently I found that fseek over NFS shared file is slow if relative offset (distance in bytes from the current position to the new position) is more than around 10^5 or 10^6.
I checked this with…

Masao
- 1
- 1
0
votes
1 answer
DIfference between C and C++ ( lseek() )
I am trying to redesign the API of my previous project that I've worked on it, which was written in C, in a way that it can be used in an application written in C++ language.
I was using in C language lseek() for chasing table, pages etc.
My…

N007
- 79
- 10
0
votes
1 answer
Lseek SEEK_END not working?
I'm working on a C program with joysticks and I'd like to get last event which is as the last line of js0 file. I'm trying to move my cursor before the last element but it doesn't seem working. Any idea why?
int fd = open ("/dev/input/js0",…

DaSim
- 363
- 5
- 10
0
votes
1 answer
Trying to read from a file using file descriptor prints numbers and slashes to console
I am trying to write a simple program that reads a file by encapsulating functions like open, lseek, pread.
My file for test contains:
first second third forth fifth sixth
seventh eighth
my main function that tries to read 20 bytes with offset 10…

Eyzuky
- 1,843
- 2
- 22
- 45
0
votes
2 answers
How to change some letter in a file with the buffer and lseek
i'm having some trouble using lseek and the buffer for an assigment. The objective is to read a file and change every letter 'a' to a '?'. I'm running some minor programs to understand how the functions and buffer works and i'm having some trouble..…

César Pereira
- 249
- 4
- 17