|
Message-ID: <940885b3b4b6ed25e4503f216a75adb7@smtp.hushmail.com> Date: Tue, 19 Mar 2013 01:12:54 +0100 From: magnum <john.magnum@...hmail.com> To: john-dev@...ts.openwall.com Subject: Re: basename portability 'fix'. Parts of your patch has CRLF and parts of it does not. This made git disregard most of it as "whitespace errors" :-) Also, I get this: misc.c: In function 'jtr_basename_r': misc.c:199:19: warning: variable 'name' set but not used [-Wunused-but-set-variable] misc.c: In function 'jtr_basename_r': misc.c:199:19: warning: variable 'name' set but not used [-Wunused-but-set-variable] I guess we can just drop all statements that declare or set name? If this is safer than our portability workarounds, I suppose Lukas could merge it to his get_basename() code that also strips an arbitrary list of extensions. magnum On 18 Mar, 2013, at 21:40 , jfoug <jfoug@....net> wrote: > Here is a proper running basename. I build both a 'normal' basename, and a thread safe one. The 'normal' one, simply has a static buffer that it passes into the thread safe one. the reason for the buffer, is I chose to have the name param be a const char *. Some basename's have only a char *, and document that the function can mess with the param. BBAAADDDD, but they do that. Looking at many implementations of basename, it looks like about 50% of them have very bad side effects, or simply do not work properly. > > Here is the function proto's (I put these into misc.c/h > > char *jtr_basename(const char *name) > char *jtr_basename_r(const char *name, char *buf) (buf must be strlen(name)+1, but PATH_BUFFER_SIZE+1 can also be used. > > Here are the 'rules' > > a null name, or name pointing to a length 0 string returns "." > Both Win32 ('\\') and unix ('/') separator chars are handled. In unix builds, only the / is handled. In win32, 'both' are handled, since they actually mean the same thing. > if string is only / or \ chars, then a single / or \ will be returned. > Win32/DOS drive letters are handled. NOTE, a C: by itself, is treated like a string of length 0, and returns "." > Trailing / or \ are removed from final basename, IIF there is a basename. > > This is made against bleeding (since a code freeze is on, I think on the new jumbo). It likely will patch to the jumbo easily, IF someone wants to do that also. > > > To use this, simply do this: > > #include "misc.h" > > char *p = jtr_basename(fullname); > > To use this IF there were in code that had to be thread safe, the jtr_basename_r() function could be used. I do not foresee that need currently, but it is there, since this function needs either a static buffer, OR needs the input parameter to be able to be destroyed. > > Jim. > > > <bleeding_basename_portability_fix.patch>
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.