MCPcopy Create free account
hub / github.com/Tencent/MMKV / ASharedMemory_getSize

Function ASharedMemory_getSize

Core/MemoryFile_Android.cpp:180–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

178}
179
180size_t ASharedMemory_getSize(int fd) {
181 size_t size = 0;
182#ifndef MMKV_OHOS
183 if (g_android_api >= __ANDROID_API_O__) {
184 static auto handle = loadLibrary();
185 static AShmem_getSize_t funcPtr =
186 (handle != nullptr) ? reinterpret_cast<AShmem_getSize_t>(dlsym(handle, "ASharedMemory_getSize")) : nullptr;
187 if (funcPtr) {
188 size = funcPtr(fd);
189 if (size == 0) {
190 MMKVError("fail to ASharedMemory_getSize:%d, %s", fd, strerror(errno));
191 }
192 } else {
193 MMKVWarning("fail to locate ASharedMemory_create() from loading libandroid.so");
194 }
195 }
196#endif
197 if (size == 0) {
198 int tmp = ioctl(fd, ASHMEM_GET_SIZE, nullptr);
199 if (tmp < 0) {
200 MMKVError("fail to get ashmem size:%d, %s", fd, strerror(errno));
201 } else {
202 size = static_cast<size_t>(tmp);
203 }
204 }
205 return size;
206}
207
208string ASharedMemory_getName(int fd) {
209 // Android Q doesn't have ASharedMemory_getName()

Callers 2

getActualFileSizeMethod · 0.85
FileMethod · 0.85

Calls 1

loadLibraryFunction · 0.85

Tested by

no test coverage detected