change log updated
[public/netxms.git] / include / nxstat.h
1 /*
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
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)
35
36 #define NX_STAT _tstati64
37 #define NX_FSTAT _fstati64
38 #define NX_STAT_STRUCT struct _stati64
39
40 #elif HAVE_LSTAT64 && HAVE_STRUCT_STAT64
41
42 #define NX_STAT lstat64
43 #define NX_FSTAT fstat64
44 #define NX_STAT_FOLLOW_SYMLINK stat64
45 #define NX_STAT_STRUCT struct stat64
46
47 #else
48
49 #define NX_STAT lstat
50 #define NX_FSTAT fstat
51 #define NX_STAT_FOLLOW_SYMLINK stat
52 #define NX_STAT_STRUCT struct stat
53
54 #endif
55
56 #if defined(UNICODE) && !defined(_WIN32)
57 inline int __call_stat(const WCHAR *f, NX_STAT_STRUCT *s, bool follow)
58 {
59 char *mbf = MBStringFromWideString(f);
60 int rc = follow ? NX_STAT_FOLLOW_SYMLINK(mbf, s) : NX_STAT(mbf, s);
61 free(mbf);
62 return rc;
63 }
64 #define CALL_STAT(f, s) __call_stat(f, s, false)
65 #define CALL_STAT_FOLLOW_SYMLINK(f, s) __call_stat(f, s, true)
66 #else
67 #define CALL_STAT(f, s) NX_STAT(f, s)
68 #define CALL_STAT_FOLLOW_SYMLINK(f, s) NX_STAT_FOLLOW_SYMLINK(f, s)
69 #endif
70
71 #endif