compat.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* Copyright (c) 2003-2004, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. /**
  6. * \file compat.c
  7. * \brief Wrappers to make calls more portable. This code defines
  8. * functions such as tor_snprintf, get/set various data types,
  9. * renaming, setting socket options, switching user IDs. It is basically
  10. * where the non-portable items are conditionally included depending on
  11. * the platform.
  12. **/
  13. #define COMPAT_PRIVATE
  14. #include "common/compat.h"
  15. #ifdef _WIN32
  16. #include <winsock2.h>
  17. #include <windows.h>
  18. #include <sys/locking.h>
  19. #endif
  20. #ifdef HAVE_UNAME
  21. #include <sys/utsname.h>
  22. #endif
  23. #ifdef HAVE_SYS_TYPES_H
  24. #include <sys/types.h>
  25. #endif
  26. #ifdef HAVE_SYS_SYSCTL_H
  27. #include <sys/sysctl.h>
  28. #endif
  29. #ifdef HAVE_SYS_STAT_H
  30. #include <sys/stat.h>
  31. #endif
  32. #ifdef HAVE_UTIME_H
  33. #include <utime.h>
  34. #endif
  35. #ifdef HAVE_SYS_UTIME_H
  36. #include <sys/utime.h>
  37. #endif
  38. #ifdef HAVE_UNISTD_H
  39. #include <unistd.h>
  40. #endif
  41. #ifdef HAVE_SYS_FCNTL_H
  42. #include <sys/fcntl.h>
  43. #endif
  44. #ifdef HAVE_PWD_H
  45. #include <pwd.h>
  46. #endif
  47. #ifdef HAVE_GRP_H
  48. #include <grp.h>
  49. #endif
  50. #ifdef HAVE_FCNTL_H
  51. #include <fcntl.h>
  52. #endif
  53. #ifdef HAVE_ERRNO_H
  54. #include <errno.h>
  55. #endif
  56. #ifdef HAVE_ARPA_INET_H
  57. #include <arpa/inet.h>
  58. #endif
  59. #ifdef HAVE_SYS_STATVFS_H
  60. #include <sys/statvfs.h>
  61. #endif
  62. #ifdef HAVE_SYS_CAPABILITY_H
  63. #include <sys/capability.h>
  64. #endif
  65. /* Includes for the process attaching prevention */
  66. #if defined(HAVE_SYS_PRCTL_H) && defined(__linux__)
  67. /* Only use the linux prctl; the IRIX prctl is totally different */
  68. #include <sys/prctl.h>
  69. #elif defined(__APPLE__)
  70. #include <sys/ptrace.h>
  71. #endif /* defined(HAVE_SYS_PRCTL_H) && defined(__linux__) || ... */
  72. #ifdef HAVE_NETDB_H
  73. #include <netdb.h>
  74. #endif
  75. #ifdef HAVE_SYS_PARAM_H
  76. #include <sys/param.h> /* FreeBSD needs this to know what version it is */
  77. #endif
  78. #include <stdio.h>
  79. #include <stdlib.h>
  80. #ifdef HAVE_SIGNAL_H
  81. #include <signal.h>
  82. #endif
  83. #ifdef HAVE_MMAP
  84. #include <sys/mman.h>
  85. #endif
  86. #ifdef HAVE_SYS_SYSLIMITS_H
  87. #include <sys/syslimits.h>
  88. #endif
  89. #ifdef HAVE_SYS_FILE_H
  90. #include <sys/file.h>
  91. #endif
  92. #include "lib/log/torlog.h"
  93. #include "common/util.h"
  94. #include "lib/container/smartlist.h"
  95. #include "lib/wallclock/tm_cvt.h"
  96. #include "lib/net/address.h"
  97. #include "lib/sandbox/sandbox.h"
  98. /*
  99. * Process control
  100. */