[postgis-devel] use of strnicmp
a.furieri at lqt.it
a.furieri at lqt.it
Fri Sep 22 10:33:08 PDT 2017
On Fri, 22 Sep 2017 12:47:24 -0400, Greg Troxel wrote:
> Building 2.3.3 on NetBSD, I am running into an error about strnicmp.
> There's a comment in the source about it:
>
> /* if we are in Unix define stricmp to be strcasecmp and strnicmp
> to */
> /* be strncasecmp. I'm not sure if all Unices have these, but Linux
> */
> /* does. */
>
> In general, the right approach (in the Unix part of the world) is to
> look at the POSIX standards, and strongly prefer those. strcasecmp
> is
> in POSIX, and dates from 4.4BSD, so it's been around a really long
> time
> (25 years?). I have no idea about sticmp, but it seems to be an MS
> thing.
>
>
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/strcasecmp.html
>
>
> I haven't figured out why the defines aren't working, but it seems
> like
> the code should be based on HAVE_FOO, with some way to set those
> semi-manually on Windows (assuming the windows build doesn't use
> autoconf).
>
side note: stricmp and strnicmp are supported only by
the Microsoft Visual C++ compiler, and both them are now
deprecated by MS itself.
modern versions of MSVC support _stricmp and _strnicmp
(notice the hyphen prefix).
the usual workaround adopted by many other FLOSS/GFOSS
libraries for ensuring transparent cross-compiler
portability is as follows:
1. always use stcasecmp and strncasecmp in your code
2. define in some appropriate header file this macro:
#if defined(_WIN32) && !defined(__MINGW32__)
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#endif
note: the "if defined" clauses ensures that name
replacement will happen only for MSVC but not for
MinGW, that being a conformant porting of GNU gcc
for Windows is perfectly aware of strcasecmp and
strncasecmp
bye Sandro
More information about the postgis-devel
mailing list