1//===- raw_ostream.cpp ----------------------------------------------------===// 2// 3// The MCLinker Project 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9#include <mcld/Config/Config.h> 10#include <mcld/Support/raw_ostream.h> 11 12#if defined(HAVE_UNISTD_H) 13# include <unistd.h> 14#endif 15 16#if defined(__CYGWIN__) 17#include <io.h> 18#endif 19 20#if defined(_MSC_VER) || defined(__MINGW32__) 21#include <io.h> 22#ifndef STDIN_FILENO 23# define STDIN_FILENO 0 24#endif 25#ifndef STDOUT_FILENO 26# define STDOUT_FILENO 1 27#endif 28#ifndef STDERR_FILENO 29# define STDERR_FILENO 2 30#endif 31#endif 32 33using namespace mcld; 34 35//===----------------------------------------------------------------------===// 36// raw_ostream 37//===----------------------------------------------------------------------===// 38mcld::raw_fd_ostream::raw_fd_ostream(const char *pFilename, 39 std::string &pErrorInfo, 40 llvm::sys::fs::OpenFlags pFlags) 41 : llvm::raw_fd_ostream(pFilename, pErrorInfo, pFlags), 42 m_bConfigColor(false), 43 m_bSetColor(false) { 44} 45 46mcld::raw_fd_ostream::raw_fd_ostream(int pFD, 47 bool pShouldClose, 48 bool pUnbuffered) 49 : llvm::raw_fd_ostream(pFD, pShouldClose, pUnbuffered), 50 m_bConfigColor(false), 51 m_bSetColor(false) { 52} 53 54mcld::raw_fd_ostream::~raw_fd_ostream() 55{ 56} 57 58void mcld::raw_fd_ostream::setColor(bool pEnable) 59{ 60 m_bConfigColor = true; 61 m_bSetColor = pEnable; 62} 63 64llvm::raw_ostream & 65mcld::raw_fd_ostream::changeColor(enum llvm::raw_ostream::Colors pColor, 66 bool pBold, 67 bool pBackground) 68{ 69 if (!is_displayed()) 70 return *this; 71 return llvm::raw_fd_ostream::changeColor(pColor, pBold, pBackground); 72} 73 74llvm::raw_ostream& mcld::raw_fd_ostream::resetColor() 75{ 76 if (!is_displayed()) 77 return *this; 78 return llvm::raw_fd_ostream::resetColor(); 79} 80 81llvm::raw_ostream& mcld::raw_fd_ostream::reverseColor() 82{ 83 if (!is_displayed()) 84 return *this; 85 return llvm::raw_ostream::reverseColor(); 86} 87 88bool mcld::raw_fd_ostream::is_displayed() const 89{ 90 if (m_bConfigColor) 91 return m_bSetColor; 92 93 return llvm::raw_fd_ostream::is_displayed(); 94} 95 96//===----------------------------------------------------------------------===// 97// outs(), errs(), nulls() 98//===----------------------------------------------------------------------===// 99mcld::raw_fd_ostream& mcld::outs() { 100 // Set buffer settings to model stdout behavior. 101 static mcld::raw_fd_ostream S(STDOUT_FILENO, false); 102 return S; 103} 104 105mcld::raw_fd_ostream& mcld::errs() { 106 // Set standard error to be unbuffered by default. 107 static mcld::raw_fd_ostream S(STDERR_FILENO, false, true); 108 return S; 109} 110 111