|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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 information about this in man pages. thanks in advance |
| Sponsored Links | ||
|
|
|
|||
|
perror uses errno.
all it does is the equivalent of sprintf your phrase along with the result of strerror(errno). You are experiencing undefined behavior - meaning do not call perror twice like that. You idea may or may not work correctly - undefined means the run time library writer decides what if anything some aspect of C coding will do. In your case it probably trashed errno after the first call. Write your own perror() if you don't want to use it conventionally. |
|
|||
|
What Jim means is that errno is undefined after a successful library call. You should only call perror() immediately after a failing call.
As a matter of fact, the glibc implementation of perror() calls some other functions such as dup(), fdopen() that modify errno, even if perror() itself always succeed. I would personally expect that clean library code doesn't expose their mess to outside. But we cannot complain, as POSIX/SUS allows such behavior. Cheers, Loïc -- My Blog: Loïc OnStage “UNIX is simple. It just takes a genius to understand its simplicity.” – Dennis Ritchie |
| Sponsored Links |
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| errno | the_learner | Programming | 5 | 10-02-2008 05:39 PM |
| Hi errno in sys/stat.h | vijlak | Programming | 6 | 11-11-2006 09:13 PM |
| errno pb | dts | Programming | 3 | 08-06-2004 10:51 AM |
| login error after sys-unconfig, errno = 13 | roing | UNIX for Dummies Questions & Answers | 14 | 02-08-2004 11:25 AM |
| Getting errno in a Multithreaded program | S.Vishwanath | Programming | 2 | 03-25-2002 09:58 AM |