Function: file-modes-number-to-symbolic
file-modes-number-to-symbolic is a byte-compiled function defined in
files.el.gz.
Signature
(file-modes-number-to-symbolic MODE &optional FILETYPE)
Documentation
Return a description of a file's MODE as a string of 10 letters and dashes.
The returned string is like the mode description produced by "ls -l".
For instance, if MODE is #o700, then it produces -rwx------.
Note that this is NOT the same as the "chmod" style symbolic description
accepted by file-modes-symbolic-to-number.
FILETYPE, if provided, should be a character denoting the type of file,
such as ?d for a directory, or ?l for a symbolic link, and will override
the leading - character.
Other relevant functions are documented in the file group.
Probably introduced at or before Emacs version 28.1.
Shortdoc
;; file
(file-modes-number-to-symbolic #o444)
=> "-r--r--r--"
Aliases
archive-int-to-mode (obsolete since 28.1)
Source Code
;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun file-modes-number-to-symbolic (mode &optional filetype)
"Return a description of a file's MODE as a string of 10 letters and dashes.
The returned string is like the mode description produced by \"ls -l\".
For instance, if MODE is #o700, then it produces `-rwx------'.
Note that this is NOT the same as the \"chmod\" style symbolic description
accepted by `file-modes-symbolic-to-number'.
FILETYPE, if provided, should be a character denoting the type of file,
such as `?d' for a directory, or `?l' for a symbolic link, and will override
the leading `-' character."
(string
(or filetype
(pcase (ash mode -12)
;; POSIX specifies that the file type is included in st_mode
;; and provides names for the file types but values only for
;; the permissions (e.g., S_IWOTH=2).
;; (#o017 ??) ;; #define S_IFMT 00170000
(#o014 ?s) ;; #define S_IFSOCK 0140000
(#o012 ?l) ;; #define S_IFLNK 0120000
;; (8 ??) ;; #define S_IFREG 0100000
(#o006 ?b) ;; #define S_IFBLK 0060000
(#o004 ?d) ;; #define S_IFDIR 0040000
(#o002 ?c) ;; #define S_IFCHR 0020000
(#o001 ?p) ;; #define S_IFIFO 0010000
(_ ?-)))
(if (zerop (logand 256 mode)) ?- ?r)
(if (zerop (logand 128 mode)) ?- ?w)
(if (zerop (logand 64 mode))
(if (zerop (logand 2048 mode)) ?- ?S)
(if (zerop (logand 2048 mode)) ?x ?s))
(if (zerop (logand 32 mode)) ?- ?r)
(if (zerop (logand 16 mode)) ?- ?w)
(if (zerop (logand 8 mode))
(if (zerop (logand 1024 mode)) ?- ?S)
(if (zerop (logand 1024 mode)) ?x ?s))
(if (zerop (logand 4 mode)) ?- ?r)
(if (zerop (logand 2 mode)) ?- ?w)
(if (zerop (logand 512 mode))
(if (zerop (logand 1 mode)) ?- ?x)
(if (zerop (logand 1 mode)) ?T ?t))))