Glob function (c) and backup file (file~)
I'm using glob function for a autocompletion function. I'm showing you the problem becaus开发者_StackOverflow社区e it's difficult to explain:
matched = ~/.tcsh
glob(matched, 0, NULL, &pglob);
glob put all matched files in a char ** and when I print it I have:
case[0] = .tcshrc
case[1] =
I should have .tcshrc~
in case[1], but nothing =S, I've seen a flag "GLOB_TILDE" like this "
glob(matched, GLOB_TILDE, NULL, &pglob);
But it doesn't change anything! Can someone help me?
The GLOB_TILDE
flag only affects the output when the ~ appears at the beginning of the glob. See here:
http://www.gnu.org/s/libc/manual/html_node/More-Flags-for-Globbing.html
As for your problem, it appears to me that your matched value is wrong. Seems like you should be sticking a *
at the end of it for it to be useful for autocompletion, i.e.:
matched = ~/.tcsh*
I'm a little bit confused as how your previous example found even the first one. The bottom part of this man page article has some interesting examples too:
http://www.opengroup.org/onlinepubs/000095399/functions/glob.html
精彩评论