Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shrink Files in C?

Status
Not open for further replies.

Jumpertka

Programmer
Feb 3, 2005
1
AT
Does anyone know, how I can shrink a file in C.
Without copying into a buffer an recopying or something like that. Only open the file, make a cut on a position.
Is there a way in C?
 
It's not a C topic: it's OS function. For example, MS Windows can't truncate files in so manner, but IBM MVS can do it.
Accordingly no such function(s) in C Standard library.
Portable code must do this op vith rewriting a new file then renaming.
Luckily for us, it's the most safe method too...
 
POSIX specifies truncate and ftruncate for this operation.
man 2 ftruncate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top