src/string.c
/**
 * dirname() in libc might not be thread-save, at least the man page states
 * "may return pointers to statically allocated memory", so we need our own
 * implementation
 */
dirname() in libc might not be thread-save, at least the man page states
"may return pointers to statically allocated memory", so we need our own
implementation
dirname () in libc might not be thread - save at least the man page states " may return pointers to statically allocated memory " so we need our own implementation
char *u_dirname(const char *path) {
	DBG_IN();
	char *ret = strdup(path);
	if (ret == NULL) {
		usyslog("strdup failed, probably out of memory!\n");
		return ret;
	}
	char *ri = rindex(ret, '/'); 
	if (ri != NULL) {
		*ri = '\0'; 
	} else {
		strcpy(ret, "."); 
	}
	return ret;
}
char * u_dirname ( const char * path ) { DBG_IN ( ) ; char * ret = strdup ( path ) ; if ( ret == NULL ) { usyslog ( " \n " ) ; return ret ; } char * ri = rindex ( ret , ' ' ) ; if ( ri != NULL ) { * ri = ' \0 ' ; } else { strcpy ( ret , " " ) ; } return ret ; }
dirname() in libc might not be thread-save, at least the man page states
 "may return pointers to statically allocated memory", so we need our own
 implementation
dirname () in libc might not be thread - save at least the man page states " may return pointers to statically allocated memory " so we need our own implementation
// '/' found, so a full path // '/' not found, so path is only a file