annotate lib/lstat.c @ 17188:d7a44f0f7a15

ftruncate, fts, lstat, openat, raise: no 'static inline' * lib/ftruncate.c (chsize_nothrow): * lib/fts.c (opendirat, diropen): * lib/lstat.c (orig_lstat): * lib/openat.c (orig_openat): * lib/raise.c (raise_nothrow): Now static, not static inline. * m4/ftruncate.m4 (gl_PREREQ_FTRUNCATE): * m4/fts.m4 (gl_FUNC_FTS_CORE): * m4/lstat.m4 (gl_PREREQ_LSTAT): * m4/openat.m4 (gl_PREREQ_OPENAT): * m4/raise.m4 (gl_PREREQ_RAISE): Do not require AC_C_INLINE.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 20 Nov 2012 22:25:09 -0800 (2012-11-21)
parents 18a38c9615f0
children e542fd46ad6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5933
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
1 /* Work around a bug of lstat on some systems
4474
f1650b772bb6 Correct SunOS and Solaris version number notation to match Sun's usage.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4061
diff changeset
2
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 15583
diff changeset
3 Copyright (C) 1997-2006, 2008-2012 Free Software Foundation, Inc.
4061
b8665a9e1ed0 New file. Simply #define LSTAT and include stat.c.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7581
diff changeset
5 This program is free software: you can redistribute it and/or modify
4061
b8665a9e1ed0 New file. Simply #define LSTAT and include stat.c.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7581
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7581
diff changeset
8 (at your option) any later version.
4061
b8665a9e1ed0 New file. Simply #define LSTAT and include stat.c.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
9
b8665a9e1ed0 New file. Simply #define LSTAT and include stat.c.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
b8665a9e1ed0 New file. Simply #define LSTAT and include stat.c.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
b8665a9e1ed0 New file. Simply #define LSTAT and include stat.c.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b8665a9e1ed0 New file. Simply #define LSTAT and include stat.c.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
13 GNU General Public License for more details.
b8665a9e1ed0 New file. Simply #define LSTAT and include stat.c.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
14
b8665a9e1ed0 New file. Simply #define LSTAT and include stat.c.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7581
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
4061
b8665a9e1ed0 New file. Simply #define LSTAT and include stat.c.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
17
5933
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
18 /* written by Jim Meyering */
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
19
15538
9fd857e43955 Avoid endless recursions if config.h includes some header files.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
20 /* If the user's config.h happens to include <sys/stat.h>, let it include only
9fd857e43955 Avoid endless recursions if config.h includes some header files.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
21 the system's <sys/stat.h> here, so that orig_lstat doesn't recurse to
9fd857e43955 Avoid endless recursions if config.h includes some header files.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
22 rpl_lstat. */
9fd857e43955 Avoid endless recursions if config.h includes some header files.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
23 #define __need_system_sys_stat_h
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 6641
diff changeset
24 #include <config.h>
5933
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
25
12064
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
26 #if !HAVE_LSTAT
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
27 /* On systems that lack symlinks, our replacement <sys/stat.h> already
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
28 defined lstat as stat, so there is nothing further to do other than
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
29 avoid an empty file. */
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
30 typedef int dummy;
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
31 #else /* HAVE_LSTAT */
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
32
12039
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
33 /* Get the original definition of lstat. It might be defined as a macro. */
12064
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
34 # include <sys/types.h>
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
35 # include <sys/stat.h>
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
36 # undef __need_system_sys_stat_h
10688
989b49566cae Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
37
17188
d7a44f0f7a15 ftruncate, fts, lstat, openat, raise: no 'static inline'
Paul Eggert <eggert@cs.ucla.edu>
parents: 16235
diff changeset
38 static int
10688
989b49566cae Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
39 orig_lstat (const char *filename, struct stat *buf)
989b49566cae Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
40 {
989b49566cae Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
41 return lstat (filename, buf);
989b49566cae Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
42 }
989b49566cae Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
43
989b49566cae Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
44 /* Specification. */
15583
716e67b8d5a9 openat: Work around compilation error with OSF/1 5.1 DTK cc.
Bruno Haible <bruno@clisp.org>
parents: 15538
diff changeset
45 /* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
716e67b8d5a9 openat: Work around compilation error with OSF/1 5.1 DTK cc.
Bruno Haible <bruno@clisp.org>
parents: 15538
diff changeset
46 eliminates this include because of the preliminary #include <sys/stat.h>
716e67b8d5a9 openat: Work around compilation error with OSF/1 5.1 DTK cc.
Bruno Haible <bruno@clisp.org>
parents: 15538
diff changeset
47 above. */
716e67b8d5a9 openat: Work around compilation error with OSF/1 5.1 DTK cc.
Bruno Haible <bruno@clisp.org>
parents: 15538
diff changeset
48 # include "sys/stat.h"
10688
989b49566cae Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
49
12064
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
50 # include <string.h>
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
51 # include <errno.h>
5933
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
52
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
53 /* lstat works differently on Linux and Solaris systems. POSIX (see
16235
18a38c9615f0 In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
54 "pathname resolution" in the glossary) requires that programs like
18a38c9615f0 In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
55 'ls' take into consideration the fact that FILE has a trailing slash
6641
884bb4ba6eae Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
56 when FILE is a symbolic link. On Linux and Solaris 10 systems, the
884bb4ba6eae Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
57 lstat function already has the desired semantics (in treating
16235
18a38c9615f0 In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
58 'lstat ("symlink/", sbuf)' just like 'lstat ("symlink/.", sbuf)',
6641
884bb4ba6eae Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
59 but on Solaris 9 and earlier it does not.
5933
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
60
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
61 If FILE has a trailing slash and specifies a symbolic link,
6641
884bb4ba6eae Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
62 then use stat() to get more info on the referent of FILE.
884bb4ba6eae Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
63 If the referent is a non-directory, then set errno to ENOTDIR
884bb4ba6eae Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
64 and return -1. Otherwise, return stat's result. */
5933
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
65
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
66 int
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
67 rpl_lstat (const char *file, struct stat *sbuf)
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
68 {
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
69 size_t len;
10688
989b49566cae Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
70 int lstat_result = orig_lstat (file, sbuf);
5933
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
71
12039
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
72 if (lstat_result != 0)
5933
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
73 return lstat_result;
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
74
12039
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
75 /* This replacement file can blindly check against '/' rather than
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
76 using the ISSLASH macro, because all platforms with '\\' either
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
77 lack symlinks (mingw) or have working lstat (cygwin) and thus do
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
78 not compile this file. 0 len should have already been filtered
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
79 out above, with a failure return of ENOENT. */
5933
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
80 len = strlen (file);
12039
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
81 if (file[len - 1] != '/' || S_ISDIR (sbuf->st_mode))
6641
884bb4ba6eae Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
82 return 0;
5933
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
83
12039
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
84 /* At this point, a trailing slash is only permitted on
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
85 symlink-to-dir; but it should have found information on the
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
86 directory, not the symlink. Call stat() to get info about the
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
87 link's referent. Our replacement stat guarantees valid results,
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
88 even if the symlink is not pointing to a directory. */
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
89 if (!S_ISLNK (sbuf->st_mode))
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
90 {
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
91 errno = ENOTDIR;
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
92 return -1;
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
93 }
eacd308b94de lstat: fix Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 10688
diff changeset
94 return stat (file, sbuf);
5933
35504bd557fa Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents: 5848
diff changeset
95 }
12064
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
96
e9a820d62f5a lstat: avoid mingw compilation error
Eric Blake <ebb9@byu.net>
parents: 12039
diff changeset
97 #endif /* HAVE_LSTAT */