Talk:Truncate a file: Difference between revisions

Suggest to reword the file size requirement part
(truncation is the bit that I am hoping to see demonstrated)
(Suggest to reword the file size requirement part)
Line 1:
==File size requirement==
So just to be sure, if the actual file size is smaller than the given truncated size, it's an error? It doesn't just leave the file alone? --[[User:Mwn3d|Mwn3d]] 14:09, 19 July 2011 (UTC)
:POSIX truncate() and ftruncate() extends the file if specified size is larger than original. It's convenient when you want to reserve some disk space. --[[User:Ledrug|Ledrug]] 14:25, 19 July 2011 (UTC)
'''Copied from below'''
:the requirement that the routine should bail out if requested size is larger than original is unrealistic. If it's important that the file must be the requested size, you should extend it; if it's not important, why not just leave it alone and move on? If you really cared, you should have checked its size beforehand anyway. --[[User:Ledrug|Ledrug]] 17:21, 19 July 2011 (UTC)
::Yeah, I would have expected a beforehand check here. However, for the purpose of this task, the truncation is the bit that I hoping to see demonstrated here, rather than determining the filesize. I don't have any objection to extending the file, if that is easier than bailing out. It would be nice to get a warning message that the file has been padded, or maybe we could just place a note against a the solution that the file gets padded, if the provided length is greater than the current length of the file. [[User:Markhobley|Markhobley]] 19:20, 19 July 2011 (UTC)
:::I'd say something like "For built-in functions, note their behavior when the actual file size is smaller than the desired file size. For user-defined functions, note the choice you made (padding, error message, leaving the file unchanged, etc.)." That leaves enough freedom to make sure there isn't much added to the meat of the solution. --[[User:Mwn3d|Mwn3d]] 19:28, 19 July 2011 (UTC)
 
== Assumes unix ==
Anonymous user