[GRASS5] winGRASS: mingw32 and execl (g.list)
Glynn Clements
glynn at gclements.plus.com
Thu Jan 26 10:41:23 EST 2006
Markus Neteler wrote:
> > > Now a question: While 'g.list' compiled, it just does not display
> > > anything and exits. May execl() be the problem?
> > > general/manage/cmd/list.c
> >
>
> OK, it's not execl().
>
> The problem is here:
> lib/gis/list.c
>
> if (lister)
> sprintf(buf,"ls '%s'", path);
> else
> sprintf(buf,"ls -C '%s'", path);
>
> which is unlikely to work in MS-Windows. No idea, how to
> solve that, though. Someone may implement a workaround
> for MS-Windows.
For Unix, the standard way to enumerate a directory's contents is
with opendir/readdir/closedir, e.g.:
DIR *dir = opendir(path);
for (;;)
{
struct dirent *d = readdir(dir);
if (!d)
break;
puts(d->d_name);
}
closedir(dir);
Windows has FindFirstFile/FindNextFile/FindClose, e.g.:
WIN32_FIND_DATA data;
HANDLE handle;
handle = FindFirstFile("*", &data);
for (;;)
{
if (!handle)
break;
puts(data.cFileName);
if (!FindNextFile(handle, &data))
break;
}
FindClose(handle);
More generally, we should stop spawning external programs for simple
tasks, e.g. ls, rm, mv, cat. We need to examine all uses of system(),
G_system() and G_popen(). Many (most?) of those calls will introduce
portability issues.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list