int Rivet_chdir_file()

in src/mod_rivet_ng/mod_rivet_common.c [793:817]


int Rivet_chdir_file (const char *file)
{
    const char  *x;
    int         chdir_retval = 0;
    char        chdir_buf[HUGE_STRING_LEN];

    x = strrchr(file, '/');
    if (x == NULL) {
#ifdef WIN32
        chdir_retval = _chdir(file);
#else
        chdir_retval = chdir(file);
#endif
    } else if (x - file < sizeof(chdir_buf) - 1) {
        memcpy(chdir_buf, file, x - file);
        chdir_buf[x - file] = '\0';
#ifdef WIN32
        chdir_retval = _chdir(chdir_buf);
#else
        chdir_retval = chdir(chdir_buf);
#endif
    }

    return chdir_retval;
}