You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

67 regels
1.7 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. typedef signed char int8_t;
  20. typedef signed short int16_t;
  21. typedef signed long int int32_t;
  22. typedef unsigned char uint8_t;
  23. typedef unsigned short uint16_t;
  24. typedef unsigned long int uint32_t;
  25. typedef long int intptr_t;
  26. typedef unsigned long int uintptr_t;
  27. #endif
  28. #if !defined(HAVE_HTONS) && !defined(HAVE_NETINET_IN_H)
  29. # if defined(HAVE_ENDIAN_H)
  30. # include <endian.h>
  31. # endif
  32. static extern inline uint16_t htons(uint16_t x)
  33. {
  34. #if defined(HAVE_ENDIAN_H)
  35. if(__BYTE_ORDER == __BIG_ENDIAN)
  36. #else
  37. /* This is compile-time optimised with at least -O1 or -Os */
  38. uint32_t const dummy = 0x12345678;
  39. if(*(uint8_t const *)&dummy == 0x12)
  40. #endif
  41. return x;
  42. else
  43. return (x >> 8) | (x << 8);
  44. }
  45. static extern inline uint32_t htonl(uint32_t x)
  46. {
  47. #if defined(HAVE_ENDIAN_H)
  48. if(__BYTE_ORDER == __BIG_ENDIAN)
  49. #else
  50. /* This is compile-time optimised with at least -O1 or -Os */
  51. uint32_t const dummy = 0x12345678;
  52. if(*(uint8_t const *)&dummy == 0x12)
  53. #endif
  54. return x;
  55. else
  56. return (x >> 24) | ((x >> 8) & 0x0000ff00)
  57. | ((x << 8) & 0x00ff0000) | (x << 24);
  58. }
  59. #endif