少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "il2cpp-config.h"
 
#if IL2CPP_TARGET_LUMIN
 
#include "os/Lumin/File.h"
#include "os/Lumin/Lifecycle.h"
#include "os/Posix/FileHandle.h"
#include "utils/PathUtils.h"
 
#include <fcntl.h>
#include <sys/errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string>
 
 
namespace il2cpp
{
namespace os
{
namespace lumin
{
    int s_StandardErrDescriptor = -1;
    int s_StandardOutDescriptor = -1;
 
    void InitializeFileHandles()
    {
        std::string base = GetPackageTempPath();
        std::string errPath = PathForErrorLog();
        std::string outPath = PathForOutputLog();
 
        s_StandardErrDescriptor = creat(errPath.c_str(), S_IRUSR | S_IWUSR);
        s_StandardOutDescriptor = creat(outPath.c_str(), S_IRUSR | S_IWUSR);
    }
 
    void CleanupFileHandles()
    {
        if (s_StandardErrDescriptor >= 0)
        {
            fdatasync(s_StandardErrDescriptor);
            close(s_StandardErrDescriptor);
        }
        if (s_StandardOutDescriptor >= 0)
        {
            fdatasync(s_StandardOutDescriptor);
            close(s_StandardOutDescriptor);
        }
    }
 
    std::string PathForErrorLog()
    {
        return il2cpp::utils::PathUtils::Combine(GetPackageTempPath(), std::string("stderr.log"));
    }
 
    std::string PathForOutputLog()
    {
        return il2cpp::utils::PathUtils::Combine(GetPackageTempPath(), std::string("stdout.log"));
    }
}
 
    FileHandle* File::GetStdError()
    {
        static FileHandle* s_handle = NULL;
        if (s_handle)
            return s_handle;
 
        s_handle = new FileHandle();
        s_handle->fd = lumin::s_StandardErrDescriptor;
        s_handle->type = kFileTypeChar;
        s_handle->options = 0;
        s_handle->accessMode = kFileAccessReadWrite;
        s_handle->shareMode = -1; // Only used for files
 
        return s_handle;
    }
 
    FileHandle* File::GetStdInput()
    {
        static FileHandle* s_handle = NULL;
        if (s_handle)
            return s_handle;
 
        s_handle = new FileHandle();
        s_handle->fd = 0;
        s_handle->type = kFileTypeChar;
        s_handle->options = 0;
        s_handle->accessMode = kFileAccessRead;
        s_handle->shareMode = -1; // Only used for files
 
        return s_handle;
    }
 
    FileHandle* File::GetStdOutput()
    {
        static FileHandle* s_handle = NULL;
        if (s_handle)
            return s_handle;
 
        s_handle = new FileHandle();
        s_handle->fd = lumin::s_StandardOutDescriptor;
        s_handle->type = kFileTypeChar;
        s_handle->options = 0;
        s_handle->accessMode = kFileAccessReadWrite;
        s_handle->shareMode = -1; // Only used for files
 
        return s_handle;
    }
}
}
 
#endif