user2978472
user2978472

Reputation: 41

Overwrite file content linux system call

I am able to append one file content to other using O_APPEND flag in "open" system call. but struggling a lot to overwrite the existing content.when I try opening the file with just O_WRONLY with out any flags its not overwriting the existing content. Can some please hep me in this?

Upvotes: 2

Views: 3026

Answers (1)

BadZen
BadZen

Reputation: 4265

Either add O_TRUNC (if you want to toss out all of the previous stuff), or seek the fd to 0 (if you want to "insert" over it, like an insert cursor). Be aware that you might not be able to see changes immediately - that's because of buffered I/O. You can use O_SYNC to make sure every write is flushed through. (Probably don't do that though.)

Upvotes: 4

Related Questions