Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/env/FilePointer.cpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2021 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
#include <stdio.h>
24
#include <stdlib.h>
25
#include <string.h>
26
27
#if defined(J9ZOS390)
28
extern "C"
29
{
30
#include "atoe.h"
31
}
32
#undef fwrite
33
#endif
34
35
#include "env/FilePointer.hpp"
36
#include "j9.h"
37
#include "env/IO.hpp"
38
39
extern char *feGetEnv(const char *);
40
41
namespace TR
42
{
43
44
FILE TR::FilePointer::_null = FilePointer(NULL);
45
FILE TR::FilePointer::_stdin = FilePointer(stdin);
46
FILE TR::FilePointer::_stdout = FilePointer(stdout);
47
FILE TR::FilePointer::_stderr = FilePointer(stderr);
48
49
50
FilePointer::FilePointer(::FILE *stream)
51
{
52
initialize(stream);
53
}
54
55
56
void
57
FilePointer::initialize(::FILE *stream)
58
{
59
_stream = stream;
60
_useJ9IO = false;
61
}
62
63
64
void
65
FilePointer::initialize(J9PortLibrary *portLib, int32_t fileId)
66
{
67
PORT_ACCESS_FROM_PORT(portLib);
68
_fileId = fileId;
69
_useJ9IO = true;
70
}
71
72
73
int32_t
74
FilePointer::write(J9PortLibrary *portLib, char *buf, int32_t length)
75
{
76
PORT_ACCESS_FROM_PORT(portLib);
77
if (length > 0)
78
{
79
if (_useJ9IO)
80
{
81
return j9file_write(_fileId, buf, length);
82
}
83
else
84
length = fwrite(buf, 1, length, _stream);
85
}
86
87
return length;
88
}
89
90
91
void
92
FilePointer::close(J9PortLibrary *portLib)
93
{
94
PORT_ACCESS_FROM_PORT(portLib);
95
if (_useJ9IO)
96
{
97
flush(portLib);
98
j9file_sync(_fileId);
99
j9file_close(_fileId);
100
}
101
else
102
{
103
fclose(_stream);
104
}
105
}
106
107
108
void
109
FilePointer::flush(J9PortLibrary *portLib)
110
{
111
PORT_ACCESS_FROM_PORT(portLib);
112
if (!_useJ9IO)
113
fflush(_stream);
114
}
115
116
}
117
118