10.03.2015 20:30, Aneesh Kumar K.V wrote: > Michael Tokarev <m...@tls.msk.ru> writes: > >> Omit one unnecessary memory allocation for components of the path >> and create the resulting path directly given lengths of the components. >> >> This uses (char*) cast because basename() accepts a char* without const, >> for unknown reason. Maybe it is better to use strrchr(), but I'm not >> sure for various forms of directory component delimiter. > > basename(3) says: > Both dirname() and basename() may modify the contents of path, so it may > be desirable to pass a copy when calling one of these functions
The same manpage also says that there are 2 versions of basename(3), one modifies its arg while another doesn't, and they return different results in some corner cases. Which one will be used depends on the compiler flags. So I think it really is better to open-code it here to have guaranteed consistent results. I'll send a v2. [] > I am not sure whether we really need all these cleanups without really > fixing anyi specific issue. This is not a cleanup, it is an optimization: it removes one completely unnecessary memory allocation. Not in a hottest path but I think it is worth this small effor anyway. Thanks, /mjt