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_LIB_SUPPORT_UNIX_UNIX_H 15#define LLVM_LIB_SUPPORT_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 <algorithm> 25#include <assert.h> 26#include <cerrno> 27#include <cstdio> 28#include <cstdlib> 29#include <cstring> 30#include <string> 31#include <sys/types.h> 32#include <sys/wait.h> 33 34#ifdef HAVE_UNISTD_H 35#include <unistd.h> 36#endif 37 38#ifdef HAVE_SYS_PARAM_H 39#include <sys/param.h> 40#endif 41 42#ifdef HAVE_SYS_TIME_H 43# include <sys/time.h> 44#endif 45#include <time.h> 46 47#ifdef HAVE_DLFCN_H 48# include <dlfcn.h> 49#endif 50 51/// This function builds an error message into \p ErrMsg using the \p prefix 52/// string and the Unix error number given by \p errnum. If errnum is -1, the 53/// default then the value of errno is used. 54/// @brief Make an error message 55/// 56/// If the error number can be converted to a string, it will be 57/// separated from prefix by ": ". 58static inline bool MakeErrMsg( 59 std::string* ErrMsg, const std::string& prefix, int errnum = -1) { 60 if (!ErrMsg) 61 return true; 62 if (errnum == -1) 63 errnum = errno; 64 *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum); 65 return true; 66} 67 68#endif 69