hi,
I want to create an empty file and then seek the file pointer position to
make ls
think it has some contents. what common lisp function I can use ? thanks.
"Lin Jingxian" <········@yahoo.ie> writes:
> I want to create an empty file and then seek the file pointer
> position to make ls think it has some contents. what common lisp
> function I can use ?
There is no ANSI standard way to do that in Common Lisp.
What are you actually trying to accomplish?
On Fri, 22 Jul 2005 06:41:20 +0000, Christopher C. Stacy wrote:
> "Lin Jingxian" <········@yahoo.ie> writes:
>
>> I want to create an empty file and then seek the file pointer
>> position to make ls think it has some contents. what common lisp
>> function I can use ?
>
> There is no ANSI standard way to do that in Common Lisp.
> What are you actually trying to accomplish?
Looks like Lin wants to create a sparse file (i.e. one of
those monster files with "holes" in it -- great for practical
jokes :-)
Cheers Ralf Mattes
"Lin Jingxian" <········@yahoo.ie> writes:
> hi, I want to create an empty file and then seek the file pointer
> position to make ls think it has some contents. what common lisp
> function I can use ? thanks.
I'm not sure if this is what you mean but:
CL-USER> (with-open-file (out "/tmp/bigfile" :direction :io :element-type '(unsigned-byte 8) :if-exists :supersede)
(file-position out (1- (* 1024 1024)))
(write-byte 0 out))
0
[·····@beagle tmp]$ ls -l bigfile
-rw-r--r-- 1 peter wheel 1048576 Jul 22 08:40 bigfile
-Peter
--
Peter Seibel * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp * http://www.gigamonkeys.com/book/
"Lin Jingxian" <········@yahoo.ie> writes:
> hi,
> I want to create an empty file and then seek the file pointer position to
> make ls
> think it has some contents. what common lisp function I can use ? thanks.
Normally:
(with-open-file (out "/tmp/content.data" :direction :output
:if-exists :supersede :if-does-not-exist :create
:element-type '(unsigned-byte 8))
(file-position out 10000)
(write-byte 0 out))
Unfortunately, some implementations on unix don't like it and give:
*** - cannot position
#<OUTPUT BUFFERED FILE-STREAM (UNSIGNED-BYTE 8) #P"/tmp/content.data">
beyond EOF
Clearly, this is an implementation problem. I see nothing in clhs
file-position that prevent to implement file-position as lseek on
unix.
In particular, clhs file-position says:
Exceptional Situations:
If position-spec is supplied, but is too large or otherwise
inappropriate, an error is signaled.
but a possition greater than the current file size is not too large
and neither inappropriate on a unix system.
The problems are
- CLHS allows this behavior (it doesn't define a too large file size
and neither an inappropriate file size).
- there is no CLRFI specifying a common meaning for these notions on
POSIX systems, therefore different implementations on a POSIX system
diverge.
- there is no CLRFI specifying a common meaning for these notions on
UNIX systems, therefore different implementations on a UNIX system
diverge.
PS: On some other implementations (eg. SBCL on Linux), it works as expected:
$ ls -l /tmp/content.data
-rw-r--r-- 1 pjb pjb 10001 2005-07-22 19:02 /tmp/content.data
--
__Pascal Bourguignon__ http://www.informatimago.com/
This is a signature virus. Add me to your signature and help me to live
Pascal Bourguignon <···@informatimago.com> writes:
> "Lin Jingxian" <········@yahoo.ie> writes:
>
>> hi,
>> I want to create an empty file and then seek the file pointer position to
>> make ls
>> think it has some contents. what common lisp function I can use ? thanks.
>
> Normally:
>
> (with-open-file (out "/tmp/content.data" :direction :output
> :if-exists :supersede :if-does-not-exist :create
> :element-type '(unsigned-byte 8))
> (file-position out 10000)
> (write-byte 0 out))
How does that impl handle it if you specify :io instead of :output?
-Peter
--
Peter Seibel * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp * http://www.gigamonkeys.com/book/