*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->Tru64 Unix man pages -> errno (5)              
Title
Content
Arch
Section
 

errno(5)

Contents


NAME    [Toc]    [Back]

       errno - Returns error condition value

SYNOPSIS    [Toc]    [Back]

       #include <errno.h>


DESCRIPTION    [Toc]    [Back]

       The errno external variable contains the most recent error
       condition set by a function. The symbolic values for errno
       are  listed  in the intro reference page and in the ERRORS
       section of the individual reference pages for  each  function.


       The  exec()  functions  set  errno  to a value of 0 (zero)
       after successful completion.  Typically,  other  functions
       only set errno to a nonzero value.

EXAMPLES    [Toc]    [Back]

       The following program uses the value of errno to determine
       why the requested file could not be opened.  If errno  has
       one of the two tested values, the program prints an appropriate
 message; otherwise, the program  uses  the  error()
       function  to  print out the appropriate message. This program
 does not have to set errno to a  value  of  0  (zero)
       because  errno  is  tested only if the open() function has
       failed.

       #include <errno.h> #include <stdio.h> #include  <string.h>
       #include    <fcntl.h>   #include   <sys/stat.h>   #include
       <sys/types.h> #define SLENGTH 80

       main() {
           char filespec[SLENGTH], *eol;
           int opret;
           while (TRUE) {
               printf("Enter file to be checked: ");
               fgets(filespec, SLENGTH, stdin);
               if ((eol = strchr(filespec, '\n')) != NULL) {
                   *eol = '\0';  /* Replace newline with null */
                   if (*filespec == '\0') return; /* exit program
       */
                   opret = open(filespec,O_RDONLY,0);
                   if (opret > 0)
                     printf("%s: File exists\n",filespec);
                   else if (errno == ENOENT)
                     printf("%s:  File  does  not  exist\n",filespec);

                   else if (errno == ENOTDIR)
                     printf("%s: Prefix in path is not  a  directory\n",

                       filespec);
                   else
                     perror(filespec);

               } else           /* Line entered too long */
                 printf("Line entered is too long\n");
           } }



NOTES    [Toc]    [Back]

       To  ensure that your programs are portable, you should not
       explicitly declare errno to be an extern int in your  program.
   You should rely on the type int declaration in the
       <errno.h> include file.  Full use.

SEE ALSO    [Toc]    [Back]

      
      
       Functions: intro(2), perror(3), strerror(3)



                                                         errno(5)
[ Back ]
 Similar pages
Name OS Title
dmColorGetError IRIX returns the value of the error flag.
dmColorGetErrorString IRIX returns a text error message.
aio_error Tru64 Returns the error status of a specified asynchronous I/O operation (P1003.1b)
zgerfs IRIX improve the computed solution to a system of linear equations and provides error bounds and backward error est
cgerfs IRIX improve the computed solution to a system of linear equations and provides error bounds and backward error est
dgerfs IRIX improve the computed solution to a system of linear equations and provides error bounds and backward error est
sgerfs IRIX improve the computed solution to a system of linear equations and provides error bounds and backward error est
ctrrfs IRIX provide error bounds and backward error estimates for the solution to a system of linear equations with a tria
ztprfs IRIX provide error bounds and backward error estimates for the solution to a system of linear equations with a tria
ztbrfs IRIX provide error bounds and backward error estimates for the solution to a system of linear equations with a tria
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service