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  // Generate a unique temporary filename from pFileTemplate and open it in
33  // an OutputFile returned. The filename will be pFileTemplate with
34  // a dot ('.') plus six random characters appended. Return NULL on error.
35  static OutputFile *CreateTemporary(const std::string &pFileTemplate,
36                                     unsigned pFlags);
37
38  OutputFile(const std::string &pFilename, unsigned pFlags = 0);
39
40  ssize_t write(const void *pBuf, size_t count);
41
42  void truncate();
43
44  // This is similar to the system call dup(). It creates a copy of the file
45  // descriptor it contains and wrap it in llvm::raw_fd_ostream object. It
46  // returns a non-NULL object if everything goes well and user should later
47  // use delete operator to destroy it by itself.
48  llvm::raw_fd_ostream *dup();
49};
50
51} // end namespace bcc
52
53#endif  // BCC_SUPPORT_OUTPUT_FILE_H
54