Skip to content

Commit e9d384d

Browse files
committed
added glob support
git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@45798 379a1393-f5fb-40a0-bcee-ef074d9b53f7
1 parent 77626a7 commit e9d384d

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/** \file archdep_glob.h
2+
* \brief very minimalistic glob()
3+
* \author pottendo
4+
*
5+
* OS support:
6+
* - Linux
7+
* - Windows
8+
* - BSD
9+
* - MacOS
10+
* - Haiku
11+
*/
12+
13+
/*
14+
* This file is part of VICE, the Versatile Commodore Emulator.
15+
* See README for copyright notice.
16+
*
17+
* This program is free software; you can redistribute it and/or modify
18+
* it under the terms of the GNU General Public License as published by
19+
* the Free Software Foundation; either version 2 of the License, or
20+
* (at your option) any later version.
21+
*
22+
* This program is distributed in the hope that it will be useful,
23+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+
* GNU General Public License for more details.
26+
*
27+
* You should have received a copy of the GNU General Public License
28+
* along with this program; if not, write to the Free Software
29+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
30+
* 02111-1307 USA.
31+
*
32+
*/
33+
34+
#ifndef VICE_ARCHDEP_GLOB_H
35+
#define VICE_ARCHDEP_GLOB_H
36+
37+
#if defined(UNIX_COMPILE)
38+
#if defined (HAVE_GLOB_H)
39+
#include <glob.h>
40+
#endif
41+
#endif
42+
43+
#if defined (WINDOWS_COMPILE)
44+
#include <stdlib.h>
45+
46+
typedef struct {
47+
size_t gl_pathc; /* Count of paths matched so far */
48+
char **gl_pathv; /* List of matched pathnames. */
49+
size_t gl_offs; /* Slots to reserve in gl_pathv. */
50+
} glob_t;
51+
52+
/* expects an absolute path for pattern and many glob() functions are NOT implemented */
53+
int glob(const char *pattern, int flags, void *errfunc, glob_t *pglob);
54+
void globfree(glob_t *pglob);
55+
56+
#endif
57+
58+
#endif

0 commit comments

Comments
 (0)