[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: libc unlink - bug or not?
From: |
Gaius Mulley |
Subject: |
Re: libc unlink - bug or not? |
Date: |
Thu, 17 Oct 2024 20:22:32 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) |
Alexey Ulasevich <alexey.ulasevich@gmail.com> writes:
> Hi,
>
> I tried to use function `unlink` from `libc`, but it's defined may be
> incorrect.
>
> In `libc.def`it's defined like:
>
> PROCEDURE unlink (file: ADDRESS) : [ INTEGER ] ;
>
> I read https://www.nongnu.org/gm2/12/interface_to_c.html and according
> it, the function should be defined like:
>
> PROCEDURE unlink (a: ARRAY OF CHAR) : [ INTEGER ] ;
>
> Or may be I don't understand how to use it be correct way.
>
>
> Thanks.
>
> Aleksey
Hi Aleksey,
it could be defined as:
> PROCEDURE unlink (a: ARRAY OF CHAR) : [ INTEGER ] ;
except the user must ensure that all strings passed to unlink must be
nul terminated. While "foo" will always be nul terminated, however:
VAR
buf: ARRAY [0..2] OF CHAR ;
BEGIN
buf := "foo" ;
unlink (buf) ; (* not nul terminated. *)
won't be nul terminated. Forcing the user to consider the C string
implementation was part of the reason in choosing file: ADDRESS, also
the close match with man 2 unlink. Occasionally it might be the case
that an address is more suitable (for example a filename appearing in a
sequence of octets)
regards,
Gaius