raw_ostream.cpp revision 6f75755c9204b1d8817ae5a65a2f7e5af0ec3f70
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(_MSC_VER) 17#include <io.h> 18#ifndef STDIN_FILENO 19# define STDIN_FILENO 0 20#endif 21#ifndef STDOUT_FILENO 22# define STDOUT_FILENO 1 23#endif 24#ifndef STDERR_FILENO 25# define STDERR_FILENO 2 26#endif 27#endif 28 29using namespace mcld; 30 31//===----------------------------------------------------------------------===// 32// raw_ostream 33//===----------------------------------------------------------------------===// 34mcld::raw_fd_ostream::raw_fd_ostream(const char *pFilename, 35 std::string &pErrorInfo, 36 unsigned int pFlags) 37 : llvm::raw_fd_ostream(pFilename, pErrorInfo, pFlags), 38 m_bConfigColor(false), 39 m_bSetColor(false) { 40} 41 42mcld::raw_fd_ostream::raw_fd_ostream(int pFD, 43 bool pShouldClose, 44 bool pUnbuffered) 45 : llvm::raw_fd_ostream(pFD, pShouldClose, pUnbuffered), 46 m_bConfigColor(false), 47 m_bSetColor(false) { 48} 49 50mcld::raw_fd_ostream::~raw_fd_ostream() 51{ 52} 53 54void mcld::raw_fd_ostream::setColor(bool pEnable) 55{ 56 m_bConfigColor = true; 57 m_bSetColor = pEnable; 58} 59 60llvm::raw_ostream & 61mcld::raw_fd_ostream::changeColor(enum llvm::raw_ostream::Colors pColor, 62 bool pBold, 63 bool pBackground) 64{ 65 if (!is_displayed()) 66 return *this; 67 return llvm::raw_fd_ostream::changeColor(pColor, pBold, pBackground); 68} 69 70llvm::raw_ostream& mcld::raw_fd_ostream::resetColor() 71{ 72 if (!is_displayed()) 73 return *this; 74 return llvm::raw_fd_ostream::resetColor(); 75} 76 77llvm::raw_ostream& mcld::raw_fd_ostream::reverseColor() 78{ 79 if (!is_displayed()) 80 return *this; 81 return llvm::raw_ostream::reverseColor(); 82} 83 84bool mcld::raw_fd_ostream::is_displayed() const 85{ 86 if (m_bConfigColor) 87 return m_bSetColor; 88 89 return llvm::raw_fd_ostream::is_displayed(); 90} 91 92//===----------------------------------------------------------------------===// 93// outs(), errs(), nulls() 94//===----------------------------------------------------------------------===// 95mcld::raw_fd_ostream& mcld::outs() { 96 // Set buffer settings to model stdout behavior. 97 // Delete the file descriptor when the program exists, forcing error 98 // detection. If you don't want this behavior, don't use outs(). 99 static mcld::raw_fd_ostream S(STDOUT_FILENO, true); 100 return S; 101} 102 103mcld::raw_fd_ostream& mcld::errs() { 104 // Set standard error to be unbuffered by default. 105 static mcld::raw_fd_ostream S(STDERR_FILENO, false, true); 106 return S; 107} 108 109