Changelog update
[public/netxms.git] / src / libnetxms / dirw_unix.c
CommitLineData
30971556
AK
1/*
2** NetXMS - Network Management System
3** Utility Library
5f77533a 4** Copyright (C) 2003-2017 Raden Solutions
30971556
AK
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
c56c93a3
VK
22#include "libnetxms.h"
23#include <sys/stat.h>
24
25#ifdef UNICODE
26
27/**
28 * opendir() wrapper
29 */
30DIRW *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 */
45struct 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;
5f77533a
VK
53#if HAVE_DIRENT_D_TYPE
54 dirp->dirstr.d_type = d->d_type;
55#endif
c56c93a3
VK
56 return &dirp->dirstr;
57}
58
59/*
60 * closedir() wrapper
61 */
62int wclosedir(DIRW *dirp)
63{
64 closedir(dirp->dir);
65 free(dirp);
66 return 0;
67}
68
69#endif