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

Mark Jackson mpfj at mimc.co.uk
Fri Aug 8 11:20:26 UTC 2008


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.

Basically I call glob() three times

First time, globret = 0 so everything was fine

Second time, I set errno to any non-zero value and then call glob().  globret = 2 meaning that glob() failed.

Third time, I set errno back to 0.  Now globret = 0 so the glob() was fine.

AFAIK, no errno should only report what *has* happenned, not affect any future function calls.  Right ?

I raised a ticket on bugs.uclibc.org on 24/07/08, but I've had no response.

Is this a known issue ?  Can someone else confirm the bug ?

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