Failure in file seek

133 views
Skip to first unread message

Nikhilesh Susarla

unread,
Apr 8, 2024, 4:33:30 PM4/8/24
to golang-nuts
I wanted to seek around a file by opening it using read-only, but then I get this error called "Invalid argument"

https://go-review.googlesource.com/c/go/+/14881

I read the above link and they say it is not supported to seek around. I tried direct lseek in c language and it failed with same. 

Is there any way ? 

Thank you

Kurtis Rader

unread,
Apr 8, 2024, 4:43:11 PM4/8/24
to Nikhilesh Susarla, golang-nuts
The issue you linked to involves files opened for writing with the O_APPEND flag. That isn't relevant if you opened the file read-only. Please show us the code you wrote.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/cf1f423c-6ba7-4b98-b37c-ac53758dcbc4n%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Ian Lance Taylor

unread,
Apr 8, 2024, 4:44:48 PM4/8/24
to Nikhilesh Susarla, golang-nuts
What that link says is that if you open the file with O_APPEND then you can't Seek.  Are you opening with O_APPEND?

If not you will need to provide more information, such as a small program that demonstrates the problem.

Ian

Nikhilesh Susarla

unread,
Apr 8, 2024, 5:24:16 PM4/8/24
to golang-nuts

I did write with ReadOnly also and it failed. 

Sorry, I assumed both Append and ReadOnly fails.

Bakul Shah

unread,
Apr 8, 2024, 5:57:00 PM4/8/24
to Nikhilesh Susarla, golang-nuts
>         offset, err := f.Seek(0, 10)

The second argument needs to be one of io.{SeekStart,SeekCurrent,SeekEnd} (0, 1 or 2).
go doc os.File.Seek

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Nikhilesh Susarla

unread,
Apr 8, 2024, 6:07:09 PM4/8/24
to golang-nuts
Thank you. I completely got both the programs wrong by interchanging the parameters.

Thank you for pointing it out.

Reply all
Reply to author
Forward
0 new messages