Commit | Line | Data |
---|---|---|
e0fed3f7 | 1 | /* |
390271e0 VK |
2 | ** NetXMS - Network Management System |
3 | ** Copyright (C) 2003-2013 Victor Kirhenshtein | |
4 | ** | |
5 | ** This program is free software; you can redistribute it and/or modify | |
6 | ** it under the terms of the GNU Lesser 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. | |
9 | ** | |
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. | |
14 | ** | |
15 | ** You should have received a copy of the GNU Lesser General Public License | |
16 | ** along with this program; if not, write to the Free Software | |
17 | ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 | ** | |
19 | ** File: nxstat.h | |
20 | ** | |
21 | **/ | |
22 | ||
279cb65b VK |
23 | #ifndef _nxstat_h_ |
24 | #define _nxstat_h_ | |
25 | ||
26 | #ifndef S_ISDIR | |
27 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) | |
28 | #endif | |
29 | ||
30 | #ifndef S_ISREG | |
31 | #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) | |
32 | #endif | |
33 | ||
34 | #if defined(_WIN32) | |
390271e0 | 35 | |
279cb65b | 36 | #define NX_STAT _tstati64 |
390271e0 | 37 | #define NX_FSTAT _fstati64 |
279cb65b | 38 | #define NX_STAT_STRUCT struct _stati64 |
390271e0 | 39 | |
279cb65b | 40 | #elif HAVE_LSTAT64 && HAVE_STRUCT_STAT64 |
390271e0 | 41 | |
279cb65b | 42 | #define NX_STAT lstat64 |
390271e0 | 43 | #define NX_FSTAT fstat64 |
e0fed3f7 | 44 | #define NX_STAT_FOLLOW_SYMLINK stat64 |
279cb65b | 45 | #define NX_STAT_STRUCT struct stat64 |
390271e0 | 46 | |
279cb65b | 47 | #else |
390271e0 | 48 | |
279cb65b | 49 | #define NX_STAT lstat |
390271e0 | 50 | #define NX_FSTAT fstat |
e0fed3f7 | 51 | #define NX_STAT_FOLLOW_SYMLINK stat |
279cb65b | 52 | #define NX_STAT_STRUCT struct stat |
390271e0 | 53 | |
279cb65b VK |
54 | #endif |
55 | ||
56 | #if defined(UNICODE) && !defined(_WIN32) | |
e0fed3f7 | 57 | inline int __call_stat(const WCHAR *f, NX_STAT_STRUCT *s, bool follow) |
279cb65b VK |
58 | { |
59 | char *mbf = MBStringFromWideString(f); | |
e0fed3f7 | 60 | int rc = follow ? NX_STAT_FOLLOW_SYMLINK(mbf, s) : NX_STAT(mbf, s); |
279cb65b VK |
61 | free(mbf); |
62 | return rc; | |
63 | } | |
e0fed3f7 | 64 | #define CALL_STAT(f, s) __call_stat(f, s, false) |
65 | #define CALL_STAT_FOLLOW_SYMLINK(f, s) __call_stat(f, s, true) | |
279cb65b VK |
66 | #else |
67 | #define CALL_STAT(f, s) NX_STAT(f, s) | |
e0fed3f7 | 68 | #define CALL_STAT_FOLLOW_SYMLINK(f, s) NX_STAT_FOLLOW_SYMLINK(f, s) |
279cb65b VK |
69 | #endif |
70 | ||
71 | #endif |