Function: file-modes-symbolic-to-number

file-modes-symbolic-to-number is a byte-compiled function defined in files.el.gz.

Signature

(file-modes-symbolic-to-number MODES &optional FROM)

Documentation

Convert symbolic file modes to numeric file modes.

MODES is the string to convert, it should match
"[ugoa]*([+-=][rwxXstugo]*)+,...".
See Info node (coreutils)File permissions for more information on this notation. FROM (or 0 if nil) gives the mode bits on which to base permissions if MODES request to add, remove, or set permissions based on existing ones, as in "og+rX-w".

Other relevant functions are documented in the file group.

Shortdoc

;; file
(file-modes-symbolic-to-number "a+r")
    e.g. => #o444

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun file-modes-symbolic-to-number (modes &optional from)
  "Convert symbolic file modes to numeric file modes.
MODES is the string to convert, it should match
\"[ugoa]*([+-=][rwxXstugo]*)+,...\".
See Info node `(coreutils)File permissions' for more information on this
notation.
FROM (or 0 if nil) gives the mode bits on which to base permissions if
MODES request to add, remove, or set permissions based on existing ones,
as in \"og+rX-w\"."
  (save-match-data
    (let ((case-fold-search nil)
	  (num-modes (or from 0)))
      (while (/= (string-to-char modes) 0)
	(if (string-match "^\\([ugoa]*\\)\\([+=-][rwxXstugo]*\\)+\\(,\\|\\)" modes)
	    (let ((num-who (apply 'logior 0
				  (mapcar 'file-modes-char-to-who
					  (match-string 1 modes)))))
	      (when (= num-who 0)
		(setq num-who (logior #o7000 (default-file-modes))))
	      (setq num-modes
		    (file-modes-rights-to-number (substring modes (match-end 1))
						 num-who num-modes)
		    modes (substring modes (match-end 3))))
	  (error "Parse error in modes near `%s'" (substring modes 0))))
      num-modes)))