Debian Codegraph @

src/__lxstat64.c

raw
1 /*
2 libfakechroot -- fake chroot environment
3 Copyright (c) 2010, 2013, 2015 Piotr Roszatycki <[email protected]>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library 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 GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20
21 #include <config.h>
22
23 #ifdef HAVE___LXSTAT64
24
25 #define _LARGEFILE64_SOURCE
26 #define _XOPEN_SOURCE 500
27 #include <sys/stat.h>
28 #include <unistd.h>
29 #include <fcntl.h>
30
31 #include "libfakechroot.h"
32 #include "readlink.h"
33
34
35 LOCAL int __lxstat64_rel(int, const char *, struct stat64 *);
36
37
38 wrapper(__lxstat64, int, (int ver, const char * filename, struct stat64 * buf))
39 {
40 debug("__lxstat64(%d, \"%s\", &buf)", ver, filename);
41
42 if (filename && !fakechroot_localdir(filename)) {
43 char abs_filename[FAKECHROOT_PATH_MAX];
44 rel2abs(filename, abs_filename);
45 filename = abs_filename;
46 }
47
48 return __lxstat64_rel(ver, filename, buf);
49 }
50
51
52 /* Prevent looping with realpath() */
53 LOCAL int __lxstat64_rel(int ver, const char * filename, struct stat64 * buf)
54 {
55 char fakechroot_buf[FAKECHROOT_PATH_MAX];
56
57 char tmp[FAKECHROOT_PATH_MAX];
58 int retval;
59 READLINK_TYPE_RETURN linksize;
60 const char *orig_filename;
61
62 debug("__lxstat64_rel(%d, \"%s\", &buf)", ver, filename);
63 orig_filename = filename;
64 expand_chroot_rel_path(filename);
65 retval = nextcall(__lxstat64)(ver, filename, buf);
66 /* deal with http://bugs.debian.org/561991 */
67 if ((retval == 0) && (buf->st_mode & S_IFMT) == S_IFLNK)
68 if ((linksize = readlink(orig_filename, tmp, sizeof(tmp)-1)) != -1)
69 buf->st_size = linksize;
70
71 return retval;
72 }
73
74
75 #else
76 typedef int empty_translation_unit;
77 #endif