blob: 97e9cf86d7805944434d0e4ea32bc1d38b1dc454 [file] [log] [blame]
Duncan P. N. Exon Smith91d3cfe2016-04-05 20:45:04 +00001//===- llvm/Support/Unix/Unix.h - Common Unix Include File -------*- C++ -*-===//
Misha Brukman10468d82005-04-21 22:55:34 +00002//
Reid Spencer814ba572004-08-25 06:20:07 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman10468d82005-04-21 22:55:34 +00007//
Reid Spencer814ba572004-08-25 06:20:07 +00008//===----------------------------------------------------------------------===//
9//
10// This file defines things specific to Unix implementations.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_SUPPORT_UNIX_UNIX_H
15#define LLVM_LIB_SUPPORT_UNIX_UNIX_H
Reid Spencere925d8b2004-12-27 06:17:50 +000016
Reid Spencer814ba572004-08-25 06:20:07 +000017//===----------------------------------------------------------------------===//
18//=== WARNING: Implementation here must contain only generic UNIX code that
19//=== is guaranteed to work on all UNIX variants.
20//===----------------------------------------------------------------------===//
21
Reid Spencer7c16caa2004-09-01 22:55:40 +000022#include "llvm/Config/config.h" // Get autoconf configuration settings
Michael J. Spencer4d2e1502010-11-29 18:29:55 +000023#include "llvm/Support/Errno.h"
Chris Lattner6ef473f2004-12-08 16:10:52 +000024#include <algorithm>
Duncan P. N. Exon Smith91d3cfe2016-04-05 20:45:04 +000025#include <assert.h>
Chandler Carruth802d7552012-12-04 07:12:27 +000026#include <cerrno>
27#include <cstdio>
28#include <cstdlib>
29#include <cstring>
30#include <string>
Reid Kleckner37f69de2013-07-26 16:54:23 +000031#include <sys/types.h>
Justin Bognerc7e3f3a2015-08-04 06:29:58 +000032#include <sys/wait.h>
Reid Spencer814ba572004-08-25 06:20:07 +000033
Reid Spencere925d8b2004-12-27 06:17:50 +000034#ifdef HAVE_UNISTD_H
35#include <unistd.h>
36#endif
37
Reid Spencere925d8b2004-12-27 06:17:50 +000038#ifdef HAVE_SYS_PARAM_H
39#include <sys/param.h>
Misha Brukman10468d82005-04-21 22:55:34 +000040#endif
Reid Spencere925d8b2004-12-27 06:17:50 +000041
Michael J. Spencer04b795b2012-04-23 19:00:27 +000042#ifdef HAVE_SYS_TIME_H
Reid Spencere925d8b2004-12-27 06:17:50 +000043# include <sys/time.h>
Reid Spencere925d8b2004-12-27 06:17:50 +000044#endif
Duncan P. N. Exon Smith91d3cfe2016-04-05 20:45:04 +000045#include <time.h>
Reid Spencere925d8b2004-12-27 06:17:50 +000046
Rafael Espindola9ab9fe92013-10-08 16:12:58 +000047#ifdef HAVE_DLFCN_H
48# include <dlfcn.h>
49#endif
50
Eugene Leviantea877d42016-08-26 08:14:54 +000051#ifdef HAVE_FCNTL_H
52# include <fcntl.h>
53#endif
54
Reid Spencer42bcf6e2006-08-21 06:02:44 +000055/// 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 Dunbar3222b9b2009-04-20 20:50:13 +000059///
60/// If the error number can be converted to a string, it will be
61/// separated from prefix by ": ".
Dan Gohmand78c4002008-05-13 00:00:25 +000062static inline bool MakeErrMsg(
Reid Spencer42bcf6e2006-08-21 06:02:44 +000063 std::string* ErrMsg, const std::string& prefix, int errnum = -1) {
64 if (!ErrMsg)
Reid Spencer879ed5a2006-08-23 07:30:48 +000065 return true;
Reid Spencer42bcf6e2006-08-21 06:02:44 +000066 if (errnum == -1)
67 errnum = errno;
Jeffrey Yasskin1a933302009-07-01 18:11:20 +000068 *ErrMsg = prefix + ": " + llvm::sys::StrError(errnum);
Reid Spencer879ed5a2006-08-23 07:30:48 +000069 return true;
Reid Spencer42bcf6e2006-08-21 06:02:44 +000070}
71
Duncan P. N. Exon Smith91d3cfe2016-04-05 20:45:04 +000072#endif