From: Nicholas Nethercote Date: Fri, 23 Nov 2007 22:37:35 +0000 (+0000) Subject: Tweak VG_(expand_file_name), as per Josef's suggestions. X-Git-Tag: svn/VALGRIND_3_3_0~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d236e4fb235400e642250e1a7ee107bd5c6104d;p=thirdparty%2Fvalgrind.git Tweak VG_(expand_file_name), as per Josef's suggestions. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7204 --- diff --git a/coregrind/m_options.c b/coregrind/m_options.c index 1e32a20b4b..6326971d86 100644 --- a/coregrind/m_options.c +++ b/coregrind/m_options.c @@ -144,11 +144,18 @@ Char* VG_(expand_file_name)(Char* option_name, Char* format) goto bad; } + // If 'format' starts with a '/', do not prefix with startup dir. + if (format[0] != '/') { + j += VG_(strlen)(base_dir); + } + // The 10 is slop, it should be enough in most cases. - j = VG_(strlen)(base_dir); len = j + VG_(strlen)(format) + 10; out = VG_(malloc)( len ); - VG_(strcpy)(out, base_dir); + if (format[0] != '/') { + VG_(strcpy)(out, base_dir); + out[j++] = '/'; + } #define ENSURE_THIS_MUCH_SPACE(x) \ if (j + x >= len) { \ @@ -156,7 +163,6 @@ Char* VG_(expand_file_name)(Char* option_name, Char* format) out = VG_(realloc)(out, len); \ } - out[j++] = '/'; while (format[i]) { if (format[i] != '%') { ENSURE_THIS_MUCH_SPACE(1); @@ -178,35 +184,44 @@ Char* VG_(expand_file_name)(Char* option_name, Char* format) j += VG_(sprintf)(&out[j], "%d", pid); i++; } - else if ('q' == format[i] && '{' == format[i+1]) { - // Get the env var name, print its contents. - Char* qualname; - Char* qual; - i += 2; - qualname = &format[i]; - while (True) { - if (0 == format[i]) { - VG_(message)(Vg_UserMsg, "%s: malformed %%q specifier", - option_name); - goto bad; - } else if ('}' == format[i]) { - // Temporarily replace the '}' with NUL to extract var name. - format[i] = 0; - qual = VG_(getenv)(qualname); - if (NULL == qual) { - VG_(message)(Vg_UserMsg, - "%s: environment variable %s is not set", - option_name, qualname); + else if ('q' == format[i]) { + i++; + if ('{' == format[i]) { + // Get the env var name, print its contents. + Char* qualname; + Char* qual; + i++; + qualname = &format[i]; + while (True) { + if (0 == format[i]) { + VG_(message)(Vg_UserMsg, "%s: malformed %%q specifier", + option_name); goto bad; + } else if ('}' == format[i]) { + // Temporarily replace the '}' with NUL to extract var + // name. + format[i] = 0; + qual = VG_(getenv)(qualname); + if (NULL == qual) { + VG_(message)(Vg_UserMsg, + "%s: environment variable %s is not set", + option_name, qualname); + format[i] = '}'; // Put the '}' back. + goto bad; + } + format[i] = '}'; // Put the '}' back. + i++; + break; } - format[i] = '}'; // Put the '}' back. i++; - break; } - i++; + ENSURE_THIS_MUCH_SPACE(VG_(strlen)(qual)); + j += VG_(sprintf)(&out[j], "%s", qual); + } else { + VG_(message)(Vg_UserMsg, + "%s: expected '{' after '%%q'", option_name); + goto bad; } - ENSURE_THIS_MUCH_SPACE(VG_(strlen)(qual)); - j += VG_(sprintf)(&out[j], "%s", qual); } else { // Something else, abort. diff --git a/include/pub_tool_options.h b/include/pub_tool_options.h index c03920b408..7ecac7799c 100644 --- a/include/pub_tool_options.h +++ b/include/pub_tool_options.h @@ -130,6 +130,9 @@ extern void VG_(err_bad_option) ( Char* opt ); isn't set, we abort. If the "{QUAL}" part is malformed, we abort. - "%%" is replaced with "%". Anything else after '%' causes an abort. + If the format specifies a relative file name, it's put in the program's + initial working directory. If it specifies an absolute file name (ie. + starts with '/') then it is put there. */ extern Char* VG_(expand_file_name)(Char* option_name, Char* format);