Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

108 rindas
2.6 KiB

  1. /*
  2. * libcucul Canvas for ultrafast compositing of Unicode letters
  3. * libcaca Colour ASCII-Art library
  4. * Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
  5. * All Rights Reserved
  6. *
  7. * $Id$
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the Do What The Fuck You Want To
  11. * Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * This file contains replacements for commonly found object types and
  16. * function prototypes that are sometimes missing.
  17. */
  18. #if defined HAVE_INTTYPES_H && !defined __KERNEL__
  19. # include <inttypes.h>
  20. #else
  21. typedef signed char int8_t;
  22. typedef signed short int16_t;
  23. typedef signed long int int32_t;
  24. typedef unsigned char uint8_t;
  25. typedef unsigned short uint16_t;
  26. typedef unsigned long int uint32_t;
  27. typedef long int intptr_t;
  28. typedef unsigned long int uintptr_t;
  29. #endif
  30. #if defined DEBUG && !defined __KERNEL__
  31. # include <stdio.h>
  32. # include <stdarg.h>
  33. # if defined(HAVE_ERRNO_H)
  34. # include <errno.h>
  35. # endif
  36. static inline void debug(const char *format, ...)
  37. {
  38. # if defined(HAVE_ERRNO_H)
  39. int saved_errno = errno;
  40. # endif
  41. va_list args;
  42. va_start(args, format);
  43. fprintf(stderr, "** libcaca debug ** ");
  44. vfprintf(stderr, format, args);
  45. fprintf(stderr, "\n");
  46. va_end(args);
  47. # if defined(HAVE_ERRNO_H)
  48. errno = saved_errno;
  49. # endif
  50. }
  51. #else
  52. # define debug(format, ...) do {} while(0)
  53. #endif
  54. #if defined HAVE_HTONS
  55. # if defined __KERNEL__
  56. /* Nothing to do */
  57. # elif defined HAVE_ARPA_INET_H
  58. # include <arpa/inet.h>
  59. # elif defined HAVE_NETINET_IN_H
  60. # include <netinet/in.h>
  61. # endif
  62. # define hton16 htons
  63. # define hton32 htonl
  64. #else
  65. # if defined HAVE_ENDIAN_H
  66. # include <endian.h>
  67. # endif
  68. static inline uint16_t hton16(uint16_t x)
  69. {
  70. /* This is compile-time optimised with at least -O1 or -Os */
  71. #if defined HAVE_ENDIAN_H
  72. if(__BYTE_ORDER == __BIG_ENDIAN)
  73. #else
  74. uint32_t const dummy = 0x12345678;
  75. if(*(uint8_t const *)&dummy == 0x12)
  76. #endif
  77. return x;
  78. else
  79. return (x >> 8) | (x << 8);
  80. }
  81. static inline uint32_t hton32(uint32_t x)
  82. {
  83. /* This is compile-time optimised with at least -O1 or -Os */
  84. #if defined HAVE_ENDIAN_H
  85. if(__BYTE_ORDER == __BIG_ENDIAN)
  86. #else
  87. uint32_t const dummy = 0x12345678;
  88. if(*(uint8_t const *)&dummy == 0x12)
  89. #endif
  90. return x;
  91. else
  92. return (x >> 24) | ((x >> 8) & 0x0000ff00)
  93. | ((x << 8) & 0x00ff0000) | (x << 24);
  94. }
  95. #endif
  96. #if defined __KERNEL__
  97. # undef HAVE_ERRNO_H
  98. #endif