Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

72 rader
1.8 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)
  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(HAVE_HTONS)
  31. # define hton16 htons
  32. # define hton32 htonl
  33. #else
  34. # if defined(HAVE_ENDIAN_H)
  35. # include <endian.h>
  36. # endif
  37. static inline uint16_t hton16(uint16_t x)
  38. {
  39. /* This is compile-time optimised with at least -O1 or -Os */
  40. #if defined(HAVE_ENDIAN_H)
  41. if(__BYTE_ORDER == __BIG_ENDIAN)
  42. #else
  43. uint32_t const dummy = 0x12345678;
  44. if(*(uint8_t const *)&dummy == 0x12)
  45. #endif
  46. return x;
  47. else
  48. return (x >> 8) | (x << 8);
  49. }
  50. static inline uint32_t hton32(uint32_t x)
  51. {
  52. /* This is compile-time optimised with at least -O1 or -Os */
  53. #if defined(HAVE_ENDIAN_H)
  54. if(__BYTE_ORDER == __BIG_ENDIAN)
  55. #else
  56. uint32_t const dummy = 0x12345678;
  57. if(*(uint8_t const *)&dummy == 0x12)
  58. #endif
  59. return x;
  60. else
  61. return (x >> 24) | ((x >> 8) & 0x0000ff00)
  62. | ((x << 8) & 0x00ff0000) | (x << 24);
  63. }
  64. #endif