/* File IO for GNU Emacs.
-Copyright (C) 1985-1988, 1993-2015 Free Software Foundation, Inc.
+Copyright (C) 1985-1988, 1993-2016 Free Software Foundation, Inc.
This file is part of GNU Emacs.
GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
#include <selinux/context.h>
#endif
-#ifdef HAVE_ACL_SET_FILE
+#if USE_ACL && defined HAVE_ACL_SET_FILE
#include <sys/acl.h>
#endif
#include <c-ctype.h>
#include "lisp.h"
-#include "intervals.h"
+#include "composite.h"
#include "character.h"
#include "buffer.h"
#include "coding.h"
#include "blockinput.h"
#include "region-cache.h"
#include "frame.h"
-#include "dispextern.h"
#ifdef WINDOWSNT
#define NOMINMAX 1
A `directly usable' directory name is one that may be used without the
intervention of any file handler.
If FILENAME is a directly usable file itself, return
-(file-name-directory FILENAME).
+\(file-name-as-directory FILENAME).
If FILENAME refers to a file which is not accessible from a local process,
then this should return nil.
The `call-process' and `start-process' functions use this function to
return STRINGP (handled_name) ? handled_name : Qnil;
}
- return Ffile_name_directory (filename);
+ return Ffile_name_as_directory (filename);
}
/* Maximum number of bytes that DST will be longer than SRC
doc: /* Generate temporary file name (string) starting with PREFIX (a string).
The Emacs process number forms part of the result, so there is no
danger of generating a name being used by another Emacs process
-(so long as only a single host can access the containing directory...).
+\(so long as only a single host can access the containing directory...).
This function tries to choose a name that has no existing file.
For this to work, PREFIX should be an absolute file name.
DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
doc: /* Convert filename NAME to absolute, and canonicalize it.
Second arg DEFAULT-DIRECTORY is directory to start with if NAME is relative
-(does not start with slash or tilde); both the directory name and
+\(does not start with slash or tilde); both the directory name and
a directory's file name are accepted. If DEFAULT-DIRECTORY is nil or
missing, the current buffer's value of `default-directory' is used.
NAME should be a string that is a valid file name for the underlying
For technical reasons, this function can return correct but
non-intuitive results for the root directory; for instance,
-(expand-file-name ".." "/") returns "/..". For this reason, use
-(directory-file-name (file-name-directory dirname)) to traverse a
+\(expand-file-name ".." "/") returns "/..". For this reason, use
+\(directory-file-name (file-name-directory dirname)) to traverse a
filesystem tree, not (expand-file-name ".." dirname). */)
(Lisp_Object name, Lisp_Object default_directory)
{
DEAFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
"Convert FILENAME to absolute, and canonicalize it.\n\
Second arg DEFAULT is directory to start with if FILENAME is relative\n\
-(does not start with slash); if DEFAULT is nil or missing,\n\
+\(does not start with slash); if DEFAULT is nil or missing,\n\
the current buffer's value of default-directory is used.\n\
Filenames containing `.' or `..' as components are simplified;\n\
initial `~/' expands to your home directory.\n\
DEFUN ("file-executable-p", Ffile_executable_p, Sfile_executable_p, 1, 1, 0,
doc: /* Return t if FILENAME can be executed by you.
For a directory, this means you can access files in that directory.
-(It is generally better to use `file-accessible-directory-p' for that
+\(It is generally better to use `file-accessible-directory-p' for that
purpose, though.) */)
(Lisp_Object filename)
{
was unable to determine the ACL entries. */)
(Lisp_Object filename)
{
+#if USE_ACL
Lisp_Object absname;
Lisp_Object handler;
-#ifdef HAVE_ACL_SET_FILE
+# ifdef HAVE_ACL_SET_FILE
acl_t acl;
Lisp_Object acl_string;
char *str;
-# ifndef HAVE_ACL_TYPE_EXTENDED
+# ifndef HAVE_ACL_TYPE_EXTENDED
acl_type_t ACL_TYPE_EXTENDED = ACL_TYPE_ACCESS;
+# endif
# endif
-#endif
absname = expand_and_dir_to_file (filename,
BVAR (current_buffer, directory));
if (!NILP (handler))
return call2 (handler, Qfile_acl, absname);
-#ifdef HAVE_ACL_SET_FILE
+# ifdef HAVE_ACL_SET_FILE
absname = ENCODE_FILE (absname);
acl = acl_get_file (SSDATA (absname), ACL_TYPE_EXTENDED);
acl_free (acl);
return acl_string;
+# endif
#endif
return Qnil;
support. */)
(Lisp_Object filename, Lisp_Object acl_string)
{
+#if USE_ACL
Lisp_Object absname;
Lisp_Object handler;
-#ifdef HAVE_ACL_SET_FILE
+# ifdef HAVE_ACL_SET_FILE
Lisp_Object encoded_absname;
acl_t acl;
bool fail;
-#endif
+# endif
absname = Fexpand_file_name (filename, BVAR (current_buffer, directory));
if (!NILP (handler))
return call3 (handler, Qset_file_acl, absname, acl_string);
-#ifdef HAVE_ACL_SET_FILE
+# ifdef HAVE_ACL_SET_FILE
if (STRINGP (acl_string))
{
acl = acl_from_text (SSDATA (acl_string));
acl_free (acl);
return fail ? Qnil : Qt;
}
+# endif
#endif
return Qnil;
st.st_size = -1;
if (!NILP (Vcoding_system_for_read))
{
+ /* Don't let invalid values into buffer-file-coding-system. */
CHECK_CODING_SYSTEM (Vcoding_system_for_read);
Fset (Qbuffer_file_coding_system, Vcoding_system_for_read);
}
if (CODING_FOR_UNIBYTE (&coding)
/* Can't do this if part of the buffer might be preserved. */
&& NILP (replace))
- /* Visiting a file with these coding system makes the buffer
- unibyte. */
- bset_enable_multibyte_characters (current_buffer, Qnil);
+ {
+ /* Visiting a file with these coding system makes the buffer
+ unibyte. */
+ if (inserted > 0)
+ bset_enable_multibyte_characters (current_buffer, Qnil);
+ else
+ Fset_buffer_multibyte (Qnil);
+ }
}
coding.dst_multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
else if (!NILP (Vcoding_system_for_write))
{
val = Vcoding_system_for_write;
- CHECK_CODING_SYSTEM (val);
if (coding_system_require_warning
&& !NILP (Ffboundp (Vselect_safe_coding_system_function)))
/* Confirm that VAL can surely encode the current region. */
if (NILP (val))
{
/* If we still have not decided a coding system, use the
- default value of buffer-file-coding-system. */
+ current buffer's value of buffer-file-coding-system. */
val = BVAR (current_buffer, buffer_file_coding_system);
using_default_coding = 1;
}
- if (!NILP (val))
- CHECK_CODING_SYSTEM (val);
-
if (! NILP (val) && ! force_raw_text)
{
Lisp_Object spec, attrs;
+ CHECK_CODING_SYSTEM (val);
CHECK_CODING_SYSTEM_GET_SPEC (val, spec);
attrs = AREF (spec, 0);
if (EQ (CODING_ATTR_TYPE (attrs), Qraw_text))
/* Confirm that VAL can surely encode the current region. */
val = call5 (Vselect_safe_coding_system_function,
start, end, val, Qnil, filename);
- CHECK_CODING_SYSTEM (val);
+ /* As the function specified by select-safe-coding-system-function
+ is out of our control, make sure we are not fed by bogus
+ values. */
+ if (!NILP (val))
+ CHECK_CODING_SYSTEM (val);
}
/* If the decided coding-system doesn't specify end-of-line
Lisp_Object dflt = BVAR (&buffer_defaults, buffer_file_coding_system);
if (! NILP (dflt))
- {
- CHECK_CODING_SYSTEM (dflt);
- val = (coding_inherit_eol_type (val, dflt));
- }
+ val = coding_inherit_eol_type (val, dflt);
}
/* If we decide not to encode text, use `raw-text' or one of its
Useful if the buffer was not read from the file normally
or if the file itself has been changed for some known benign reason.
An argument specifies the modification time value to use
-(instead of that of the visited file), in the form of a list
-(HIGH LOW USEC PSEC) or an integer flag as returned by
+\(instead of that of the visited file), in the form of a list
+\(HIGH LOW USEC PSEC) or an integer flag as returned by
`visited-file-modtime'. */)
(Lisp_Object time_flag)
{