greiman / SdFat-beta

Beta SdFat for test of new features
MIT License
166 stars 62 forks source link

Moving cursor position with O_APPEND #68

Open s4CD opened 3 years ago

s4CD commented 3 years ago

When I try to write to a file with the append flag none of the cursor functions seem to work. I couldn't find much of a clear description of how to use them but they all function as I expected without append. seekSet, seekEnd, and seekCur have no effect. curPosition accurately shows me at position zero, and my file writes from position zero, despite docs saying append starts with cursor at end of file and without the other functions you can't move so append is not possible.

I fear I'm overlooking something as this seems like an important feature and I don't see any other reports so I may be doing something wrong, but since it works without the append flag I thought I should post it.

greiman commented 3 years ago

I can't help unless you post code.

O_APPEND does not position the file until you call write. * O_APPEND - If set, the file offset shall be set to the end of the file prior to each write.

The following will always append to the file when write is called. file.open("test.txt", O_RDWR|O_CREAT|O_APPEND);

You may want this flag. It is more efficient since seek is only called at open time. * O_AT_END - Set the initial position at the end of the file.