Date: Thu, 13 Jan 2000 03:34:34 +0100 (CET) From: Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de> To: freebsd-questions@FreeBSD.ORG Subject: Re: Giving a sighandler more information Message-ID: <200001130234.DAA64583@dorifer.heim3.tu-clausthal.de> In-Reply-To: <85jcfs$1oj0$1@atlantis.rz.tu-clausthal.de>
next in thread | previous in thread | raw e-mail | index | archive | help
Laurence Berland <stuyman@confusion.net> wrote in list.freebsd-questions:
> Followup question: is a sig_atomic_t appropriate to hold the value of a
> FILE * ?
No. It is only guaranteed to be large enough to hold an int.
Of course, on intel PCs, a pointer has the same size as an int,
but not on other platforms (e.g. the Alpha). Therefore,
portable programs cannot store a pointer in a sig_atomic_t.
Apart from that: You can't use a FILE* within a signal handler
anyway, because most of stdio's functions are not guaranteed to
be re-entrant.
If you have to do something with a file within a signal
handler, use the lower-level file handling functions based on
file descriptors, i.e. open(), read(), write(), close().
Conveniently, a file descriptor fits in a sig_atomic_t, too.
Please refer to the sigaction(2) manpage, it contains a
complete list of all functions that are "async-signal safe".
All other functions are _not_ safe to use from within a signal
handler.
Regards
Oliver
--
Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany
(Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de)
"In jedem Stück Kohle wartet ein Diamant auf seine Geburt"
(Terry Pratchett)
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200001130234.DAA64583>
