Unix.h revision 218885
10SN/A//===- llvm/Support/Unix/Unix.h - Common Unix Include File -------*- C++ -*-===//
21472SN/A//
30SN/A//                     The LLVM Compiler Infrastructure
40SN/A//
50SN/A// This file is distributed under the University of Illinois Open Source
60SN/A// License. See LICENSE.TXT for details.
70SN/A//
80SN/A//===----------------------------------------------------------------------===//
90SN/A//
100SN/A// This file defines things specific to Unix implementations.
110SN/A//
120SN/A//===----------------------------------------------------------------------===//
130SN/A
140SN/A#ifndef LLVM_SYSTEM_UNIX_UNIX_H
150SN/A#define LLVM_SYSTEM_UNIX_UNIX_H
160SN/A
170SN/A//===----------------------------------------------------------------------===//
180SN/A//=== WARNING: Implementation here must contain only generic UNIX code that
191472SN/A//===          is guaranteed to work on all UNIX variants.
201472SN/A//===----------------------------------------------------------------------===//
211472SN/A
220SN/A#include "llvm/Config/config.h"     // Get autoconf configuration settings
230SN/A#include "llvm/Support/Errno.h"
240SN/A#include <cstdlib>
250SN/A#include <cstdio>
260SN/A#include <cstring>
270SN/A#include <cerrno>
280SN/A#include <string>
290SN/A#include <algorithm>
30
31#ifdef HAVE_UNISTD_H
32#include <unistd.h>
33#endif
34
35#ifdef HAVE_SYS_TYPES_H
36#include <sys/types.h>
37#endif
38
39#ifdef HAVE_SYS_PARAM_H
40#include <sys/param.h>
41#endif
42
43#ifdef HAVE_ASSERT_H
44#include <assert.h>
45#endif
46
47#ifdef TIME_WITH_SYS_TIME
48# include <sys/time.h>
49# include <time.h>
50#else
51# ifdef HAVE_SYS_TIME_H
52#  include <sys/time.h>
53# else
54#  include <time.h>
55# endif
56#endif
57
58#ifdef HAVE_SYS_WAIT_H
59# include <sys/wait.h>
60#endif
61
62#ifndef WEXITSTATUS
63# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
64#endif
65
66#ifndef WIFEXITED
67# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
68#endif
69
70/// This function builds an error message into \p ErrMsg using the \p prefix
71/// string and the Unix error number given by \p errnum. If errnum is -1, the
72/// default then the value of errno is used.
73/// @brief Make an error message
74///
75/// If the error number can be converted to a string, it will be
76/// separated from prefix by ": ".
77static inline bool MakeErrMsg(
78  std::string* ErrMsg, const std::string& prefix, int errnum = -1) {
79  if (!ErrMsg)
80    return true;
81  if (errnum == -1)
82    errnum = errno;
83  *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum);
84  return true;
85}
86
87#endif
88