X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Futil.c;h=e9284809e34bbd956a0b892f67e188a97e70a95b;hb=36775dad3505929f8370166c33e8e0f04ca96c1c;hp=c9ef8b1592dafa186aa3900b097fe832714637c1;hpb=f38b84ea2b6b61d309c604faedd41ab3b0fcf16b;p=openvswitch diff --git a/lib/util.c b/lib/util.c index c9ef8b15..e9284809 100644 --- a/lib/util.c +++ b/lib/util.c @@ -168,8 +168,10 @@ ovs_error(int err_no, const char *format, ...) va_start(args, format); vfprintf(stderr, format, args); va_end(args); - if (err_no != 0) - fprintf(stderr, " (%s)", strerror(err_no)); + if (err_no != 0) { + fprintf(stderr, " (%s)", + err_no == EOF ? "end of file" : strerror(err_no)); + } putc('\n', stderr); errno = save_errno; @@ -355,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) { }