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 14#ifndef LLVM_SYSTEM_UNIX_UNIX_H 15#define LLVM_SYSTEM_UNIX_UNIX_H 16 17//===----------------------------------------------------------------------===// 18//=== WARNING: Implementation here must contain only generic UNIX code that 19//=== is guaranteed to work on all UNIX variants. 20//===----------------------------------------------------------------------===// 21 22#include "llvm/Config/config.h" // Get autoconf configuration settings 23#include "llvm/Support/Errno.h" 24#include <cstdlib> 25#include <cstdio> 26#include <cstring> 27#include <cerrno> 28#include <string> 29#include <algorithm> 30 31#ifdef HAVE_UNISTD_H 32#include <unistd.h> 33#endif 34 35#ifdef HAVE_SYS_TYPES_H 36#include <sys/types.h> 37#endif 38 39#ifdef HAVE_SYS_PARAM_H 40#include <sys/param.h> 41#endif 42 43#ifdef HAVE_ASSERT_H 44#include <assert.h> 45#endif 46 47#ifdef HAVE_SYS_TIME_H 48# include <sys/time.h> 49#endif 50#include <time.h> 51 52#ifdef HAVE_SYS_WAIT_H 53# include <sys/wait.h> 54#endif 55 56#ifndef WEXITSTATUS 57# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) 58#endif 59 60#ifndef WIFEXITED 61# define WIFEXITED(stat_val) (((stat_val) & 255) == 0) 62#endif 63 64/// This function builds an error message into \p ErrMsg using the \p prefix 65/// string and the Unix error number given by \p errnum. If errnum is -1, the 66/// default then the value of errno is used. 67/// @brief Make an error message 68/// 69/// If the error number can be converted to a string, it will be 70/// separated from prefix by ": ". 71static inline bool MakeErrMsg( 72 std::string* ErrMsg, const std::string& prefix, int errnum = -1) { 73 if (!ErrMsg) 74 return true; 75 if (errnum == -1) 76 errnum = errno; 77 *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum); 78 return true; 79} 80 81#endif 82