common-lisp - sbcl 判断是否是符号链接(symbolic link)

标签 common-lisp symlink sbcl

如何在 sbcl 中测试路径名是否为符号链接(symbolic link)?

CL-USER> (apropos "syml" )
:CLASSIFY-SYMLINKS (bound)
:RESOLVE-SYMLINKS (bound)
:SYMLINK (bound)
SB-IMPL::CLASSIFY-SYMLINKS
SB-IMPL::RESOLVE-PROBLEMATIC-SYMLINK
SB-IMPL::RESOLVE-SYMLINKS
SB-POSIX:SYMLINK (fbound)
UIOP/FILESYSTEM:*RESOLVE-SYMLINKS* (bound)
UIOP/FILESYSTEM:RESOLVE-SYMLINKS (fbound)
UIOP/FILESYSTEM:RESOLVE-SYMLINKS* (fbound)
UTIL::CLASSIFY-SYMLINKS
UTIL::SYMLINK
; No value

这些似乎都没有用。 classify-symlinks 似乎是一个关键字。

最佳答案

长话短说

(defun symlinkp (pathname)
  (sb-posix:s-islnk (sb-posix:stat-mode (sb-posix:lstat pathname))))

要回答必须首先问的问题,如何确定某物(我假设是文件描述符)是否是 posix 中的符号链接(symbolic link)。 man 2 stat 来拯救。来自联机帮助页

  • lstat() is identical to stat(), except that if path is asymbolic link, then the link itself is stat-ed, not the file that it refers to.

  • The following POSIX macros are defined to check the file type using the st_mode field:

  • S_ISLNK(m) symbolic link? (Not in POSIX.1-1996.)

关于common-lisp - sbcl 判断是否是符号链接(symbolic link),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32927250/

相关文章:

lisp - SBCL 多线程写入标准输出

common-lisp - Hunchentoot 通过 HTTP 方法调度

lisp - 函数 (OccurencesOfPrimes < list >) 计算(可能嵌套的)列表中素数的数量

lisp - 常见的 Lisp 循环问题

windows - 从 babun 主目录创建到其他路径的符号链接(symbolic link)

linux - 解析所有符号链接(symbolic link)

windows - 构建脚本中的平台独立符号链接(symbolic link)

lisp - "Package GLUT does not exist",即使在 Arch Linux 中安装了 cl-opengl

list - 使用迭代递归函数在 Lisp 中构建列表

clojure - Clojure中Common Lisp的符号名称?