This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
On 12/21/2017 02:13 AM, Martin Liška wrote:
On 12/20/2017 06:45 PM, Jakub Jelinek wrote:Another thing is that the "/" in there is wrong, so const char dir_separator_str[] = { DIR_SEPARATOR, '\0' }; char *b = concat (profile_data_prefix, dir_separator_str, pwd, NULL); needs to be used instead.This looks much nicer, I forgot about DIR_SEPARATOR.Does profile_data_prefix have any dir separators stripped from the end?That's easy to achieve..Is pwd guaranteed to be relative in this case?.. however this is absolute path, which would be problematic on a DOC based FS. Maybe we should do the same path mangling as we do for purpose of gcov: https://github.com/gcc-mirror/gcc/blob/master/gcc/gcov.c#L2424 What do you think about it? Regarding the string manipulation: I'm not an expert, but work with string in C is for me always a pain :)
For me too, especially when using the lowest level APIs like memcpy or even strcpy. Higher-level interfaces like this concat or sprintf (and asprintf) take away the onerous tedium of getting the character counts and offsets right. C++ std::string makes it completely trivial by also managing memory: std::string path = prefix + separator + suffix; String may not be appropriate everywhere but for things where the space overhead isn't significant (e.g., pathnames) it's the right tool for the job. (Trying to use string in the case of this small change probably wouldn't make sense without also making the change in the rest of the file.) Martin
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |