Thread: Return the errno from open func. and print it to screen

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    20

    Return the errno from open func. and print it to screen

    Hi...
    i am programming Cli/Ser ,so part of the program is to open file to download it from client side,but i want to return the global value Errorno to print it to screen , and how to use strerror() func ???
    i write this "This is part of server code" :

    Code:
    fd= open("abc.txt",O_RDONLY);
                    //error handilng in open file
                    if(fd<0)
                    {
                        fprintf(stderr,"The Error is : \n");
                        //bzero(&buffer,sizeof(buffer));
                        snprintf(buffer,sizeof(buffer),"%d",fd);
                        n=write(connfd,&buffer,sizeof(buffer));
                        continue;
                    }
    if the fd <0 return error ,i want to know what is the error and print it to screen

    **note :when i use perror() ,the result print to screen like this
    "n success"???
    Last edited by zmhnak; 03-22-2013 at 03:21 AM. Reason: syntax

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    open() doesn't return an error number. It just returns -1 if there is an error. The type of the error is stored in the errno macro which you can use with strerror().

    Bye, Andreas

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    20
    ok i know this my frnd,but give me an example in "code"to illstrate this please? using open func()

  4. #4

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 10-06-2010, 02:28 PM
  2. fopen "w" return errno ENOENT
    By zatlas1 in forum C Programming
    Replies: 8
    Last Post: 08-12-2010, 09:31 AM
  3. Print Screen
    By /\/\ E /\/ @ in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-11-2002, 05:37 PM
  4. Delete & print func()
    By spentdome in forum C Programming
    Replies: 5
    Last Post: 05-29-2002, 09:02 AM
  5. how do i print the screen?
    By massive_attack in forum C++ Programming
    Replies: 4
    Last Post: 12-29-2001, 02:39 PM

Tags for this Thread