|
From: Greg J. <gv...@gm...> - 2015-02-07 20:04:37
|
I've been modifying a routine that compiles in mingw, linux, and (lately
not tested tho) MS visual studio.
For everything but glob(), mingw maps pretty good but there is no fnmatch,
so win32/PatternMatch is used.
The directory is opened as follows (c++):
DString root = dirN;
AppendIfNeeded( root, "/");
DIR* dir = opendir( dirN.c_str());
if( dir == NULL) return;
then to scan the directory
struct stat64 statStruct;
#ifdef _WIN32
WCHAR tchrpat[MAX_PATH+1];
WCHAR tchrentry[MAX_PATH+1];
MultiByteToWideChar(CP_UTF8, 0,
(LPCSTR)pat.c_str(), -1,
tchrpat, MAX_PATH+1);
#endif
for(;;)
{
struct dirent* entry = readdir( dir);
if( entry == NULL)
break;
DString entryStr( entry->d_name);
if( entryStr != "." && entryStr != "..")
{
DString testFile = root + entryStr;
int actStat = lstat64( testFile.c_str(), &statStruct);
if( S_ISDIR(statStruct.st_mode) == 0)
{ // only test non-dirs
this is the same, _WIN32 or no. But for matching files you have to do the
unicode dance:
#ifdef _WIN32
MultiByteToWideChar(CP_UTF8, 0,
(LPCSTR)entryStr.c_str(), -1,
tchrentry, MAX_PATH+1);
int match = 1 - PathMatchSpecW(tchrentry, tchrpat);
#else
int match = fnmatch( pat.c_str(), entryStr.c_str(), fnFlags);
#endif
another drop-in replacement that increases compatibiliity:
#ifdef _WIN32
#define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
// ref:http://sourceforge.net/p/mingw/patches/256/ Keith Marshall 2005-12-02
// http://msdn.microsoft.com/en-us/library/506720ff.aspx
#endif
The header dance at the top is another story:
#ifndef _MSC_VER // everything but MS visual studio
# include <unistd.h>
#endif
#ifndef _WIN32
# include <fnmatch.h>
# include <glob.h> // glob in MinGW does not working..... why?
#else
# include <shlwapi.h>
# include <windows.h>
# if !defined(S_IFLNK)
# define S_IFLNK 0xA000
# define S_ISLNK(mode) (((mode) & S_IFLNK) == S_IFLNK)
# endif
#endif
#ifndef _MSC_VER
# include <dirent.h>
#else
# include <io.h>
# define access _access
# define R_OK 4 /* Test for read permission. */
# define W_OK 2 /* Test for write permission. */
//# define X_OK 1 /* execute permission - unsupported in
windows*/
# define F_OK 0 /* Test for existence. */
# define PATH_MAX 255
# include <direct.h>
# if !defined(S_ISDIR)
# define __S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask))
# define S_ISDIR(mode) __S_ISTYPE((mode), S_IFDIR)
# define S_ISREG(mode) __S_ISTYPE((mode), S_IFREG)
#endif
#endif
#ifdef _MSC_VER
/*
Implementation of POSIX directory browsing functions and types for
Win32.
Author: Kevlin Henney (ke...@ac..., ke...@cu...)
History: Created March 1997. Updated June 2003 and July 2012.
Rights: See end of file.
*/
<< Code for MSC_VER case opendir, readdir, etc. >>
#endif
/*
Copyright Kevlin Henney, 1997, 2003, 2012. All rights reserved.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose is hereby granted without fee, provided
that this copyright and permissions notice appear in all copies and
derivatives.
This software is supplied "as is" without express or implied warranty.
But that said, if there are any problems please get in touch.
*/
in my case, I use fstat64, and stat64 but cygwin doesn't:
#ifdef __CYGWIN__
#define stat64 stat
#define lstat64 lstat
// for religious reasons, CYGWIN doesn't do lstat64
#endif
#ifdef _WIN32
//
# define lstat64(x,y) stat64(x,y)
#endif
On Sat, Feb 7, 2015 at 4:14 AM, Miro Kropáček <mir...@gm...>
wrote:
>
> On Sat, Feb 7, 2015 at 12:22 PM, Keith Marshall <
> kei...@us...> wrote:
>
>> #define DIRHANDLE dirp->dd_handle
>
> Perhaps you overlooked this line?
> http://sourceforge.net/p/aranym/code/ci/master/tree/src/gui-sdl/file.cpp#l22
> So it's using the 'fd' member variable. I assure you it does compile :)
>
> All right, I'll see what can I do about that code, thank you.
>
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming. The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is
> your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> MinGW-users mailing list
> Min...@li...
>
> This list observes the Etiquette found at
> http://www.mingw.org/Mailing_Lists.
> We ask that you be polite and do the same. Disregard for the list
> etiquette may cause your account to be moderated.
>
> _______________________________________________
> You may change your MinGW Account Options or unsubscribe at:
> https://lists.sourceforge.net/lists/listinfo/mingw-users
> Also: mailto:min...@li...?subject=unsubscribe
>
|