MCPcopy Create free account
hub / github.com/Inori/GPCS4 / sceKernelOpen

Function sceKernelOpen

GPCS4/SceModules/SceLibkernel/sce_kernel_file.cpp:98–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96
97
98int PS4API sceKernelOpen(const char *path, int flags, SceKernelMode mode)
99{
100 LOG_SCE_TRACE("path %s flag %x mode %x", path, flags, mode);
101 std::string pcPath = plat::PS4PathToPCPath(path);
102
103#ifdef GPCS4_WINDOWS
104 int idx = g_fdSlots.GetEmptySlotIndex();
105 bool hasError = false;
106 if (flags & SCE_KERNEL_O_DIRECTORY)
107 {
108 DIR* dir = opendir(pcPath.c_str());
109 if (!dir)
110 {
111 LOG_WARN("open dir failed %s", path);
112 hasError = true;
113 }
114 g_fdSlots[idx].fd = (uintptr_t)dir;
115 g_fdSlots[idx].type = FD_TYPE_DIRECTORY;
116
117 }
118 else
119 {
120 LOG_ASSERT((flags == SCE_KERNEL_O_RDONLY || flags & SCE_KERNEL_O_TRUNC), "not supported flag.");
121 LOG_ASSERT((mode == SCE_KERNEL_S_IRU) || ((mode == SCE_KERNEL_S_INONE) && ((flags & SCE_KERNEL_O_CREAT) == 0)) || ((mode == SCE_KERNEL_S_IRWU) && ((flags & SCE_KERNEL_O_TRUNC))), "not supported mode.");
122
123 int oflag;
124 int pmode;
125
126 if (flags & SCE_KERNEL_O_TRUNC)
127 {
128 oflag = _O_CREAT | _O_TRUNC | _O_BINARY;
129 pmode = _S_IREAD | _S_IWRITE;
130 }
131 else
132 {
133 oflag = _O_RDONLY | _O_BINARY;
134 pmode = _S_IREAD;
135 }
136
137 int fd = _open(pcPath.c_str(), oflag, pmode);
138 if (fd == -1)
139 {
140 LOG_WARN("open file failed %s", path);
141 hasError = true;
142 g_fdSlots[idx].fd = 0;
143 g_fdSlots[idx].type = FD_TYPE_UNKNOWN;
144 }
145 else
146 {
147 g_fdSlots[idx].fd = fd;
148 g_fdSlots[idx].type = FD_TYPE_FILE;
149 }
150 }
151
152 int ret_fd = hasError ? -1 : idx;
153 return ret_fd;
154#endif //GPCS4_WINDOWS
155}

Callers

nothing calls this directly

Calls 4

PS4PathToPCPathFunction · 0.85
opendirFunction · 0.85
GetEmptySlotIndexMethod · 0.80
c_strMethod · 0.45

Tested by

no test coverage detected