Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Answer: How do I pre-extend a file to a specified size

by Anonymous Monk
on Jan 05, 2001 at 06:17 UTC ( [id://49963]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I pre-extend a file to a specified size
in thread How do I pre-extend a file to a specified size

I tried the following code segment on both Win98 and VMS and it failed to give the desired result:
open HANDLE, ">temp.tmp" || die; $desired_size=1000000; seek HANDLE, 0, $desired_size -1; print HANDLE "\0"; seek HANDLE, 0, 0; close HANDLE;
The resulting file on Win98 is one byte long!! On VMS it is one block (minimum file size). It would appear that the seek doesn't extend the file past its current size (initially 0 bytes). Any suggestion appreciated.

Replies are listed 'Best First'.
Re: Re: Answer: How do I pre-extend a file to a specified size
by chipmunk (Parson) on Jan 05, 2001 at 07:11 UTC
    It is rather frustrating that the Q&A section is not properly threaded. I pointed out the bug in merlyn's code in Re: Answer: How do I pre-extend a file to a specified size, but looking at the node for the question, there's no indication that merlyn's answer even has a response. Meanwhile, looking at the node for merlyn's answer, there is no way to get back to the original question.

    To fix the bug, swap the second and third arguments to seek:

    seek HANDLE, $desired_size -1, 0;
      Thanks... that did the trick (kind-a): Now works fine with Win9x/2K but fails to extend the file on OpenVMS. I'll forward a bug report to the VMS porting people.

        That snippet doesn't check any return values so it is possible that the seek() failed. But I really suspect that VMS creates a sparse file and reports the amount of space the file is using, not the maximum byte offset for the file.

        The same thing often happens under Unix -- the file isn't really preextended as far as allocating that much space on the disk. It is just that "ls" reports the maximum byte offset for the file, not how much disk space has been allocated to it.

                - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://49963]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-28 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found