Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/newlisp
- ;; 共有ライブラリからの返り値が文字列のポインタだったりすると
- ;; アーキテクチャによって型のサイズが違うので処理が面倒だねという話。
- ;; len_void* == sizeof(void *);
- (cond
- ;; 64-bit
- ((= 256 (& 256 (sys-info 9)))
- (define get-ptr get-long)
- (define len_void* 8))
- ;; 32-bit
- (true
- (define get-ptr get-int)
- (define len_void* 4)))
- (define NULL 0)
- (import "./environ.so" "envp") ; 付属のenviron.cからshared-objectファイルを作成しておく
- (import "libc.so.6" "puts")
- (import "libc.so.6" "printf")
- (setf environ (envp))
- (while (!= (get-ptr environ) NULL)
- (printf "%s\n" (get-ptr environ))
- (++ environ len_void*)
- )
- (exit)
Add Comment
Please, Sign In to add comment