The Utils repository stores basic components of OpenHarmony. These basic components are used by OpenHarmony subsystems and upper-layer applications.
The Utils library provides the following capabilities on different platforms:
Table 1 Utils capabilities
utils/native/lite/ # Root directory
├── file # Implementation of the file system APIs
├── hals # HAL directory
│ └── file # Header files of the hardware abstraction layer for file operations
├── include # Header files of external APIs
├── js # JavaScript APIs
│ └── builtin
│ ├── common # Builtin common function
│ ├── deviceinfokit # Device information kit
│ ├── filekit # File kit
│ └── kvstorekit # KV store kit
├── kal # KAL directory
│ └── timer # KAL implementation of the timer
├── kv_store # KV store implementation
│ ├── innerkits # Internal KV store APIs
│ └── src # KV store source file
├── memory
│ └── include # Memory pool management APIs
└── timer_task # Timer implementation
KV store
// Store or update the value of a key.
const char key1[] = "key_sample";
const char defValue[] = "test case of key value store.";
int ret = UtilsSetValue(key1, defValue);
// Obtain the value of the key.
char value1[32] = {0};
ret = UtilsGetValue(key1, value1, 32);
// Delete the value of the key.
UtilsDeleteValue(key1);
File operation
// Open or create a file.
const char fileName[] = "testfile";
int fd = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS | O_TRUNC_FS, 0);
// Write a specified length of data into a file with the specified file descriptor.
const char defValue[] = "test case of file system.";
int ret = UtilsFileWrite(fd, defValue, strlen(defValue));
// Close a file with a specified file descriptor.
UtilsFileClose(fd);
// Obtain the file size.
int fileLen = 0;
ret = UtilsFileStat(fileName, &fileLen);
printf("file size = %d\n", fileLen);
// Adjust the read and write position offset in a file.
int fd1 = UtilsFileOpen(fileName, O_RDWR_FS, 0);
ret = UtilsFileSeek(fd1, 5, SEEK_SET_FS);
// Read a specified length of data from a file with the specified file descriptor and write the data into the buffer.
char buf[32] = {0};
int readLen = UtilsFileRead(fd1, buf, 32);
ret = UtilsFileClose(fd1);
printf("read len = %d : buf = %s\n", readLen, buf);
// Delete a specified file.
ret = UtilsFileDelete(fileName);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。