[m-users.] "posix" extra library won't compile

Volker Wysk post at volker-wysk.de
Sat Mar 16 07:09:45 AEDT 2019


Hi!

Am Freitag, 15. März 2019, 18:17:54 CET schrieb Zoltan Somogyi:
> On Fri, 15 Mar 2019 17:13:22 +0100, Volker Wysk <post at volker-wysk.de> wrote:
> > > Actually, not glibc, the explanation is about half way down:
> > > 
> > > https://wiki.ubuntu.com/ToolChain/CompilerFlags?action=show&redirect=Com
> > > pile rFlags#-D_FORTIFY_SOURCE=2
> > > 
> > > It seems Ubuntu have started making the C compile with
> > > -D_FORTIFY_SOURCE=2 by default and that will reject calls to open()
> > > without a mode argument.
> > 
> > So will it be fixed?
> 
> The person who is best positioned to fix the problem is YOU,
> because you seem to be the only person whose machine
> actually *has* the problem.
> 
> Look up your machine's documentation of fortify source,
> figure out what C compiler options turn it off, then
> add a file named Mercury.options to the posix directory
> containing a line like this, with the dots replaced by that
> C compiler option.
> 
> CFLAGS-posix.open = ...
> 
> A more drastic solution would be to simply delete the code
> that calls the two-argument version of open, directly or indirectly.
> However, that would not be backwards compatible.

I've figured it out. Changing line 74 of posix.open.m from 

    FileDes = open(PathName, Flags);

to

    FileDes = open(PathName, Flags, 0);

fixes the problem.

The third argument of open() is needed exactly when the Flag O_CREAT is set. 
You are supposed to call the three-argument version of open(), when this is 
the case. (But nothing prevents you from calling the two-argument version, 
with undefined results.) Otherwise, the third argument is ignored.

So, the two-argument version is needed for not-O_CREAT only. In this case the 
mode is ignored, so it can be set to 0.

Happy hacking,
Volker




More information about the users mailing list