* error programming
@ 2005-01-13 19:21 r_zaca
2005-01-13 19:40 ` Francesco Gadaleta
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: r_zaca @ 2005-01-13 19:21 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Mail message body --]
[-- Type: text/plain, Size: 410 bytes --]
Hi all,
Can anybody sugest me a good documentation about how all the functions
related to "error treatment" on linux work?
I know there is a "variable" called errno that is set when a error about
something happens and that I can read this value through perror, (at least I
think it works that way) but how it really works I have no idea. So any tip
on this subject will be nice.
Thanks again.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: error programming
2005-01-13 19:21 error programming r_zaca
@ 2005-01-13 19:40 ` Francesco Gadaleta
2005-01-13 19:57 ` wwp
2005-01-14 21:48 ` Glynn Clements
2 siblings, 0 replies; 4+ messages in thread
From: Francesco Gadaleta @ 2005-01-13 19:40 UTC (permalink / raw)
To: r_zaca; +Cc: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 1073 bytes --]
On Thu, 2005-01-13 at 17:21 -0200, r_zaca wrote:
> Hi all,
>
> Can anybody sugest me a good documentation about how all the functions
> related to "error treatment" on linux work?
> I know there is a "variable" called errno that is set when a error about
> something happens and that I can read this value through perror, (at least I
> think it works that way) but how it really works I have no idea. So any tip
> on this subject will be nice.
> Thanks again.
take a look to "Advanced Linux Programming".
It speaks about errors too.
FG
_________________________________________________
Francesco Gadaleta - Italian GNU/Linux User
web site: www.gadaleta.org
email : francesco@gadaleta.org
ICQ : 286063291
Fingerprint: 3CB8 C721 FE99 BC98 38DC F463 BFDC E4EC CE3B 7327
(1024/DSA) [with image]
Linux Registered User #327326
__________________________________________________
Pls do not send me Word or Powerpoint files
RMS'll explain you why, here:
http://www.gadaleta.org/articles/ita/allegati_word.html
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: error programming
2005-01-13 19:21 error programming r_zaca
2005-01-13 19:40 ` Francesco Gadaleta
@ 2005-01-13 19:57 ` wwp
2005-01-14 21:48 ` Glynn Clements
2 siblings, 0 replies; 4+ messages in thread
From: wwp @ 2005-01-13 19:57 UTC (permalink / raw)
To: linux-c-programming
Hello r_zaca,
On Thu, 13 Jan 2005 17:21:22 -0200 r_zaca <r_zaca@ig.com.br> wrote:
> Hi all,
>
> Can anybody sugest me a good documentation about how all the functions
> related to "error treatment" on linux work?
> I know there is a "variable" called errno that is set when a error about
> something happens and that I can read this value through perror, (at least I
> think it works that way) but how it really works I have no idea. So any tip
> on this subject will be nice.
Ever asked to man?
$ man errno
My 2ct.
Regards,
--
wwp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: error programming
2005-01-13 19:21 error programming r_zaca
2005-01-13 19:40 ` Francesco Gadaleta
2005-01-13 19:57 ` wwp
@ 2005-01-14 21:48 ` Glynn Clements
2 siblings, 0 replies; 4+ messages in thread
From: Glynn Clements @ 2005-01-14 21:48 UTC (permalink / raw)
To: r_zaca; +Cc: linux-c-programming
r_zaca wrote:
> Can anybody sugest me a good documentation about how all the functions
> related to "error treatment" on linux work?
> I know there is a "variable" called errno that is set when a error about
> something happens and that I can read this value through perror, (at least I
> think it works that way) but how it really works I have no idea. So any tip
> on this subject will be nice.
If you need to check for specific errors, you can just check the value
of errno, e.g.
#include <errno.h>
...
if (do_something() == -1)
if (errno != EAGAIN)
perror("...");
The man page for a function should tell you which errors can occur.
Most of the time, you only care about whether an error occurred, not
which error.
The most common errors to check for are EAGAIN and EINTR, which
indicate "transient" errors (i.e. if you try again, the call may
succeed). EAGAIN occurs when you try to read() from a non-blocking
descriptor when no data is available. EINTR occurs if a system call is
interrupted by a signal.
If you just want to report the details to the user, you can use
perror() to print an error message to stderr which includes a
description of the last error. If you can't use perror() (e.g. if
you're reporting the error via syslog(), you can use strerror() to
obtain the description string for a given error).
In most situations, you can treat errno as a simple integer variable;
you can read its value, assign a new value, or take its address.
However, with glibc 2.x, it's actually a macro:
#define errno (*__errno_location ())
The reason for this is that, with multi-threaded programs, each thread
has its own "copy" of errno.
One consequence of this is that you can't take its address at compile
time, i.e.:
static int *errno_p = &errno;
won't work.
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-01-14 21:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-13 19:21 error programming r_zaca
2005-01-13 19:40 ` Francesco Gadaleta
2005-01-13 19:57 ` wwp
2005-01-14 21:48 ` Glynn Clements
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).