Function: file-modes-rights-to-number

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

Signature

(file-modes-rights-to-number RIGHTS WHO-MASK &optional FROM)

Documentation

Convert a symbolic mode string specification to an equivalent number.

RIGHTS is the symbolic mode spec, it should match "([+=-][rwxXstugo]*)+". WHO-MASK is the bit-mask specifying the category of users to which to apply the access permissions. See file-modes-char-to-who. FROM (or 0 if nil) gives the mode bits on which to base permissions if RIGHTS request to add, remove, or set permissions based on existing ones, as in "og+rX-w".

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun file-modes-rights-to-number (rights who-mask &optional from)
  "Convert a symbolic mode string specification to an equivalent number.
RIGHTS is the symbolic mode spec, it should match \"([+=-][rwxXstugo]*)+\".
WHO-MASK is the bit-mask specifying the category of users to which to
apply the access permissions.  See `file-modes-char-to-who'.
FROM (or 0 if nil) gives the mode bits on which to base permissions if
RIGHTS request to add, remove, or set permissions based on existing ones,
as in \"og+rX-w\"."
  (let* ((num-rights (or from 0))
	 (list-rights (string-to-list rights))
	 (op (pop list-rights)))
    (while (memq op '(?+ ?- ?=))
      (let ((num-right 0)
	    char-right)
	(while (memq (setq char-right (pop list-rights))
		     '(?r ?w ?x ?X ?s ?t ?u ?g ?o))
	  (setq num-right
		(logior num-right
			(file-modes-char-to-right char-right num-rights))))
	(setq num-right (logand who-mask num-right)
	      num-rights
	      (cond ((= op ?+) (logior num-rights num-right))
		    ((= op ?-) (logand num-rights (lognot num-right)))
		    (t (logior (logand num-rights (lognot who-mask)) num-right)))
	      op char-right)))
    num-rights))