1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <ctype.h> #include <errno.h> #include <sys/types.h> int dbus_objpath_alnumify(char *path) { for (size_t i = 0; path[i]; i++) { if (!isalnum(path[i]) && path[i] != '/') path[i] = '_'; else if (i > 0 && path[i] == '/' && path[i - 1] == '/') return -EINVAL; } return 0; }