Function: read-file-modes

read-file-modes is a byte-compiled function defined in files.el.gz.

Signature

(read-file-modes &optional PROMPT ORIG-FILE)

Documentation

Read file modes in octal or symbolic notation and return its numeric value.

PROMPT is used as the prompt, default to "File modes (octal or symbolic): ". ORIG-FILE is the name of a file on whose mode bits to base returned permissions if what user types requests to add, remove, or set permissions based on existing mode bits, as in "og+rX-w".

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun read-file-modes (&optional prompt orig-file)
  "Read file modes in octal or symbolic notation and return its numeric value.
PROMPT is used as the prompt, default to \"File modes (octal or symbolic): \".
ORIG-FILE is the name of a file on whose mode bits to base returned
permissions if what user types requests to add, remove, or set permissions
based on existing mode bits, as in \"og+rX-w\"."
  (let* ((modes (or (if orig-file (file-modes orig-file) 0)
		    (error "File not found")))
	 (modestr (and (stringp orig-file)
		       (file-attribute-modes (file-attributes orig-file))))
	 (default
	   (and (stringp modestr)
		(string-match "^.\\(...\\)\\(...\\)\\(...\\)$" modestr)
		(string-replace
		 "-" ""
		 (format "u=%s,g=%s,o=%s"
			 (match-string 1 modestr)
			 (match-string 2 modestr)
			 (match-string 3 modestr)))))
	 (value (read-string (or prompt "File modes (octal or symbolic): ")
			     nil nil default)))
    (save-match-data
      (if (string-match "^[0-7]+" value)
	  (string-to-number value 8)
	(file-modes-symbolic-to-number value modes)))))