aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2017-08-25 09:20:52 -0700
committerPaul Eggert2017-08-25 09:32:09 -0700
commit9a223dab9036ff72b16e7a9878af090c041fd0c6 (patch)
tree79c473ca74ec90e194576639ca9ccc1cab0a5132 /src
parent579890f1c7703cd8ecfe2e56f52cc06fcd1b2442 (diff)
downloademacs-9a223dab9036ff72b16e7a9878af090c041fd0c6.tar.gz
emacs-9a223dab9036ff72b16e7a9878af090c041fd0c6.zip
Simplify expand_and_dir_to_file
* src/fileio.c (expand_and_dir_to_file): Simplify by omitting 2nd argument, since in practice it always has the default value. All callers changed. Prefer C99 style decls in nearby code.
Diffstat (limited to 'src')
-rw-r--r--src/callproc.c2
-rw-r--r--src/fileio.c85
-rw-r--r--src/lisp.h2
3 files changed, 30 insertions, 59 deletions
diff --git a/src/callproc.c b/src/callproc.c
index 4cec02be7ef..b93d361a947 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -120,7 +120,7 @@ encode_current_directory (void)
120 if (NILP (dir)) 120 if (NILP (dir))
121 dir = build_string ("~"); 121 dir = build_string ("~");
122 122
123 dir = expand_and_dir_to_file (dir, Qnil); 123 dir = expand_and_dir_to_file (dir);
124 124
125 if (NILP (Ffile_accessible_directory_p (dir))) 125 if (NILP (Ffile_accessible_directory_p (dir)))
126 report_file_error ("Setting current directory", 126 report_file_error ("Setting current directory",
diff --git a/src/fileio.c b/src/fileio.c
index ca1bc5065e5..76ea7da0e81 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1758,11 +1758,9 @@ those `/' is discarded. */)
1758 (directory-file-name (expand-file-name FOO)). */ 1758 (directory-file-name (expand-file-name FOO)). */
1759 1759
1760Lisp_Object 1760Lisp_Object
1761expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir) 1761expand_and_dir_to_file (Lisp_Object filename)
1762{ 1762{
1763 register Lisp_Object absname; 1763 Lisp_Object absname = Fexpand_file_name (filename, Qnil);
1764
1765 absname = Fexpand_file_name (filename, defdir);
1766 1764
1767 /* Remove final slash, if any (unless this is the root dir). 1765 /* Remove final slash, if any (unless this is the root dir).
1768 stat behaves differently depending! */ 1766 stat behaves differently depending! */
@@ -2676,14 +2674,11 @@ Symbolic links to directories count as directories.
2676See `file-symlink-p' to distinguish symlinks. */) 2674See `file-symlink-p' to distinguish symlinks. */)
2677 (Lisp_Object filename) 2675 (Lisp_Object filename)
2678{ 2676{
2679 Lisp_Object absname; 2677 Lisp_Object absname = expand_and_dir_to_file (filename);
2680 Lisp_Object handler;
2681
2682 absname = expand_and_dir_to_file (filename, BVAR (current_buffer, directory));
2683 2678
2684 /* If the file name has special constructs in it, 2679 /* If the file name has special constructs in it,
2685 call the corresponding file handler. */ 2680 call the corresponding file handler. */
2686 handler = Ffind_file_name_handler (absname, Qfile_directory_p); 2681 Lisp_Object handler = Ffind_file_name_handler (absname, Qfile_directory_p);
2687 if (!NILP (handler)) 2682 if (!NILP (handler))
2688 return call2 (handler, Qfile_directory_p, absname); 2683 return call2 (handler, Qfile_directory_p, absname);
2689 2684
@@ -2807,15 +2802,12 @@ Symbolic links to regular files count as regular files.
2807See `file-symlink-p' to distinguish symlinks. */) 2802See `file-symlink-p' to distinguish symlinks. */)
2808 (Lisp_Object filename) 2803 (Lisp_Object filename)
2809{ 2804{
2810 register Lisp_Object absname;
2811 struct stat st; 2805 struct stat st;
2812 Lisp_Object handler; 2806 Lisp_Object absname = expand_and_dir_to_file (filename);
2813
2814 absname = expand_and_dir_to_file (filename, BVAR (current_buffer, directory));
2815 2807
2816 /* If the file name has special constructs in it, 2808 /* If the file name has special constructs in it,
2817 call the corresponding file handler. */ 2809 call the corresponding file handler. */
2818 handler = Ffind_file_name_handler (absname, Qfile_regular_p); 2810 Lisp_Object handler = Ffind_file_name_handler (absname, Qfile_regular_p);
2819 if (!NILP (handler)) 2811 if (!NILP (handler))
2820 return call2 (handler, Qfile_regular_p, absname); 2812 return call2 (handler, Qfile_regular_p, absname);
2821 2813
@@ -2853,21 +2845,13 @@ Return (nil nil nil nil) if the file is nonexistent or inaccessible,
2853or if SELinux is disabled, or if Emacs lacks SELinux support. */) 2845or if SELinux is disabled, or if Emacs lacks SELinux support. */)
2854 (Lisp_Object filename) 2846 (Lisp_Object filename)
2855{ 2847{
2856 Lisp_Object absname;
2857 Lisp_Object user = Qnil, role = Qnil, type = Qnil, range = Qnil; 2848 Lisp_Object user = Qnil, role = Qnil, type = Qnil, range = Qnil;
2858 2849 Lisp_Object absname = expand_and_dir_to_file (filename);
2859 Lisp_Object handler;
2860#if HAVE_LIBSELINUX
2861 security_context_t con;
2862 int conlength;
2863 context_t context;
2864#endif
2865
2866 absname = expand_and_dir_to_file (filename, BVAR (current_buffer, directory));
2867 2850
2868 /* If the file name has special constructs in it, 2851 /* If the file name has special constructs in it,
2869 call the corresponding file handler. */ 2852 call the corresponding file handler. */
2870 handler = Ffind_file_name_handler (absname, Qfile_selinux_context); 2853 Lisp_Object handler = Ffind_file_name_handler (absname,
2854 Qfile_selinux_context);
2871 if (!NILP (handler)) 2855 if (!NILP (handler))
2872 return call2 (handler, Qfile_selinux_context, absname); 2856 return call2 (handler, Qfile_selinux_context, absname);
2873 2857
@@ -2876,10 +2860,11 @@ or if SELinux is disabled, or if Emacs lacks SELinux support. */)
2876#if HAVE_LIBSELINUX 2860#if HAVE_LIBSELINUX
2877 if (is_selinux_enabled ()) 2861 if (is_selinux_enabled ())
2878 { 2862 {
2879 conlength = lgetfilecon (SSDATA (absname), &con); 2863 security_context_t con;
2864 int conlength = lgetfilecon (SSDATA (absname), &con);
2880 if (conlength > 0) 2865 if (conlength > 0)
2881 { 2866 {
2882 context = context_new (con); 2867 context_t context = context_new (con);
2883 if (context_user_get (context)) 2868 if (context_user_get (context))
2884 user = build_string (context_user_get (context)); 2869 user = build_string (context_user_get (context));
2885 if (context_role_get (context)) 2870 if (context_role_get (context))
@@ -2990,35 +2975,28 @@ Return nil if file does not exist or is not accessible, or if Emacs
2990was unable to determine the ACL entries. */) 2975was unable to determine the ACL entries. */)
2991 (Lisp_Object filename) 2976 (Lisp_Object filename)
2992{ 2977{
2993#if USE_ACL 2978 Lisp_Object acl_string = Qnil;
2994 Lisp_Object absname;
2995 Lisp_Object handler;
2996# ifdef HAVE_ACL_SET_FILE
2997 acl_t acl;
2998 Lisp_Object acl_string;
2999 char *str;
3000# ifndef HAVE_ACL_TYPE_EXTENDED
3001 acl_type_t ACL_TYPE_EXTENDED = ACL_TYPE_ACCESS;
3002# endif
3003# endif
3004 2979
3005 absname = expand_and_dir_to_file (filename, 2980#if USE_ACL
3006 BVAR (current_buffer, directory)); 2981 Lisp_Object absname = expand_and_dir_to_file (filename);
3007 2982
3008 /* If the file name has special constructs in it, 2983 /* If the file name has special constructs in it,
3009 call the corresponding file handler. */ 2984 call the corresponding file handler. */
3010 handler = Ffind_file_name_handler (absname, Qfile_acl); 2985 Lisp_Object handler = Ffind_file_name_handler (absname, Qfile_acl);
3011 if (!NILP (handler)) 2986 if (!NILP (handler))
3012 return call2 (handler, Qfile_acl, absname); 2987 return call2 (handler, Qfile_acl, absname);
3013 2988
3014# ifdef HAVE_ACL_SET_FILE 2989# ifdef HAVE_ACL_SET_FILE
3015 absname = ENCODE_FILE (absname); 2990 absname = ENCODE_FILE (absname);
3016 2991
3017 acl = acl_get_file (SSDATA (absname), ACL_TYPE_EXTENDED); 2992# ifndef HAVE_ACL_TYPE_EXTENDED
2993 acl_type_t ACL_TYPE_EXTENDED = ACL_TYPE_ACCESS;
2994# endif
2995 acl_t acl = acl_get_file (SSDATA (absname), ACL_TYPE_EXTENDED);
3018 if (acl == NULL) 2996 if (acl == NULL)
3019 return Qnil; 2997 return Qnil;
3020 2998
3021 str = acl_to_text (acl, NULL); 2999 char *str = acl_to_text (acl, NULL);
3022 if (str == NULL) 3000 if (str == NULL)
3023 { 3001 {
3024 acl_free (acl); 3002 acl_free (acl);
@@ -3028,12 +3006,10 @@ was unable to determine the ACL entries. */)
3028 acl_string = build_string (str); 3006 acl_string = build_string (str);
3029 acl_free (str); 3007 acl_free (str);
3030 acl_free (acl); 3008 acl_free (acl);
3031
3032 return acl_string;
3033# endif 3009# endif
3034#endif 3010#endif
3035 3011
3036 return Qnil; 3012 return acl_string;
3037} 3013}
3038 3014
3039DEFUN ("set-file-acl", Fset_file_acl, Sset_file_acl, 3015DEFUN ("set-file-acl", Fset_file_acl, Sset_file_acl,
@@ -3097,15 +3073,12 @@ DEFUN ("file-modes", Ffile_modes, Sfile_modes, 1, 1, 0,
3097Return nil, if file does not exist or is not accessible. */) 3073Return nil, if file does not exist or is not accessible. */)
3098 (Lisp_Object filename) 3074 (Lisp_Object filename)
3099{ 3075{
3100 Lisp_Object absname;
3101 struct stat st; 3076 struct stat st;
3102 Lisp_Object handler; 3077 Lisp_Object absname = expand_and_dir_to_file (filename);
3103
3104 absname = expand_and_dir_to_file (filename, BVAR (current_buffer, directory));
3105 3078
3106 /* If the file name has special constructs in it, 3079 /* If the file name has special constructs in it,
3107 call the corresponding file handler. */ 3080 call the corresponding file handler. */
3108 handler = Ffind_file_name_handler (absname, Qfile_modes); 3081 Lisp_Object handler = Ffind_file_name_handler (absname, Qfile_modes);
3109 if (!NILP (handler)) 3082 if (!NILP (handler))
3110 return call2 (handler, Qfile_modes, absname); 3083 return call2 (handler, Qfile_modes, absname);
3111 3084
@@ -3232,20 +3205,18 @@ If FILE1 does not exist, the answer is nil;
3232otherwise, if FILE2 does not exist, the answer is t. */) 3205otherwise, if FILE2 does not exist, the answer is t. */)
3233 (Lisp_Object file1, Lisp_Object file2) 3206 (Lisp_Object file1, Lisp_Object file2)
3234{ 3207{
3235 Lisp_Object absname1, absname2;
3236 struct stat st1, st2; 3208 struct stat st1, st2;
3237 Lisp_Object handler;
3238 3209
3239 CHECK_STRING (file1); 3210 CHECK_STRING (file1);
3240 CHECK_STRING (file2); 3211 CHECK_STRING (file2);
3241 3212
3242 absname1 = Qnil; 3213 Lisp_Object absname1 = expand_and_dir_to_file (file1);
3243 absname1 = expand_and_dir_to_file (file1, BVAR (current_buffer, directory)); 3214 Lisp_Object absname2 = expand_and_dir_to_file (file2);
3244 absname2 = expand_and_dir_to_file (file2, BVAR (current_buffer, directory));
3245 3215
3246 /* If the file name has special constructs in it, 3216 /* If the file name has special constructs in it,
3247 call the corresponding file handler. */ 3217 call the corresponding file handler. */
3248 handler = Ffind_file_name_handler (absname1, Qfile_newer_than_file_p); 3218 Lisp_Object handler = Ffind_file_name_handler (absname1,
3219 Qfile_newer_than_file_p);
3249 if (NILP (handler)) 3220 if (NILP (handler))
3250 handler = Ffind_file_name_handler (absname2, Qfile_newer_than_file_p); 3221 handler = Ffind_file_name_handler (absname2, Qfile_newer_than_file_p);
3251 if (!NILP (handler)) 3222 if (!NILP (handler))
diff --git a/src/lisp.h b/src/lisp.h
index 48cf3b30709..81f8d6a24b5 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3998,7 +3998,7 @@ extern void syms_of_marker (void);
3998 3998
3999/* Defined in fileio.c. */ 3999/* Defined in fileio.c. */
4000 4000
4001extern Lisp_Object expand_and_dir_to_file (Lisp_Object, Lisp_Object); 4001extern Lisp_Object expand_and_dir_to_file (Lisp_Object);
4002extern Lisp_Object write_region (Lisp_Object, Lisp_Object, Lisp_Object, 4002extern Lisp_Object write_region (Lisp_Object, Lisp_Object, Lisp_Object,
4003 Lisp_Object, Lisp_Object, Lisp_Object, 4003 Lisp_Object, Lisp_Object, Lisp_Object,
4004 Lisp_Object, int); 4004 Lisp_Object, int);