Function: set-default-file-modes

set-default-file-modes is a function defined in fileio.c.

Signature

(set-default-file-modes MODE)

Documentation

Set the file permission bits for newly created files.

The argument MODE should be an integer; only the low 9 bits are used. On Posix hosts, this setting is inherited by subprocesses.

This function works by setting the Emacs's file mode creation mask. Each bit that is set in the mask means that the corresponding bit in the permissions of newly created files will be disabled.

Note that when write-region creates a file, it resets the execute bit, even if the mask set by this function allows that bit by having the corresponding bit in the mask reset.

See also with-file-modes.

Other relevant functions are documented in the file group.

View in manual

Shortdoc

;; file
(set-default-file-modes #o755)

Source Code

// Defined in /usr/src/emacs/src/fileio.c
{
  mode_t oldrealmask, oldumask, newumask;
  CHECK_FIXNUM (mode);
  oldrealmask = realmask;
  newumask = ~ XFIXNUM (mode) & 0777;

  block_input ();
  realmask = newumask;
  oldumask = umask (newumask);
  unblock_input ();

  eassert (oldumask == oldrealmask);
  return Qnil;
}