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

Function zeroFillFile

Core/MemoryFile.cpp:399–424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397}
398
399bool zeroFillFile(int fd, size_t startPos, size_t size) {
400 if (fd < 0) {
401 return false;
402 }
403
404 if (lseek(fd, static_cast<off_t>(startPos), SEEK_SET) < 0) {
405 MMKVError("fail to lseek fd[%d], error:%s", fd, strerror(errno));
406 return false;
407 }
408
409 static const char zeros[4096] = {};
410 while (size >= sizeof(zeros)) {
411 if (write(fd, zeros, sizeof(zeros)) < 0) {
412 MMKVError("fail to write fd[%d], error:%s", fd, strerror(errno));
413 return false;
414 }
415 size -= sizeof(zeros);
416 }
417 if (size > 0) {
418 if (write(fd, zeros, size) < 0) {
419 MMKVError("fail to write fd[%d], error:%s", fd, strerror(errno));
420 return false;
421 }
422 }
423 return true;
424}
425
426#ifndef MMKV_APPLE
427

Callers 1

truncateMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected