Back to index

glibc  2.9
errnos-tmpl.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 1993, 1997 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <errno.h>
00020 
00021 static char iferrno[] = "#ifdef _ERRNO_H";
00022 static char endiferrno[] = "#endif /* <errno.h> included.  */";
00023 static char ifEmath[] = "#if !defined(__Emath_defined) && \
00024  (defined(_ERRNO_H) || defined(__need_Emath))";
00025 static char endifEmath[] = "#endif /* Emath not defined and <errno.h> \
00026 included or need Emath.  */";
00027 
00028 static int biggest_value = 0;
00029 static int done_ENOSYS = 0;
00030 static int done_ERANGE = 0, done_EDOM = 0;
00031 
00032 static void
00033 DO(name, value)
00034      char *name;
00035      int value;
00036 {
00037   int is_ERANGE = !done_ERANGE && !strcmp(name, "ERANGE");
00038   int is_EDOM = !done_EDOM && !strcmp(name, "EDOM");
00039   int is_Emath = is_ERANGE || is_EDOM;
00040 
00041   if (is_Emath)
00042     {
00043       puts(endiferrno);
00044       puts(ifEmath);
00045     }
00046 
00047   if (!strcmp (name, "EWOULDBLOCK"))
00048     {
00049       puts ("#define EWOULDBLOCK EAGAIN /* Translated in glibc. */");
00050       name = "EWOULDBLOCK_sys /* Value actually returned by kernel. */";
00051     }
00052 
00053   printf ("#define %s %d\n", name, value);
00054 
00055   if (is_Emath)
00056     {
00057       puts(endifEmath);
00058       puts(iferrno);
00059     }
00060 
00061   if (value > biggest_value)
00062     biggest_value = value;
00063 
00064   if (is_ERANGE)
00065     done_ERANGE = 1;
00066   else if (is_EDOM)
00067     done_EDOM = 1;
00068   else if (!done_ENOSYS && !strcmp(name, "ENOSYS"))
00069     done_ENOSYS = 1;
00070 }
00071 
00072 int
00073 main()
00074 {
00075   puts(iferrno);
00076 
00077   ERRNOS;
00078 
00079   if (!done_EDOM || !done_ERANGE)
00080     {
00081       puts(endiferrno);
00082       puts(ifEmath);
00083       if (!done_EDOM)
00084        printf("#define EDOM %d\n", ++biggest_value);
00085       if (!done_ERANGE)
00086        printf("#define ERANGE %d\n", ++biggest_value);
00087       puts(endifEmath);
00088     }
00089 
00090   if (!done_ENOSYS)
00091     printf("#define ENOSYS %d\n", ++biggest_value);
00092 
00093   puts(endiferrno);
00094 
00095   puts("#undef __need_Emath");
00096   puts("#ifndef __Emath_defined\n#define __Emath_defined 1\n#endif");
00097 
00098   exit(0);
00099 }