de880fa7258c2a2afe025eb9b38ab06c39f65c13
[public/netxms.git] / src / libnetxms / dirw_unix.c
1 /*
2 ** NetXMS - Network Management System
3 ** Utility Library
4 ** Copyright (C) 2003-2013 Raden Solutions
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published
8 ** by the Free Software Foundation; either version 3 of the License, or
9 ** (at your option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **
20 **/
21
22 #include "libnetxms.h"
23 #include <sys/stat.h>
24
25 #ifdef UNICODE
26
27 /**
28 * opendir() wrapper
29 */
30 DIRW *wopendir(const WCHAR *name)
31 {
32 char *utf8name = UTF8StringFromWideString(name);
33 DIR *dir = opendir(utf8name);
34 free(utf8name);
35 if (dir == NULL)
36 return NULL;
37 DIRW *d = (DIRW *)malloc(sizeof(DIRW));
38 d->dir = dir;
39 return d;
40 }
41
42 /**
43 * readdir() wrapper
44 */
45 struct dirent_w *wreaddir(DIRW *dirp)
46 {
47 struct dirent *d = readdir(dirp->dir);
48 if (d == NULL)
49 return NULL;
50 MultiByteToWideChar(CP_UTF8, 0, d->d_name, -1, dirp->dirstr.d_name, 257);
51 dirp->dirstr.d_name[256] = 0;
52 dirp->dirstr.d_ino = d->d_ino;
53 return &dirp->dirstr;
54 }
55
56 /*
57 * closedir() wrapper
58 */
59 int wclosedir(DIRW *dirp)
60 {
61 closedir(dirp->dir);
62 free(dirp);
63 return 0;
64 }
65
66 #endif