[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug] close() returns "0" when closing unopened files
From: |
Aharon Robbins |
Subject: |
Re: [bug] close() returns "0" when closing unopened files |
Date: |
Mon, 08 Dec 2008 05:51:21 +0200 |
> Date: Sat, 6 Dec 2008 13:43:50 +0100
> From: Seb <address@hidden>
> To: Aharon Robbins <address@hidden>
> Cc: address@hidden
> Subject: Re: [bug] close() returns "0" when closing unopened files
>
> Oh! I forgot to notice that the returned values of close() are not documented
> in the manual.
I'm sorry, but this is incorrect. In node Close Files And Pipes it says:
@command{gawk} treats @code{close} as a function.
The return value is @minus{}1 if the argument names something
that was never opened with a redirection, or if there is
a system problem closing the file or process.
In these cases, @command{gawk} sets the built-in variable
@code{ERRNO} to a string describing the problem.
In @command{gawk},
when closing a pipe or coprocess (input or output),
the return value is the exit status of the address@hidden
This is a full 16-bit value as returned by the @code{wait}
system call. See the system manual pages for information on
how to decode this value.}
Otherwise, it is the return value from the system's @code{close} or
@code{fclose} C functions when closing input or output
files, respectively.
This value is zero if the close succeeds, or @minus{}1 if
it fails.
The POSIX standard is very vague; it says that @code{close}
returns zero on success and non-zero otherwise. In general,
different implementations vary in what they report when closing
pipes; thus the return value cannot be used portably.
@value{DARKCORNER}
Thanks,
Arnold