Results 1 to 6 of 6
here the program gives a odd result:
Code:
#include <stdio.h>
int main(){
perror("first");
perror("next");
return 0;
}
result:
first: Success
next: Illegal seek
why? any resonable explanation? i found no ...
- 08-14-2009 #1Just Joined!
- Join Date
- Aug 2009
- Posts
- 2
does perror() set errno?
here the program gives a odd result:
result:Code:#include <stdio.h> int main(){ perror("first"); perror("next"); return 0; }
first: Success
next: Illegal seek
why? any resonable explanation? i found no information about this in man pages.
thanks in advance
- 08-14-2009 #2Just Joined!
- Join Date
- Jul 2009
- Posts
- 10
According to "C in a Nutshell":
perror
Print an error message corresponding to the value of errno
The perror() function prints a message to the standard error stream. The output includes first the string referenced by the pointer argument, if any; then a colon and a space, then the error message that corresponds to the current value of the errno variable, ending with a newline character.
- 08-14-2009 #3Just Joined!
- Join Date
- Aug 2009
- Posts
- 2
i know this about perror
i wonder why the sencond perror prints an error, where the error be created?
- 08-14-2009 #4
When I copied and ran your program it produced:
first:Success
next:Success
Which is what its supposed to produce. Perror just reports the value of errno...Gerard4143Make mine Arch Linux
- 08-14-2009 #5Just Joined!
- Join Date
- Jul 2009
- Posts
- 10
Works for me, too ...
Code:joebuffer@ubuntu:~/clang$ ./test first: Success next: Success
- 08-15-2009 #6Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
According to:
we might expect both reported results ... cheers, drlWhen a system call fails, it usually returns -1 and sets the variable errno to a value describing what went wrong. (These values can be found in <errno.h>.) Many library functions do likewise. The function perror() serves to translate this error code into human-readable form. Note that errno is undefined after a successful library call: this call may well change this variable, even though it succeeds, for example because it internally used some other library function that failed.
-- excerpt from perror(3): print system error message - Linux man pageWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote