1/* 2 * Copyright 2012, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef BCC_SUPPORT_OUTPUT_FILE_H 18#define BCC_SUPPORT_OUTPUT_FILE_H 19 20#include "bcc/Support/File.h" 21#include "bcc/Support/FileBase.h" 22 23namespace llvm { 24 class raw_fd_ostream; 25} 26 27namespace bcc { 28 29class OutputFile : public File<FileBase::kWriteMode> { 30 typedef File<FileBase::kWriteMode> super; 31public: 32 OutputFile(const std::string &pFilename, unsigned pFlags = 0); 33 34 ssize_t write(const void *pBuf, size_t count); 35 36 void truncate(); 37 38 // This is similar to the system call dup(). It creates a copy of the file 39 // descriptor it contains and wrap it in llvm::raw_fd_ostream object. It 40 // returns a non-NULL object if everything goes well and user should later 41 // use delete operator to destroy it by itself. 42 llvm::raw_fd_ostream *dup(); 43}; 44 45} // end namespace bcc 46 47#endif // BCC_SUPPORT_OUTPUT_FILE_H 48