Home | History | Annotate | Download | only in Unix
      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_SYSTEM_UNIX_UNIX_H
     15 #define LLVM_SYSTEM_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 
     33 #ifdef HAVE_UNISTD_H
     34 #include <unistd.h>
     35 #endif
     36 
     37 #ifdef HAVE_SYS_PARAM_H
     38 #include <sys/param.h>
     39 #endif
     40 
     41 #ifdef HAVE_SYS_TIME_H
     42 # include <sys/time.h>
     43 #endif
     44 #include <time.h>
     45 
     46 #ifdef HAVE_SYS_WAIT_H
     47 # include <sys/wait.h>
     48 #endif
     49 
     50 #ifndef WEXITSTATUS
     51 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
     52 #endif
     53 
     54 #ifndef WIFEXITED
     55 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
     56 #endif
     57 
     58 /// This function builds an error message into \p ErrMsg using the \p prefix
     59 /// string and the Unix error number given by \p errnum. If errnum is -1, the
     60 /// default then the value of errno is used.
     61 /// @brief Make an error message
     62 ///
     63 /// If the error number can be converted to a string, it will be
     64 /// separated from prefix by ": ".
     65 static inline bool MakeErrMsg(
     66   std::string* ErrMsg, const std::string& prefix, int errnum = -1) {
     67   if (!ErrMsg)
     68     return true;
     69   if (errnum == -1)
     70     errnum = errno;
     71   *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum);
     72   return true;
     73 }
     74 
     75 #endif
     76