Unix.h revision 263508
1218885Sdim//===- llvm/Support/Unix/Unix.h - Common Unix Include File -------*- C++ -*-===// 2218885Sdim// 3218885Sdim// The LLVM Compiler Infrastructure 4218885Sdim// 5218885Sdim// This file is distributed under the University of Illinois Open Source 6218885Sdim// License. See LICENSE.TXT for details. 7218885Sdim// 8218885Sdim//===----------------------------------------------------------------------===// 9218885Sdim// 10218885Sdim// This file defines things specific to Unix implementations. 11218885Sdim// 12218885Sdim//===----------------------------------------------------------------------===// 13218885Sdim 14218885Sdim#ifndef LLVM_SYSTEM_UNIX_UNIX_H 15218885Sdim#define LLVM_SYSTEM_UNIX_UNIX_H 16218885Sdim 17218885Sdim//===----------------------------------------------------------------------===// 18218885Sdim//=== WARNING: Implementation here must contain only generic UNIX code that 19218885Sdim//=== is guaranteed to work on all UNIX variants. 20218885Sdim//===----------------------------------------------------------------------===// 21218885Sdim 22218885Sdim#include "llvm/Config/config.h" // Get autoconf configuration settings 23218885Sdim#include "llvm/Support/Errno.h" 24249423Sdim#include <algorithm> 25263508Sdim#include <assert.h> 26249423Sdim#include <cerrno> 27249423Sdim#include <cstdio> 28218885Sdim#include <cstdlib> 29218885Sdim#include <cstring> 30218885Sdim#include <string> 31263508Sdim#include <sys/types.h> 32218885Sdim 33218885Sdim#ifdef HAVE_UNISTD_H 34218885Sdim#include <unistd.h> 35218885Sdim#endif 36218885Sdim 37218885Sdim#ifdef HAVE_SYS_PARAM_H 38218885Sdim#include <sys/param.h> 39218885Sdim#endif 40218885Sdim 41239462Sdim#ifdef HAVE_SYS_TIME_H 42218885Sdim# include <sys/time.h> 43218885Sdim#endif 44239462Sdim#include <time.h> 45218885Sdim 46218885Sdim#ifdef HAVE_SYS_WAIT_H 47218885Sdim# include <sys/wait.h> 48218885Sdim#endif 49218885Sdim 50263508Sdim#ifdef HAVE_DLFCN_H 51263508Sdim# include <dlfcn.h> 52263508Sdim#endif 53263508Sdim 54218885Sdim#ifndef WEXITSTATUS 55218885Sdim# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) 56218885Sdim#endif 57218885Sdim 58218885Sdim#ifndef WIFEXITED 59218885Sdim# define WIFEXITED(stat_val) (((stat_val) & 255) == 0) 60218885Sdim#endif 61218885Sdim 62218885Sdim/// This function builds an error message into \p ErrMsg using the \p prefix 63218885Sdim/// string and the Unix error number given by \p errnum. If errnum is -1, the 64218885Sdim/// default then the value of errno is used. 65218885Sdim/// @brief Make an error message 66218885Sdim/// 67218885Sdim/// If the error number can be converted to a string, it will be 68218885Sdim/// separated from prefix by ": ". 69218885Sdimstatic inline bool MakeErrMsg( 70218885Sdim std::string* ErrMsg, const std::string& prefix, int errnum = -1) { 71218885Sdim if (!ErrMsg) 72218885Sdim return true; 73218885Sdim if (errnum == -1) 74218885Sdim errnum = errno; 75218885Sdim *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum); 76218885Sdim return true; 77218885Sdim} 78218885Sdim 79218885Sdim#endif 80