X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Futil.c;h=e9284809e34bbd956a0b892f67e188a97e70a95b;hb=36775dad3505929f8370166c33e8e0f04ca96c1c;hp=6c152e24d1231247af779557ca18de4e5b668ebe;hpb=0fec26b00be202f828193a66ed35c842389588f4;p=openvswitch diff --git a/lib/util.c b/lib/util.c index 6c152e24..e9284809 100644 --- a/lib/util.c +++ b/lib/util.c @@ -357,3 +357,35 @@ hexit_value(int c) NOT_REACHED(); } + +/* Returns the directory name portion of 'file_name' as a malloc()'d string, + * similar to the POSIX dirname() function but thread-safe. */ +char * +dir_name(const char *file_name) +{ + size_t len = strlen(file_name); + while (len > 0 && file_name[len - 1] == '/') { + len--; + } + while (len > 0 && file_name[len - 1] != '/') { + len--; + } + while (len > 0 && file_name[len - 1] == '/') { + len--; + } + if (!len) { + return xstrdup((file_name[0] == '/' + && file_name[1] == '/' + && file_name[2] != '/') ? "//" + : file_name[0] == '/' ? "/" + : "."); + } else { + return xmemdup0(file_name, len); + } +} + +/* Pass a value to this function if it is marked with + * __attribute__((warn_unused_result)) and you genuinely want to ignore + * its return value. (Note that every scalar type can be implicitly + * converted to bool.) */ +void ignore(bool x UNUSED) { }