1

I have a sparse file in linux and I wish to seek to a location containing data within that file. In C unistd.h gives me access to the constant SEEK_DATA for the whence flag of lseek. However I can't find an equivalent constant in golang.

I've examined "io", "os", "x/sys/unix" and did a text search through the golang standard library.

Do I just have to hard code the value in?

Q the Platypus
  • 825
  • 1
  • 7
  • 13
  • I can just pass "3" in the whence flag of Seek but I would rather have a library constant I could refer to for all the reasons you prefer to use constants rather then littering your code with magic numbers. – Q the Platypus May 23 '19 at 07:52
  • I found a related question with an in-depth answer that should help you. Marked this as a duplicate. – Jonathan Hall May 23 '19 at 07:55
  • That is not the same question. The linked question is talking about the operation of sparse files while I'm asking about the constants for working with sparse files. The fact that the author has to also add the constants themselves does suggest that the constants are not available however it address the question I have given here. – Q the Platypus May 23 '19 at 07:59
  • Yes, I know it's not the same question. But the answer answers this one--and that's how duplicates are defined here, as indicated by the automatic text at the top of this question now: "This question already has an answer here:" – Jonathan Hall May 23 '19 at 08:00
  • Its a strange definition of duplicate and seems to be contradicted by the "This question has been asked before and already has an answer." under it. Seems like doing it this way would undermine the efforts to create useful question-answer pairs. Well I got my answer anyway. – Q the Platypus May 23 '19 at 08:08
  • It actually makes good sense. It would _not_ make sense to have to provide an identical answer here for your question. This would typically lead to scattered answers and information, which is hard to find across the site that's difficult to search. It _does_ makes sense to provide a link from this question to another that has the same answer. This leads to the best info all being concentrated in one location, and an easy-to-search site. – Jonathan Hall May 23 '19 at 08:11

0 Answers0