Sponsored Content
Full Discussion: does perror() set errno?
Top Forums Programming does perror() set errno? Post 302343958 by jim mcnamara on Friday 14th of August 2009 08:06:50 AM
Old 08-14-2009
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.
 

10 More Discussions You Might Find Interesting

1. Programming

Getting errno in a Multithreaded program

In Tru64 Unix, the 'errno' variable is not thread safe. Could anybody help me about how to make it thread safe or how to check 'errno' in a Multithreaded program ???? The Programming process is like this. There are some definite number of threads having their own task. There is one... (2 Replies)
Discussion started by: S.Vishwanath
2 Replies

2. Programming

errno pb

Hello, I need to make a lib with pthread, when I run my make file all is good. But when I run my test program, I test errno in the begining and is already set to 251. Is it normal ??? What can I modify in my Makefile to have errno set to 0 ??? Thanks $make gcc -D_REENTRANT -shared -fpic... (3 Replies)
Discussion started by: dts
3 Replies

3. Programming

Hi errno in sys/stat.h

How should I use errno in a c program and what info does it have . I am working with directories and files. So can any one tell me How to access errno?I am using the stat() function on \etc directory and I am alble to access only the half of the directories.I am not able to access other half and... (6 Replies)
Discussion started by: vijlak
6 Replies

4. Programming

errno

Hey, Can I assume that for certain function calls, errno can never be set to a certain value. More specifically, can I assume that for if the stat function call fails, the errno can never be or "No space left on device." I am assuming that a read function cannot fail because of no space... (5 Replies)
Discussion started by: the_learner
5 Replies

5. Programming

A question about printing error message with perror

Dear all, I use perror in order to print an error message to the standar error. For example if a C program is called without its two necessary command line parameters then : if (argc != 3) { perror("use: ./myProgram <source file> <target file>\n"); return 1; } Now the... (2 Replies)
Discussion started by: dariyoosh
2 Replies

6. UNIX for Dummies Questions & Answers

perror with signals

I have following problem with this code.. First time trough the main loop..... perror gives ....blocked signal:success(all other times gives illlegal seek) Should every time trought the main loop be success?? And the perror otside of main loop...didn't change mask:success That line of code... (2 Replies)
Discussion started by: joker40
2 Replies

7. Programming

help with C programming, perror

i am trying to use the perror function: something like perror("WRONG!!!"); but when i see the message in the terminal, it comes out like WRONG!!! : Success How can i change it to WRONG!!! : WRONG!!! well i just want to have my own custom message for the part after the colon... (1 Reply)
Discussion started by: omega666
1 Replies

8. Programming

need help about get errno [ENXIO] for mmap

from mmap manpage I get it's errors discription: The addresses specified by the range [off, off + len) are invalid for filedes. How could I trigger a ENXIO ? anyone can input the code? Lei (3 Replies)
Discussion started by: yanglei_fage
3 Replies

9. Linux

[Errno 256] No more mirrors to try.

Dear all, CentOS 6 After executing "yum update -y" command I am facing this error. Please help me out. thanks in advance. Full error & error code is given as follow: ... (7 Replies)
Discussion started by: saqlain.bashir
7 Replies

10. AIX

Errno.h symbols

Hi, I need to look at a recent copy of /usr/include/errno.h from AIX 7.2 to check some symbols. In particular, I'm curious if it defines EOWNERDEAD and ENOTRECOVERABLE. Can someone who has access to 7.2 please check for me? Thanks! (1 Reply)
Discussion started by: topcat
1 Replies
PERROR(3)							 Library functions							 PERROR(3)

NAME
perror - print a system error message SYNOPSIS
#include <stdio.h> void perror(const char *s); #include <errno.h> const char *sys_errlist[]; int sys_nerr; DESCRIPTION
The routine perror() produces a message on the standard error output, describing the last error encountered during a call to a system or library function. First (if s is not NULL and *s is not NUL) the argument string s is printed, followed by a colon and a blank. Then the message and a new-line. To be of most use, the argument string should include the name of the function that incurred the error. The error number is taken from the external variable errno, which is set when errors occur but not cleared when non-erroneous calls are made. The global error list sys_errlist[] indexed by errno can be used to obtain the error message without the newline. The largest message num- ber provided in the table is sys_nerr -1. Be careful when directly accessing this list because new error values may not have been added to sys_errlist[]. When 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. Thus, if a failing call is not immediately followed by a call to perror, the value of errno should be saved. CONFORMING TO
ANSI C, BSD 4.3, POSIX, X/OPEN SEE ALSO
strerror(3) 2001-12-14 PERROR(3)
All times are GMT -4. The time now is 11:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy