From a6163888f3c56123b1db313743c6147ba498732c Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Fri, 8 Aug 2014 14:42:07 +0300 Subject: Add third_party libs --- .../windows/fltk-1.1.10/src/scandir_win32.c | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 third_party/windows/fltk-1.1.10/src/scandir_win32.c (limited to 'third_party/windows/fltk-1.1.10/src/scandir_win32.c') diff --git a/third_party/windows/fltk-1.1.10/src/scandir_win32.c b/third_party/windows/fltk-1.1.10/src/scandir_win32.c new file mode 100644 index 0000000..128060b --- /dev/null +++ b/third_party/windows/fltk-1.1.10/src/scandir_win32.c @@ -0,0 +1,115 @@ +/* + * "$Id: scandir_win32.c 4548 2005-08-29 20:16:36Z matt $" + * + * WIN32 scandir function for the Fast Light Tool Kit (FLTK). + * + * Copyright 1998-2005 by Bill Spitzak and others. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems on the following page: + * + * http://www.fltk.org/str.php + */ + +#ifndef __CYGWIN__ +/* Emulation of posix scandir() call */ + +#include +#include "flstring.h" +#include +#include + +int fl_scandir(const char *dirname, struct dirent ***namelist, + int (*select)(struct dirent *), + int (*compar)(struct dirent **, struct dirent **)) { + int len; + char *findIn, *d, is_dir = 0; + WIN32_FIND_DATA find; + HANDLE h; + int nDir = 0, NDir = 0; + struct dirent **dir = 0, *selectDir; + unsigned long ret; + + len = strlen(dirname); + findIn = (char *)malloc((size_t)(len+5)); + + if (!findIn) return -1; + + strcpy(findIn, dirname); + for (d = findIn; *d; d++) if (*d=='/') *d='\\'; + if ((len==0)) { strcpy(findIn, ".\\*"); } + if ((len==2)&&findIn[1]==':'&&isalpha(findIn[0])) { *d++ = '\\'; *d = 0; } + if ((len==1)&& (d[-1]=='.')) { strcpy(findIn, ".\\*"); is_dir = 1; } + if ((len>0) && (d[-1]=='\\')) { *d++ = '*'; *d = 0; is_dir = 1; } + if ((len>1) && (d[-1]=='.') && (d[-2]=='\\')) { d[-1] = '*'; is_dir = 1; } + if (!is_dir) { /* this file may still be a directory that we need to list */ + DWORD attr = GetFileAttributes(findIn); + if (attr&FILE_ATTRIBUTE_DIRECTORY) + strcpy(d, "\\*"); + } + if ((h=FindFirstFile(findIn, &find))==INVALID_HANDLE_VALUE) { + free(findIn); + ret = GetLastError(); + if (ret != ERROR_NO_MORE_FILES) { + nDir = -1; + } + *namelist = dir; + return nDir; + } + do { + selectDir=(struct dirent*)malloc(sizeof(struct dirent)+strlen(find.cFileName)+2); + strcpy(selectDir->d_name, find.cFileName); + if (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + /* Append a trailing slash to directory names... */ + strcat(selectDir->d_name, "/"); + } + if (!select || (*select)(selectDir)) { + if (nDir==NDir) { + struct dirent **tempDir = (struct dirent **)calloc(sizeof(struct dirent*), (size_t)(NDir+33)); + if (NDir) memcpy(tempDir, dir, sizeof(struct dirent*)*NDir); + if (dir) free(dir); + dir = tempDir; + NDir += 32; + } + dir[nDir] = selectDir; + nDir++; + dir[nDir] = 0; + } else { + free(selectDir); + } + } while (FindNextFile(h, &find)); + ret = GetLastError(); + if (ret != ERROR_NO_MORE_FILES) { + /* don't return an error code, because the dir list may still be valid + up to this point */ + } + FindClose(h); + + free (findIn); + + if (compar) qsort(dir, (size_t)nDir, sizeof(*dir), + (int(*)(const void*, const void*))compar); + + *namelist = dir; + return nDir; +} + +#endif + +/* + * End of "$Id: scandir_win32.c 4548 2005-08-29 20:16:36Z matt $". + */ -- cgit v1.3.1