system.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * \file popt/system.h
  3. */
  4. #ifdef HAVE_CONFIG_H
  5. #include "config.h"
  6. #endif
  7. #if defined (__GLIBC__) && defined(__LCLINT__)
  8. /*@-declundef@*/
  9. /*@unchecked@*/
  10. extern __const __int32_t *__ctype_tolower;
  11. /*@unchecked@*/
  12. extern __const __int32_t *__ctype_toupper;
  13. /*@=declundef@*/
  14. #endif
  15. #include <ctype.h>
  16. /* XXX isspace(3) has i18n encoding signednesss issues on Solaris. */
  17. #define _isspaceptr(_chp) isspace((int)(*(unsigned char *)(_chp)))
  18. #include <errno.h>
  19. #include <fcntl.h>
  20. #include <limits.h>
  21. #ifdef HAVE_MCHECK_H
  22. #include <mcheck.h>
  23. #endif
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #if defined(HAVE_UNISTD_H) && !defined(__LCLINT__)
  28. #include <unistd.h>
  29. #endif
  30. #ifdef __NeXT
  31. /* access macros are not declared in non posix mode in unistd.h -
  32. don't try to use posix on NeXTstep 3.3 ! */
  33. #include <libc.h>
  34. #endif
  35. /*@-incondefs@*/
  36. /*@mayexit@*/ /*@only@*/ /*@out@*/ /*@unused@*/
  37. void * xmalloc (size_t size)
  38. /*@globals errno @*/
  39. /*@ensures maxSet(result) == (size - 1) @*/
  40. /*@modifies errno @*/;
  41. /*@mayexit@*/ /*@only@*/ /*@unused@*/
  42. void * xcalloc (size_t nmemb, size_t size)
  43. /*@ensures maxSet(result) == (nmemb - 1) @*/
  44. /*@*/;
  45. /*@mayexit@*/ /*@only@*/ /*@unused@*/
  46. void * xrealloc (/*@null@*/ /*@only@*/ void * ptr, size_t size)
  47. /*@ensures maxSet(result) == (size - 1) @*/
  48. /*@modifies *ptr @*/;
  49. /*@mayexit@*/ /*@only@*/ /*@unused@*/
  50. char * xstrdup (const char *str)
  51. /*@*/;
  52. /*@=incondefs@*/
  53. #if !defined(HAVE_STPCPY)
  54. /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
  55. static inline char * stpcpy (char *dest, const char * src) {
  56. register char *d = dest;
  57. register const char *s = src;
  58. do
  59. *d++ = *s;
  60. while (*s++ != '\0');
  61. return d - 1;
  62. }
  63. #endif
  64. /* Memory allocation via macro defs to get meaningful locations from mtrace() */
  65. #if defined(HAVE_MCHECK_H) && defined(__GNUC__)
  66. #define vmefail() (fprintf(stderr, "virtual memory exhausted.\n"), exit(EXIT_FAILURE), NULL)
  67. #define xmalloc(_size) (malloc(_size) ? : vmefail())
  68. #define xcalloc(_nmemb, _size) (calloc((_nmemb), (_size)) ? : vmefail())
  69. #define xrealloc(_ptr, _size) (realloc((_ptr), (_size)) ? : vmefail())
  70. #define xstrdup(_str) (strcpy((malloc(strlen(_str)+1) ? : vmefail()), (_str)))
  71. #else
  72. #define xmalloc(_size) malloc(_size)
  73. #define xcalloc(_nmemb, _size) calloc((_nmemb), (_size))
  74. #define xrealloc(_ptr, _size) realloc((_ptr), (_size))
  75. #define xstrdup(_str) strdup(_str)
  76. #endif /* defined(HAVE_MCHECK_H) && defined(__GNUC__) */
  77. #if defined(HAVE___SECURE_GETENV) && !defined(__LCLINT__)
  78. #define getenv(_s) __secure_getenv(_s)
  79. #endif
  80. #if !defined(__GNUC__) && !defined(__attribute__)
  81. #define __attribute__(x)
  82. #endif
  83. #define UNUSED(x) x __attribute__((__unused__))
  84. #include "popt.h"