On Fri, Jul 12, 2019 at 10:39 AM Allan Streib <astr...@indiana.edu> wrote:

> Probably an elementary question stemming from my lack of C expertise.
>
> I am trying to complile some C code that includes its own "bcrypt"
> function. This is conflicting with the declaration in pwd.h.
>
>     error: conflicting types for 'bcrypt'
>     int bcrypt(char *, const char *, const char *);
>         ^
>     /usr/include/pwd.h:112:8: note: previous declaration is here
>     char            *bcrypt(const char *, const char *);
>
> In pwd.h I see that the bcrypt declaration is wrapped in a #if block:
>
...

> __POSIX_VISIBLE is defined as 200809, so __BSD_VISIBLE should be 0 and
> the pwd.h declaration for bcrypt should be skipped?
>

There are four options here:
1) change the software to not use the name 'bcrypt' for a non-static
function.  OpenBSD has only been using it for 15 years...

2) If you're going to use the name bcrypt, then don't do so in files that
pull in <pwd.h>.  (This would be a last choice in my book, as that's a
fragile setup)

3) *IF* the software was written to only rely on the interfaces of some
version of the POSIX standard, then follow the compilation rules described
in that standard.  You mention POSIX 2008, so perhaps this software would
build when following those rules, passing the compiler
-D_POSIX_C_SOURCE=200809L to only declare the symbols from that standard

Note that application software should *never* define macros matching the
pattern __*_VISIBLE such as __BSD_VISIBLE.  Those are in the reserved
namespace and on OpenBSD they are set by <sys/cdefs.h> based on the macros
specified in the various standards for use by application and build
software.  The ones you should care about are:
  _POSIX_C_SOURCE     -- standardized: specifies a POSIX version
  _XOPEN_SOURCE        -- standardized: specifies a POSIX + XSI version
  _ISOC11_SOURCE        -- adds C2011 interfaces
  _BSD_SOURCE             -- adds all BSD and obsoleted interfaces

Make sense?

Philip Guenther

Reply via email to