LLVM API Documentation
00001 //===- llvm/System/Unix/Unix.h - Common Unix Include File -------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines things specific to Unix implementations. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_SYSTEM_UNIX_UNIX_H 00015 #define LLVM_SYSTEM_UNIX_UNIX_H 00016 00017 //===----------------------------------------------------------------------===// 00018 //=== WARNING: Implementation here must contain only generic UNIX code that 00019 //=== is guaranteed to work on all UNIX variants. 00020 //===----------------------------------------------------------------------===// 00021 00022 #include "llvm/Config/config.h" // Get autoconf configuration settings 00023 #include "llvm/System/Errno.h" 00024 #include <cstdlib> 00025 #include <cstdio> 00026 #include <cstring> 00027 #include <cerrno> 00028 #include <string> 00029 #include <algorithm> 00030 00031 #ifdef HAVE_UNISTD_H 00032 #include <unistd.h> 00033 #endif 00034 00035 #ifdef HAVE_SYS_TYPES_H 00036 #include <sys/types.h> 00037 #endif 00038 00039 #ifdef HAVE_SYS_PARAM_H 00040 #include <sys/param.h> 00041 #endif 00042 00043 #ifdef HAVE_ASSERT_H 00044 #include <assert.h> 00045 #endif 00046 00047 #ifdef TIME_WITH_SYS_TIME 00048 # include <sys/time.h> 00049 # include <time.h> 00050 #else 00051 # ifdef HAVE_SYS_TIME_H 00052 # include <sys/time.h> 00053 # else 00054 # include <time.h> 00055 # endif 00056 #endif 00057 00058 #ifdef HAVE_SYS_WAIT_H 00059 # include <sys/wait.h> 00060 #endif 00061 00062 #ifndef WEXITSTATUS 00063 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) 00064 #endif 00065 00066 #ifndef WIFEXITED 00067 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0) 00068 #endif 00069 00070 /// This function builds an error message into \p ErrMsg using the \p prefix 00071 /// string and the Unix error number given by \p errnum. If errnum is -1, the 00072 /// default then the value of errno is used. 00073 /// @brief Make an error message 00074 /// 00075 /// If the error number can be converted to a string, it will be 00076 /// separated from prefix by ": ". 00077 static inline bool MakeErrMsg( 00078 std::string* ErrMsg, const std::string& prefix, int errnum = -1) { 00079 if (!ErrMsg) 00080 return true; 00081 if (errnum == -1) 00082 errnum = errno; 00083 *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum); 00084 return true; 00085 } 00086 00087 #endif