Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 1 | //===- llvm/Support/Unix/Unix.h - Common Unix Include File -------*- C++ -*-===// |
Misha Brukman | 10468d8 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
Reid Spencer | 814ba57 | 2004-08-25 06:20:07 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 10468d8 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
Reid Spencer | 814ba57 | 2004-08-25 06:20:07 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines things specific to Unix implementations. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_SUPPORT_UNIX_UNIX_H |
| 15 | #define LLVM_LIB_SUPPORT_UNIX_UNIX_H |
Reid Spencer | e925d8b | 2004-12-27 06:17:50 +0000 | [diff] [blame] | 16 | |
Reid Spencer | 814ba57 | 2004-08-25 06:20:07 +0000 | [diff] [blame] | 17 | //===----------------------------------------------------------------------===// |
| 18 | //=== WARNING: Implementation here must contain only generic UNIX code that |
| 19 | //=== is guaranteed to work on all UNIX variants. |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | |
Reid Spencer | 7c16caa | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 22 | #include "llvm/Config/config.h" // Get autoconf configuration settings |
Michael J. Spencer | 4d2e150 | 2010-11-29 18:29:55 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Errno.h" |
Chris Lattner | 6ef473f | 2004-12-08 16:10:52 +0000 | [diff] [blame] | 24 | #include <algorithm> |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 25 | #include <assert.h> |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 26 | #include <cerrno> |
| 27 | #include <cstdio> |
| 28 | #include <cstdlib> |
| 29 | #include <cstring> |
| 30 | #include <string> |
Reid Kleckner | 37f69de | 2013-07-26 16:54:23 +0000 | [diff] [blame] | 31 | #include <sys/types.h> |
Justin Bogner | c7e3f3a | 2015-08-04 06:29:58 +0000 | [diff] [blame] | 32 | #include <sys/wait.h> |
Reid Spencer | 814ba57 | 2004-08-25 06:20:07 +0000 | [diff] [blame] | 33 | |
Reid Spencer | e925d8b | 2004-12-27 06:17:50 +0000 | [diff] [blame] | 34 | #ifdef HAVE_UNISTD_H |
| 35 | #include <unistd.h> |
| 36 | #endif |
| 37 | |
Reid Spencer | e925d8b | 2004-12-27 06:17:50 +0000 | [diff] [blame] | 38 | #ifdef HAVE_SYS_PARAM_H |
| 39 | #include <sys/param.h> |
Misha Brukman | 10468d8 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 40 | #endif |
Reid Spencer | e925d8b | 2004-12-27 06:17:50 +0000 | [diff] [blame] | 41 | |
Michael J. Spencer | 04b795b | 2012-04-23 19:00:27 +0000 | [diff] [blame] | 42 | #ifdef HAVE_SYS_TIME_H |
Reid Spencer | e925d8b | 2004-12-27 06:17:50 +0000 | [diff] [blame] | 43 | # include <sys/time.h> |
Reid Spencer | e925d8b | 2004-12-27 06:17:50 +0000 | [diff] [blame] | 44 | #endif |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 45 | #include <time.h> |
Reid Spencer | e925d8b | 2004-12-27 06:17:50 +0000 | [diff] [blame] | 46 | |
Rafael Espindola | 9ab9fe9 | 2013-10-08 16:12:58 +0000 | [diff] [blame] | 47 | #ifdef HAVE_DLFCN_H |
| 48 | # include <dlfcn.h> |
| 49 | #endif |
| 50 | |
Eugene Leviant | ea877d4 | 2016-08-26 08:14:54 +0000 | [diff] [blame] | 51 | #ifdef HAVE_FCNTL_H |
| 52 | # include <fcntl.h> |
| 53 | #endif |
| 54 | |
Reid Spencer | 42bcf6e | 2006-08-21 06:02:44 +0000 | [diff] [blame] | 55 | /// This function builds an error message into \p ErrMsg using the \p prefix |
| 56 | /// string and the Unix error number given by \p errnum. If errnum is -1, the |
| 57 | /// default then the value of errno is used. |
| 58 | /// @brief Make an error message |
Daniel Dunbar | 3222b9b | 2009-04-20 20:50:13 +0000 | [diff] [blame] | 59 | /// |
| 60 | /// If the error number can be converted to a string, it will be |
| 61 | /// separated from prefix by ": ". |
Dan Gohman | d78c400 | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 62 | static inline bool MakeErrMsg( |
Reid Spencer | 42bcf6e | 2006-08-21 06:02:44 +0000 | [diff] [blame] | 63 | std::string* ErrMsg, const std::string& prefix, int errnum = -1) { |
| 64 | if (!ErrMsg) |
Reid Spencer | 879ed5a | 2006-08-23 07:30:48 +0000 | [diff] [blame] | 65 | return true; |
Reid Spencer | 42bcf6e | 2006-08-21 06:02:44 +0000 | [diff] [blame] | 66 | if (errnum == -1) |
| 67 | errnum = errno; |
Jeffrey Yasskin | 1a93330 | 2009-07-01 18:11:20 +0000 | [diff] [blame] | 68 | *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum); |
Reid Spencer | 879ed5a | 2006-08-23 07:30:48 +0000 | [diff] [blame] | 69 | return true; |
Reid Spencer | 42bcf6e | 2006-08-21 06:02:44 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 72 | #endif |