1 //===- llvm/System/Unix/Unix.h - Common Unix Include File -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines things specific to Unix implementations.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SYSTEM_UNIX_UNIX_H
15 #define LLVM_SYSTEM_UNIX_UNIX_H
17 //===----------------------------------------------------------------------===//
18 //=== WARNING: Implementation here must contain only generic UNIX code that
19 //=== is guaranteed to work on all UNIX variants.
20 //===----------------------------------------------------------------------===//
22 #include "llvm/Config/config.h" // Get autoconf configuration settings
34 #ifdef HAVE_SYS_TYPES_H
35 #include <sys/types.h>
38 #ifdef HAVE_SYS_PARAM_H
39 #include <sys/param.h>
46 #ifdef TIME_WITH_SYS_TIME
47 # include <sys/time.h>
50 # ifdef HAVE_SYS_TIME_H
51 # include <sys/time.h>
57 #ifdef HAVE_SYS_WAIT_H
58 # include <sys/wait.h>
62 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
66 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
69 inline void ThrowErrno(const std::string& prefix) {
70 char buffer[MAXPATHLEN];
72 #ifdef HAVE_STRERROR_R
73 // strerror_r is thread-safe.
75 strerror_r(errno,buffer,MAXPATHLEN-1);
77 // Copy the thread un-safe result of strerror into
78 // the buffer as fast as possible to minimize impact
79 // of collision of strerror in multiple threads.
81 strncpy(buffer,strerror(errno),MAXPATHLEN-1);
82 buffer[MAXPATHLEN-1] = 0;
84 // Strange that this system doesn't even have strerror
85 // but, oh well, just use a generic message
86 sprintf(buffer, "Error #%d", errno);
88 throw prefix + ": " + buffer;