glob() appears to fails if errno is not already zero

Mark Jackson mpfj at mimc.co.uk
Fri Aug 8 11:30:15 UTC 2008


Mark Jackson wrote:
> I'm using 0.9.29 on Atmel's AVR32-based NGW100 dev kit.
> 
> The attached code shows some strange behaviour in the glob() function.

The extra unlink() call can be ignored / removed

> Regards
> Mark
> 
> ---
> 
> #include <stdio.h>
> #include <glob.h>
> #include <errno.h>
> #include <string.h>
> 
> int main(void) {
>     glob_t globbuf;
>     int globret;
>     memset(&globbuf, 0, sizeof(globbuf));
> 
>     globret = glob("/etc/avahi/services/*.service", GLOB_ERR, NULL, &globbuf);
>     printf("test globret = %d\n", globret);
>     globfree(&globbuf);
> 
>     errno = 1;
> 
>     memset(&globbuf, 0, sizeof(globbuf));
>     globret = glob("/etc/avahi/services/*.service", GLOB_ERR, NULL, &globbuf);
>     printf("test globret = %d\n", globret);
>     globfree(&globbuf);
> 
>     unlink("/tmp/missing_file");
> 
>     errno = 0;
> 
>     memset(&globbuf, 0, sizeof(globbuf));
>     globret = glob("/etc/avahi/services/*.service", GLOB_ERR, NULL, &globbuf);
>     printf("test globret = %d\n", globret);
>     globfree(&globbuf);
> }



More information about the uClibc mailing list