1 /* Work around unlinkat bugs on Solaris 9.
3 Copyright (C) 2009 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Written by Eric Blake. */
33 /* unlinkat without AT_REMOVEDIR does not honor trailing / on Solaris
34 9. Solve it in a similar manner to unlink. */
37 rpl_unlinkat (int fd, char const *name, int flag)
41 /* rmdir behavior has no problems with trailing slash. */
42 if (flag & AT_REMOVEDIR)
43 return unlinkat (fd, name, flag);
46 if (len && ISSLASH (name[len - 1]))
48 /* See the lengthy comment in unlink.c why we disobey the POSIX
49 rule of letting unlink("link-to-dir/") attempt to unlink a
52 result = lstatat (fd, name, &st);
55 /* Trailing NUL will overwrite the trailing slash. */
56 char *short_name = malloc (len);
62 memcpy (short_name, name, len);
63 while (len && ISSLASH (short_name[len - 1]))
64 short_name[--len] = '\0';
65 if (len && (lstatat (fd, short_name, &st) || S_ISLNK (st.st_mode)))
75 result = unlinkat (fd, name, flag);