how to clean errno?

This is a discussion on how to clean errno? within the C Programming forums, part of the General Programming Boards category; I think check each function if it's returning an error and you'll be fine....

  1. #16
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    I think check each function if it's returning an error and you'll be fine.

  2. #17
    Complete Beginner
    Join Date
    Feb 2009
    Posts
    312
    Quote Originally Posted by MK27 View Post
    so generally speaking there is no reason to set errno to zero.
    There is: the C standard library contains some functions that indicate an error only by setting errno. Hence, if you don't set errno to 0 right before the function call, you can't tell whether errno has been modified by the function or not.

    By the way, the standard guarantees that no library function will ever set errno to 0.

    Greets,
    Philip
    All things begin as source code.
    Source code begins with an empty file.
    -- Tao Te Chip

  3. #18
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    Of course, that looks like a mismatch in design. well, what solution would you propose in that case?

  4. #19
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Brafil View Post
    Of course, that looks like a mismatch in design. well, what solution would you propose in that case?
    Write to the ISO/IEEE people and tell them what a bunch of incompetent jerks they are and how they have ruined your life.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #20
    Complete Beginner
    Join Date
    Feb 2009
    Posts
    312
    Quote Originally Posted by Brafil View Post
    Of course, that looks like a mismatch in design. well, what solution would you propose in that case?
    Code:
    errno = 0;
    library_call_with_a_bad_design();
    
    switch(errno) {
            /* ... */
                    break;
            case 0:
                    /* everything's ok */
                    break;
            default:
                    /* uncatched error */
                    break;
    }
    Greets,
    Philip
    All things begin as source code.
    Source code begins with an empty file.
    -- Tao Te Chip

  6. #21
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    Yeah... I'll do it tomorrow. Well, actually I've never used one of them. And it's not their "fault". There are some factors not existing in ANSI C. For example threads. And they've done a good job. I like C. Especially C99.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Establishing 'make clean' with GNU make
    By Jesdisciple in forum C Programming
    Replies: 9
    Last Post: 04-11-2009, 10:10 AM
  2. errno function, error TLS/non TLS
    By fran.b in forum C Programming
    Replies: 13
    Last Post: 03-25-2009, 09:06 AM
  3. Replies: 8
    Last Post: 03-10-2008, 12:57 PM
  4. make clean
    By Jaguar in forum Linux Programming
    Replies: 5
    Last Post: 12-27-2002, 06:44 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21