LLVM API Documentation

Unix.h
Go to the documentation of this file.
00001 //===- llvm/Support/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_LIB_SUPPORT_UNIX_UNIX_H
00015 #define LLVM_LIB_SUPPORT_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/Support/Errno.h"
00024 #include <algorithm>
00025 #include <assert.h>
00026 #include <cerrno>
00027 #include <cstdio>
00028 #include <cstdlib>
00029 #include <cstring>
00030 #include <string>
00031 #include <sys/types.h>
00032 
00033 #ifdef HAVE_UNISTD_H
00034 #include <unistd.h>
00035 #endif
00036 
00037 #ifdef HAVE_SYS_PARAM_H
00038 #include <sys/param.h>
00039 #endif
00040 
00041 #ifdef HAVE_SYS_TIME_H
00042 # include <sys/time.h>
00043 #endif
00044 #include <time.h>
00045 
00046 #ifdef HAVE_SYS_WAIT_H
00047 # include <sys/wait.h>
00048 #endif
00049 
00050 #ifdef HAVE_DLFCN_H
00051 # include <dlfcn.h>
00052 #endif
00053 
00054 #ifndef WEXITSTATUS
00055 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
00056 #endif
00057 
00058 #ifndef WIFEXITED
00059 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
00060 #endif
00061 
00062 /// This function builds an error message into \p ErrMsg using the \p prefix
00063 /// string and the Unix error number given by \p errnum. If errnum is -1, the
00064 /// default then the value of errno is used.
00065 /// @brief Make an error message
00066 ///
00067 /// If the error number can be converted to a string, it will be
00068 /// separated from prefix by ": ".
00069 static inline bool MakeErrMsg(
00070   std::string* ErrMsg, const std::string& prefix, int errnum = -1) {
00071   if (!ErrMsg)
00072     return true;
00073   if (errnum == -1)
00074     errnum = errno;
00075   *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum);
00076   return true;
00077 }
00078 
00079 #endif