gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: libc unlink - bug or not?


From: Alexey Ulasevich
Subject: Re: libc unlink - bug or not?
Date: Fri, 18 Oct 2024 10:44:41 +0300
User-agent: Mozilla Thunderbird

Ok, thanks.

Can we expand module FIO.def by `Delete` procedure that will be delete a file?

I think FIO.def is good place for it, because `Exists` is here.


17.10.2024 22:22, Gaius Mulley пишет:

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]