glob
chenzhelu
chenzero@netease.com
Fri Jan 16 09:46:36 GMT 2026
You need to add the offset when you are indexing through gl_pathv:
‘gl_pathc’
The number of elements in the vector, excluding the initial
null entries if the GLOB_DOOFFS flag is used (see gl_offs
below).
I don't know why gl_offs even exists, it does not seem very useful.
(The caller cannot supply its own buffer via gl_pathv, and the prefix
is overwritten by null pointers.)
the gl_offs is used to fill user-defined args, e.g:
memset(&globbuf, 0, sizeof(globbuf));
globbuf.gl_offs = 2;
glob("*.c", GLOB_DOOFFS, NULL, &globbuf);
globbuf.gl_pathv[0] = "ls";
globbuf.gl_pathv[1] = "-l";
execvp("ls", &globbuf.gl_pathv[0]);
so, it doesn't create a duplicated array when invoke execvp()
Whether when gl_offs==1 and there are 3 C files in the current dir, it should output as following ?
* (null)
a.c
b.c
c.c
Thanks,
Florian
More information about the Libc-help
mailing list