popt  1.16
system.h
Go to the documentation of this file.
00001 
00005 #ifdef HAVE_CONFIG_H
00006 #include "config.h"
00007 #endif
00008 
00009 #if defined (__GLIBC__) && defined(__LCLINT__)
00010 /*@-declundef@*/
00011 /*@unchecked@*/
00012 extern __const __int32_t *__ctype_tolower;
00013 /*@unchecked@*/
00014 extern __const __int32_t *__ctype_toupper;
00015 /*@=declundef@*/
00016 #endif
00017 
00018 #include <ctype.h>
00019 
00020 /* XXX isspace(3) has i18n encoding signednesss issues on Solaris. */
00021 #define _isspaceptr(_chp)       isspace((int)(*(unsigned char *)(_chp)))
00022 
00023 #include <errno.h>
00024 #include <fcntl.h>
00025 #include <limits.h>
00026 
00027 #ifdef HAVE_MCHECK_H
00028 #include <mcheck.h>
00029 #endif
00030 
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 #include <string.h>
00034 
00035 #if defined(HAVE_UNISTD_H) && !defined(__LCLINT__)
00036 #include <unistd.h>
00037 #endif
00038 
00039 #ifdef __NeXT
00040 /* access macros are not declared in non posix mode in unistd.h -
00041  don't try to use posix on NeXTstep 3.3 ! */
00042 #include <libc.h>
00043 #endif
00044 
00045 /*@-incondefs@*/
00046 /*@mayexit@*/ /*@only@*/ /*@out@*/ /*@unused@*/
00047 void * xmalloc (size_t size)
00048         /*@globals errno @*/
00049         /*@ensures maxSet(result) == (size - 1) @*/
00050         /*@modifies errno @*/;
00051 
00052 /*@mayexit@*/ /*@only@*/ /*@unused@*/
00053 void * xcalloc (size_t nmemb, size_t size)
00054         /*@ensures maxSet(result) == (nmemb - 1) @*/
00055         /*@*/;
00056 
00057 /*@mayexit@*/ /*@only@*/ /*@unused@*/
00058 void * xrealloc (/*@null@*/ /*@only@*/ void * ptr, size_t size)
00059         /*@ensures maxSet(result) == (size - 1) @*/
00060         /*@modifies *ptr @*/;
00061 
00062 /*@mayexit@*/ /*@only@*/ /*@unused@*/
00063 char * xstrdup (const char *str)
00064         /*@*/;
00065 /*@=incondefs@*/
00066 
00067 #if !defined(HAVE_STPCPY)
00068 /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST.  */
00069 static inline char * stpcpy (char *dest, const char * src) {
00070     register char *d = dest;
00071     register const char *s = src;
00072 
00073     do
00074         *d++ = *s;
00075     while (*s++ != '\0');
00076     return d - 1;
00077 }
00078 #endif
00079 
00080 /* Memory allocation via macro defs to get meaningful locations from mtrace() */
00081 #if defined(HAVE_MCHECK_H) && defined(__GNUC__)
00082 #define vmefail()       (fprintf(stderr, "virtual memory exhausted.\n"), exit(EXIT_FAILURE), NULL)
00083 #define xmalloc(_size)          (malloc(_size) ? : vmefail())
00084 #define xcalloc(_nmemb, _size)  (calloc((_nmemb), (_size)) ? : vmefail())
00085 #define xrealloc(_ptr, _size)   (realloc((_ptr), (_size)) ? : vmefail())
00086 #define xstrdup(_str)   (strcpy((malloc(strlen(_str)+1) ? : vmefail()), (_str)))
00087 #else
00088 #define xmalloc(_size)          malloc(_size)
00089 #define xcalloc(_nmemb, _size)  calloc((_nmemb), (_size))
00090 #define xrealloc(_ptr, _size)   realloc((_ptr), (_size))
00091 #define xstrdup(_str)   strdup(_str)
00092 #endif  /* defined(HAVE_MCHECK_H) && defined(__GNUC__) */
00093 
00094 #ifndef __LCLINT__
00095 # if defined HAVE_SECURE_GETENV
00096 #  define       getenv(_s)      secure_getenv(_s)
00097 # elif defined HAVE___SECURE_GETENV
00098 #  define       getenv(_s)      __secure_getenv(_s)
00099 #endif
00100 #endif /* !__LCLINT__ */
00101 
00102 #if !defined(__GNUC__) && !defined(__attribute__)
00103 #define __attribute__(x) 
00104 #endif
00105 #define UNUSED(x) x __attribute__((__unused__))
00106 
00107 #include "popt.h"

Generated for popt by  doxygen 1.7.6.1