VirtualBox

source: kBuild/vendor/grep/2.12/lib/fstat.c

Last change on this file was 2595, checked in by bird, 12 years ago

gnu grep version 2.12 (grep-2.12.tar.xz, md5sum=8d2f0346d08b13c18afb81f0e8aa1e2f)

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1/* fstat() replacement.
2 Copyright (C) 2011-2012 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17/* If the user's config.h happens to include <sys/stat.h>, let it include only
18 the system's <sys/stat.h> here, so that orig_fstat doesn't recurse to
19 rpl_fstat. */
20#define __need_system_sys_stat_h
21#include <config.h>
22
23/* Get the original definition of fstat. It might be defined as a macro. */
24#include <sys/types.h>
25#include <sys/stat.h>
26#if _GL_WINDOWS_64_BIT_ST_SIZE
27# define stat _stati64
28# define fstat _fstati64
29#endif
30#undef __need_system_sys_stat_h
31
32static inline int
33orig_fstat (int fd, struct stat *buf)
34{
35 return fstat (fd, buf);
36}
37
38/* Specification. */
39/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
40 eliminates this include because of the preliminary #include <sys/stat.h>
41 above. */
42#include "sys/stat.h"
43
44#include <errno.h>
45#include <unistd.h>
46
47#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
48# include "msvc-inval.h"
49#endif
50
51#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
52static inline int
53fstat_nothrow (int fd, struct stat *buf)
54{
55 int result;
56
57 TRY_MSVC_INVAL
58 {
59 result = orig_fstat (fd, buf);
60 }
61 CATCH_MSVC_INVAL
62 {
63 result = -1;
64 errno = EBADF;
65 }
66 DONE_MSVC_INVAL;
67
68 return result;
69}
70#else
71# define fstat_nothrow orig_fstat
72#endif
73
74int
75rpl_fstat (int fd, struct stat *buf)
76{
77#if REPLACE_FCHDIR && REPLACE_OPEN_DIRECTORY
78 /* Handle the case when rpl_open() used a dummy file descriptor to work
79 around an open() that can't normally visit directories. */
80 const char *name = _gl_directory_name (fd);
81 if (name != NULL)
82 return stat (name, buf);
83#endif
84
85 return fstat_nothrow (fd, buf);
86}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette