From cee9c53a51cdbd7d3f9a8395de37570be5687db8 Mon Sep 17 00:00:00 2001 From: Hunter Date: Sat, 13 Oct 2018 01:29:11 +0800 Subject: Fix win file type (#749) before: nni_file_is_dir with path D:\\ D:/ D: all returns false after: nni_file_is_dir with path D:\\ D:/ D: all returns true --- src/platform/windows/win_file.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/platform/windows/win_file.c') diff --git a/src/platform/windows/win_file.c b/src/platform/windows/win_file.c index 47bb87af..4fc5930f 100644 --- a/src/platform/windows/win_file.c +++ b/src/platform/windows/win_file.c @@ -1,6 +1,7 @@ // // Copyright 2018 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV +// Copyright 2018 QXSoftware // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -281,18 +282,16 @@ nni_plat_temp_dir(void) int nni_plat_file_type(const char *name, int *typep) { - HANDLE dirh; - WIN32_FIND_DATA data; + DWORD attrs; - if ((dirh = FindFirstFile(name, &data)) == INVALID_HANDLE_VALUE) { + if ((attrs = GetFileAttributes(name)) == INVALID_FILE_ATTRIBUTES) { return (nni_win_error(GetLastError())); } - (void) FindClose(dirh); - if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + if (attrs & FILE_ATTRIBUTE_DIRECTORY) { *typep = NNI_PLAT_FILE_TYPE_DIR; - } else if (data.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) { + } else if (attrs & FILE_ATTRIBUTE_DEVICE) { *typep = NNI_PLAT_FILE_TYPE_OTHER; - } else if (data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) { + } else if (attrs & FILE_ATTRIBUTE_HIDDEN) { *typep = NNI_PLAT_FILE_TYPE_OTHER; } else { *typep = NNI_PLAT_FILE_TYPE_FILE; -- cgit v1.2.3-70-g09d2