Hi there everyone!
What is The Way, or your preferred way, of querying the file system for information about the accessibility of a file?  I was looking for a portable way to do this also.
For instance, a function file-readable? which given a filename returns true or false depending on if the current process can read the file or not.  I was also looking for a file-writable? function which would be defined similarly.
Has anyone made any progress on this?  Sorry if we've talked about this before.  Thanks for any help.
--Rick
			
			
									
									Portable file accessibility queries
Portable file accessibility queries
(λx. x x) (λx. x x)
						here some random notes for this topic (some only applicable to UNIX/Mac OSX)
 
Get the current uid
Check if a file is a link
Get file permissions
Change file permissions
Lutz
			
			
									
									
						Code: Select all
; Access rights are in the mode byte (the second)
(file-info "newlisp.c") 
=> (131038 33188 0 501 501 1194273030 1193797570 1194035314)
Get the current uid
Code: Select all
(import "/usr/lib/libc.dylib" "getuid")
(getuid) => 501Check if a file is a link
Code: Select all
(define (link? fname) 
    (= 0x2000 (& (file-info fname 1) 0x2000)))Code: Select all
; masking right bit and checking the user-id and group-id
; could be used to define 'file-readable?' etc
(& 0xFFF ((file-info "newlisp.c") 1)) => 420
; 420 is 644 in octal which would be:
((parse ((exec "ls -l newlisp.c") 0) " ") 0) => "-rw-r--r--"
Code: Select all
(import "/usr/lib/libc.dylib" "chmod")
(write-file "junk.txt" "just-testing")
(chmod "junk.txt" 0755)
> !ls -l junk.txt
-rwxr-xr-x  1 lutz  lutz  12 Nov  5 12:01 junk.txt
>