Updating/overwriting a file in c without creating a new or temp file -
i writing c code file handling have file format such below:
domain1:ip:port:id1,id2,id3 domain2:ip:port:id1,id2,
it should possible add new line new domains , should possible modify existing domains id's. , modify id's mean, number of id's can increased or decreased such in 1 operation should able add id4 domain1 in above example , in operation should able delete id1 of domain2 example.
so questions (thanks help):
i don't want create temp/new file , change name , delete old file. can read , write existing file? how can make secure? (i tried examples updating lines (using fwrite) see remove characters next line when add more characters such id4 , other strange characters in trials) ). sample code?
also later need use locking file, 1 should able read , write @ 1 time. suggestions/links appreciated.
thanks alot.
for appending file don't need temporary file or anything. if want replace characters equal amount of characters, don't need temporary file either.
but if want other modification changes size of contents need temporary buffer of kind. either temporary file or in-memory buffer.
Comments
Post a Comment