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_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/Support/Errno.h"
00024 #include <algorithm>
00025 #include <cerrno>
00026 #include <cstdio>
00027 #include <cstdlib>
00028 #include <cstring>
00029 #include <string>
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 HAVE_SYS_TIME_H
00048 # include <sys/time.h>
00049 #endif
00050 #include <time.h>
00051 
00052 #ifdef HAVE_SYS_WAIT_H
00053 # include <sys/wait.h>
00054 #endif
00055 
00056 #ifndef WEXITSTATUS
00057 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
00058 #endif
00059 
00060 #ifndef WIFEXITED
00061 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
00062 #endif
00063 
00064 /// This function builds an error message into \p ErrMsg using the \p prefix
00065 /// string and the Unix error number given by \p errnum. If errnum is -1, the
00066 /// default then the value of errno is used.
00067 /// @brief Make an error message
00068 ///
00069 /// If the error number can be converted to a string, it will be
00070 /// separated from prefix by ": ".
00071 static inline bool MakeErrMsg(
00072   std::string* ErrMsg, const std::string& prefix, int errnum = -1) {
00073   if (!ErrMsg)
00074     return true;
00075   if (errnum == -1)
00076     errnum = errno;
00077   *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum);
00078   return true;
00079 }
00080 
00081 #endif