Mercurial > hg > octave-lojdl > gnulib-hg
comparison lib/rename-dest-slash.c @ 7308:eac21c5dbf2f
* rename-dest-slash.c (has_trailing_slash): Use
FILE_SYSTEM_PREFIX_LEN, for non-POSIX systems.
(rpl_rename_dest_slash): Perform the cheaper trailing slash
test before testing whether SRC is a directory.
Suggestions from Bruno Haible.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Fri, 15 Sep 2006 18:48:09 +0000 |
parents | 57043fbf87a2 |
children | 80672a16f597 |
comparison
equal
deleted
inserted
replaced
7307:87cb6e41fd09 | 7308:eac21c5dbf2f |
---|---|
40 | 40 |
41 static inline bool | 41 static inline bool |
42 has_trailing_slash (char const *file, size_t len) | 42 has_trailing_slash (char const *file, size_t len) |
43 { | 43 { |
44 /* Don't count "/" as having a trailing slash. */ | 44 /* Don't count "/" as having a trailing slash. */ |
45 if (len <= 1) | 45 if (len <= FILE_SYSTEM_PREFIX_LEN (file) + 1) |
46 return false; | 46 return false; |
47 | 47 |
48 char last = file[len - 1]; | 48 char last = file[len - 1]; |
49 return ISSLASH (last); | 49 return ISSLASH (last); |
50 } | 50 } |
62 size_t d_len; | 62 size_t d_len; |
63 int ret_val = rename (src, dst); | 63 int ret_val = rename (src, dst); |
64 if (ret_val == 0 || errno != ENOENT) | 64 if (ret_val == 0 || errno != ENOENT) |
65 return ret_val; | 65 return ret_val; |
66 | 66 |
67 /* Don't call rename again if there are no trailing slashes. */ | |
68 d_len = strlen (dst); | |
69 if ( ! has_trailing_slash (dst, d_len)) | |
70 return ret_val; | |
71 | |
67 { | 72 { |
68 /* Fail now, unless SRC is a directory. */ | 73 /* Fail now, unless SRC is a directory. */ |
69 struct stat sb; | 74 struct stat sb; |
70 if (lstat (src, &sb) != 0 || ! S_ISDIR (sb.st_mode)) | 75 if (lstat (src, &sb) != 0 || ! S_ISDIR (sb.st_mode)) |
71 return ret_val; | 76 return ret_val; |
72 } | 77 } |
73 | |
74 /* Don't call rename again if there are no trailing slashes. */ | |
75 d_len = strlen (dst); | |
76 if ( ! has_trailing_slash (dst, d_len)) | |
77 return ret_val; | |
78 | 78 |
79 { | 79 { |
80 char *dst_temp; | 80 char *dst_temp; |
81 dst_temp = xmemdup (dst, d_len + 1); | 81 dst_temp = xmemdup (dst, d_len + 1); |
82 strip_trailing_slashes (dst_temp); | 82 strip_trailing_slashes (dst_temp); |