1 //===- llvm/Support/Unix/Unix.h - Common Unix Include File -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines things specific to Unix implementations.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SYSTEM_UNIX_UNIX_H
15 #define LLVM_SYSTEM_UNIX_UNIX_H
17 //===----------------------------------------------------------------------===//
18 //=== WARNING: Implementation here must contain only generic UNIX code that
19 //=== is guaranteed to work on all UNIX variants.
20 //===----------------------------------------------------------------------===//
22 #include "llvm/Config/config.h" // Get autoconf configuration settings
23 #include "llvm/Support/Errno.h"
31 #include <sys/types.h>
37 #ifdef HAVE_SYS_PARAM_H
38 #include <sys/param.h>
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
46 #ifdef HAVE_SYS_WAIT_H
47 # include <sys/wait.h>
51 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
55 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
58 /// This function builds an error message into \p ErrMsg using the \p prefix
59 /// string and the Unix error number given by \p errnum. If errnum is -1, the
60 /// default then the value of errno is used.
61 /// @brief Make an error message
63 /// If the error number can be converted to a string, it will be
64 /// separated from prefix by ": ".
65 static inline bool MakeErrMsg(
66 std::string* ErrMsg, const std::string& prefix, int errnum = -1) {
71 *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum);