Mercurial > hg > octave-kai > gnulib-hg
annotate lib/lstat.c @ 10690:01f3623813da
Split winsock.c into many smaller files.
* lib/close.c: Add _gl_close_fd_maybe_socket from winsock.c.
* lib/accept.c: New file, based on winsock.c.
* lib/bind.c: New file, based on winsock.c.
* lib/connect.c: New file, based on winsock.c.
* lib/getpeername.c: New file, based on winsock.c.
* lib/getsockname.c: New file, based on winsock.c.
* lib/getsockopt.c: New file, based on winsock.c.
* lib/ioctl.c: New file, based on winsock.c.
* lib/listen.c: New file, based on winsock.c.
* lib/recv.c: New file, based on winsock.c.
* lib/recvfrom.c: New file, based on winsock.c.
* lib/send.c: New file, based on winsock.c.
* lib/sendto.c: New file, based on winsock.c.
* lib/setsockopt.c: New file, based on winsock.c.
* lib/shutdown.c: New file, based on winsock.c.
* lib/socket.c: New file, based on winsock.c.
* lib/w32sock.h: New file, based on winsock.c.
* lib/winsock.c: Remove file.
* modules/accept: Likewise.
* modules/bind: Likewise.
* modules/connect: Likewise.
* modules/getpeername: Likewise.
* modules/getsockname: Likewise.
* modules/getsockopt: Likewise.
* modules/ioctl: Likewise.
* modules/listen: Likewise.
* modules/recv: Likewise.
* modules/recvfrom: Likewise.
* modules/send: Likewise.
* modules/sendto: Likewise.
* modules/setsockopt: Likewise.
* modules/shutdown: Likewise.
* modules/socket: Use socket.c instead of winsock.c.
* modules/sys_socket: Remove (unneeded?) dependency on winsock.c.
* doc/posix-functions/accept.texi: Doc fix.
* doc/posix-functions/bind.texi: Doc fix.
* doc/posix-functions/close.texi: Doc fix.
* doc/posix-functions/connect.texi: Doc fix.
* doc/posix-functions/getpeername.texi: Doc fix.
* doc/posix-functions/getsockname.texi: Doc fix.
* doc/posix-functions/getsockopt.texi: Doc fix.
* doc/posix-functions/ioctl.texi: Doc fix.
* doc/posix-functions/listen.texi: Doc fix.
* doc/posix-functions/recv.texi: Doc fix.
* doc/posix-functions/recvfrom.texi: Doc fix.
* doc/posix-functions/send.texi: Doc fix.
* doc/posix-functions/sendto.texi: Doc fix.
* doc/posix-functions/setsockopt.texi: Doc fix.
* doc/posix-functions/shutdown.texi: Doc fix.
* doc/posix-functions/socket.texi: Doc fix.
author | Simon Josefsson <simon@josefsson.org> |
---|---|
date | Tue, 21 Oct 2008 12:17:19 +0200 |
parents | 989b49566cae |
children | eacd308b94de |
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 |
10688
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
3 Copyright (C) 1997-1999, 2000-2006, 2008 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 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6641
diff
changeset
|
20 #include <config.h> |
5933
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
21 |
10688
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
22 /* Get the original definition of open. It might be defined as a macro. */ |
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
23 #define __need_system_sys_stat_h |
5933
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
24 #include <sys/types.h> |
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
25 #include <sys/stat.h> |
10688
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
26 #undef __need_system_sys_stat_h |
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
27 |
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
28 static inline int |
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
29 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
|
30 { |
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
31 return lstat (filename, buf); |
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
32 } |
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
33 |
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
34 /* Specification. */ |
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
35 #include <sys/stat.h> |
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
36 |
5933
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
37 #include <string.h> |
6641 | 38 #include <errno.h> |
5933
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
39 |
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
40 /* lstat works differently on Linux and Solaris systems. POSIX (see |
6641 | 41 `pathname resolution' in the glossary) requires that programs like |
42 `ls' take into consideration the fact that FILE has a trailing slash | |
43 when FILE is a symbolic link. On Linux and Solaris 10 systems, the | |
44 lstat function already has the desired semantics (in treating | |
45 `lstat ("symlink/", sbuf)' just like `lstat ("symlink/.", sbuf)', | |
46 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
|
47 |
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
48 If FILE has a trailing slash and specifies a symbolic link, |
6641 | 49 then use stat() to get more info on the referent of FILE. |
50 If the referent is a non-directory, then set errno to ENOTDIR | |
51 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
|
52 |
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
53 int |
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
54 rpl_lstat (const char *file, struct stat *sbuf) |
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
55 { |
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
56 size_t len; |
10688
989b49566cae
Move the lstat() declaration to <sys/stat.h>.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
57 int lstat_result = orig_lstat (file, sbuf); |
5933
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
58 |
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
59 if (lstat_result != 0 || !S_ISLNK (sbuf->st_mode)) |
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
60 return lstat_result; |
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
61 |
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
62 len = strlen (file); |
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
63 if (len == 0 || file[len - 1] != '/') |
6641 | 64 return 0; |
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 /* FILE refers to a symbolic link and the name ends with a slash. |
6641 | 67 Call stat() to get info about the link's referent. */ |
68 | |
69 /* If stat fails, then we do the same. */ | |
70 if (stat (file, sbuf) != 0) | |
71 return -1; | |
5933
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
72 |
6641 | 73 /* If FILE references a directory, return 0. */ |
74 if (S_ISDIR (sbuf->st_mode)) | |
75 return 0; | |
5933
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
76 |
6641 | 77 /* Here, we know stat succeeded and FILE references a non-directory. |
78 But it was specified via a name including a trailing slash. | |
79 Fail with errno set to ENOTDIR to indicate the contradiction. */ | |
80 errno = ENOTDIR; | |
81 return -1; | |
5933
35504bd557fa
Remove stat module & update lstat.
Derek R. Price <derek@ximbiot.com>
parents:
5848
diff
changeset
|
82 } |