|
| 1 | +/** \file archdep_glob.c |
| 2 | + * \brief very minimalistic glob() |
| 3 | + * |
| 4 | + * Wrapper for the POSIX glob(3) function. |
| 5 | + * |
| 6 | + * \author pottendo |
| 7 | + * |
| 8 | + * OS support: |
| 9 | + * - Linux |
| 10 | + * - Windows |
| 11 | + * - BSD |
| 12 | + * - MacOS |
| 13 | + * - Haiku |
| 14 | + */ |
| 15 | + |
| 16 | +/* |
| 17 | + * This file is part of VICE, the Versatile Commodore Emulator. |
| 18 | + * See README for copyright notice. |
| 19 | + * |
| 20 | + * This program is free software; you can redistribute it and/or modify |
| 21 | + * it under the terms of the GNU General Public License as published by |
| 22 | + * the Free Software Foundation; either version 2 of the License, or |
| 23 | + * (at your option) any later version. |
| 24 | + * |
| 25 | + * This program is distributed in the hope that it will be useful, |
| 26 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 | + * GNU General Public License for more details. |
| 29 | + * |
| 30 | + * You should have received a copy of the GNU General Public License |
| 31 | + * along with this program; if not, write to the Free Software |
| 32 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 33 | + * 02111-1307 USA. |
| 34 | + * |
| 35 | + */ |
| 36 | + |
| 37 | +#include "vice.h" |
| 38 | + |
| 39 | +#if !defined(UNIX_COMPILE) && !defined(HAIKU_COMPILE) && !defined(WINDOWS_COMPILE) |
| 40 | +# error "Unsupported OS!" |
| 41 | +#endif |
| 42 | + |
| 43 | +#if defined(WINDOWS_COMPILE) |
| 44 | +#include <archdep_glob.h> |
| 45 | +#include <archdep_defs.h> |
| 46 | +#include <windows.h> |
| 47 | +#include <tchar.h> |
| 48 | +#include <stdio.h> |
| 49 | +#include "lib.h" |
| 50 | +#include "util.h" |
| 51 | + |
| 52 | +static char *fh[1]; |
| 53 | + |
| 54 | +/* expects an absolute path for pattern and many glob() functions are NOT implemented */ |
| 55 | +int glob(const char *pattern, int flags, void *errfunc, glob_t *pglob) |
| 56 | +{ |
| 57 | + WIN32_FIND_DATA FindFileData; |
| 58 | + HANDLE hFind; |
| 59 | + if(!pattern) { |
| 60 | + return -1; |
| 61 | + } |
| 62 | + hFind = FindFirstFile(pattern, &FindFileData); |
| 63 | + if (hFind == INVALID_HANDLE_VALUE) { |
| 64 | + return -1; |
| 65 | + } else { |
| 66 | + char tmp[ARCHDEP_PATH_MAX]; |
| 67 | + strcpy(tmp, pattern); |
| 68 | + char *del = strrchr(tmp, '/'); |
| 69 | + char *fn = FindFileData.cFileName; |
| 70 | + if (del) { |
| 71 | + *del = 0; |
| 72 | + fh[0] = util_concat(tmp, "/", fn, NULL); |
| 73 | + } else { |
| 74 | + fh[0] = fn; |
| 75 | + } |
| 76 | + pglob->gl_pathc = 1; |
| 77 | + pglob->gl_offs = 1; |
| 78 | + pglob->gl_pathv = fh; |
| 79 | + FindClose(hFind); |
| 80 | + } |
| 81 | + return 0; |
| 82 | +} |
| 83 | + |
| 84 | +void globfree(glob_t *pglob) |
| 85 | +{ |
| 86 | + lib_free(pglob->gl_pathv[0]); |
| 87 | +} |
| 88 | + |
| 89 | +#endif |
0 commit comments