Re: bug: :if-exists :append
Sam Steingold <[email protected]>
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <m17f4szvuc.fsf@clr-sds> |
Jean, please keep the discussion on the list. > * Jean Louis <[email protected]> [2017-02-14 04:22:16 +0300]: > >> > OK, if you happen to know how to get file descriptor by sys:: let me >> > know. Or how to append to file which is chattr +a >> >> (require "linux") >> (defparameter *my-stream* >> (ext:make-stream (linux:open filename (logior linux::O_APPEND linux::O_RDONLY) 0) >> :direction :append ...)) > > I cannot require "linux" for some reason, using 2.49+ development > version which is too hard to compile. this the "bindings/glibc" module. http://clisp.org/impnotes/modules.html#incmod-bind >> > I have tried that with SBCL and it appended to the file >> >> interesting - what does my lisp code below do in SBCL? >> >> >> >> --8<---------------cut here---------------start------------->8--- >> >> (with-open-file (s "my-append-only-file" :direction :output :if-exists :append) >> >> (let ((pos (file-position s))) >> >> (write-string "foo" s) >> >> (file-position s (- pos 3)) >> >> (write-string "bar" s))) >> >> --8<---------------cut here---------------end--------------->8--- > debugger invoked on a TYPE-ERROR in thread > #<THREAD "main thread" RUNNING {10028DE633}>: > The value > -3 > is not of type > (OR UNSIGNED-BYTE (MEMBER NIL :END :START)) oops, my bad. --8<---------------cut here---------------start------------->8--- (with-open-file (s "my-append-only-file" :direction :output :if-exists :append) (let ((pos (file-position s))) (print pos) (write-string "foo" s) (print (file-position s)) (file-position s pos) (print (file-position s)) (write-string "bar" s) (print (file-position s)))) --8<---------------cut here---------------end--------------->8--- this should work without errors - if it does not, please try `:direction :io`. the question is: will this append * "foobar" (as per `O_APPEND`) or * "bar" (as per `:if-exists :append`) we should be able to figure that out by examining the printed file-positions. Thanks. -- Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.1504 http://steingoldpsychology.com http://www.childpsy.net http://mideasttruth.com https://ffii.org http://www.memritv.org http://camera.org http://jij.org "Sustainability" without "population growth control" is hypocrisy. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ clisp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/clisp-list