Unix.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //===- llvm/Support/Unix/Unix.h - Common Unix Include File -------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines things specific to Unix implementations.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_LIB_SUPPORT_UNIX_UNIX_H
  14. #define LLVM_LIB_SUPPORT_UNIX_UNIX_H
  15. //===----------------------------------------------------------------------===//
  16. //=== WARNING: Implementation here must contain only generic UNIX code that
  17. //=== is guaranteed to work on all UNIX variants.
  18. // //
  19. ///////////////////////////////////////////////////////////////////////////////
  20. #include "llvm/Config/config.h" // Get autoconf configuration settings
  21. #include "llvm/Support/Errno.h"
  22. #include <algorithm>
  23. #include <assert.h>
  24. #include <cerrno>
  25. #include <cstdio>
  26. #include <cstdlib>
  27. #include <cstring>
  28. #include <string>
  29. #include <sys/types.h>
  30. #ifdef HAVE_UNISTD_H
  31. #include <unistd.h>
  32. #endif
  33. #ifdef HAVE_SYS_PARAM_H
  34. #include <sys/param.h>
  35. #endif
  36. #ifdef HAVE_SYS_TIME_H
  37. # include <sys/time.h>
  38. #endif
  39. #include <time.h>
  40. #ifdef HAVE_SYS_WAIT_H
  41. # include <sys/wait.h>
  42. #endif
  43. #ifdef HAVE_DLFCN_H
  44. # include <dlfcn.h>
  45. #endif
  46. #ifndef WEXITSTATUS
  47. # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
  48. #endif
  49. #ifndef WIFEXITED
  50. # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
  51. #endif
  52. /// This function builds an error message into \p ErrMsg using the \p prefix
  53. /// string and the Unix error number given by \p errnum. If errnum is -1, the
  54. /// default then the value of errno is used.
  55. /// @brief Make an error message
  56. ///
  57. /// If the error number can be converted to a string, it will be
  58. /// separated from prefix by ": ".
  59. static inline bool MakeErrMsg(
  60. std::string* ErrMsg, const std::string& prefix, int errnum = -1) {
  61. if (!ErrMsg)
  62. return true;
  63. if (errnum == -1)
  64. errnum = errno;
  65. *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum);
  66. return true;
  67. }
  68. #endif