1# commonlibrary/utils_lite<a name="EN-US_TOPIC_0000001121139825"></a> 2 3- [Overview](#section62661387114) 4- [Directory Structure](#section1464106163817) 5- [Usage](#section25021123178) 6- [Repositories Involved](#section4571352889) 7 8## Overview<a name="section62661387114"></a> 9 10The utils_lite repository stores basic components of OpenHarmony. These basic components are used by OpenHarmony subsystems and upper-layer applications. 11 12The utils_lite library provides the following capabilities on different platforms: 13 14- LiteOS Cortex-M \(Hi3861 platform\): file operations and timer 15- LiteOS Cortex-A \(Hi3516 or Hi3518 platform\): timer and JavaScript APIs for device query and data storage 16 17**Table 1** Utils_lite capabilities 18 19<a name="en-us_topic_0000001052623010_table206292206282"></a> 20<table><thead align="left"><tr id="en-us_topic_0000001052623010_row8629020112819"><th class="cellrowborder" valign="top" width="21.22%" id="mcps1.2.4.1.1"><p id="en-us_topic_0000001052623010_p66291220192816"><a name="en-us_topic_0000001052623010_p66291220192816"></a><a name="en-us_topic_0000001052623010_p66291220192816"></a>Module</p> 21</th> 22<th class="cellrowborder" valign="top" width="24.77%" id="mcps1.2.4.1.2"><p id="en-us_topic_0000001052623010_p3629122014289"><a name="en-us_topic_0000001052623010_p3629122014289"></a><a name="en-us_topic_0000001052623010_p3629122014289"></a>Platform</p> 23</th> 24<th class="cellrowborder" valign="top" width="54.010000000000005%" id="mcps1.2.4.1.3"><p id="en-us_topic_0000001052623010_p206298206288"><a name="en-us_topic_0000001052623010_p206298206288"></a><a name="en-us_topic_0000001052623010_p206298206288"></a>Description</p> 25</th> 26</tr> 27</thead> 28<tbody> 29<tr id="en-us_topic_0000001052623010_row116301920152816"><td class="cellrowborder" valign="top" width="21.22%" headers="mcps1.2.4.1.1 "><p id="en-us_topic_0000001052623010_p96300207286"><a name="en-us_topic_0000001052623010_p96300207286"></a><a name="en-us_topic_0000001052623010_p96300207286"></a>File operation</p> 30</td> 31<td class="cellrowborder" valign="top" width="24.77%" headers="mcps1.2.4.1.2 "><p id="en-us_topic_0000001052623010_p1463032012281"><a name="en-us_topic_0000001052623010_p1463032012281"></a><a name="en-us_topic_0000001052623010_p1463032012281"></a>LiteOS Cortex-M</p> 32</td> 33<td class="cellrowborder" valign="top" width="54.010000000000005%" headers="mcps1.2.4.1.3 "><p id="en-us_topic_0000001052623010_p163042052810"><a name="en-us_topic_0000001052623010_p163042052810"></a><a name="en-us_topic_0000001052623010_p163042052810"></a>Provides unified file operation interfaces that can be used on different underlying chip components.</p> 34</td> 35</tr> 36<tr id="en-us_topic_0000001052623010_row1163022022812"><td class="cellrowborder" valign="top" width="21.22%" headers="mcps1.2.4.1.1 "><p id="en-us_topic_0000001052623010_p66308202284"><a name="en-us_topic_0000001052623010_p66308202284"></a><a name="en-us_topic_0000001052623010_p66308202284"></a>Timer</p> 37</td> 38<td class="cellrowborder" valign="top" width="24.77%" headers="mcps1.2.4.1.2 "><p id="en-us_topic_0000001052623010_p26301620192820"><a name="en-us_topic_0000001052623010_p26301620192820"></a><a name="en-us_topic_0000001052623010_p26301620192820"></a>LiteOS Cortex-M and LiteOS Cortex-A</p> 39</td> 40<td class="cellrowborder" valign="top" width="54.010000000000005%" headers="mcps1.2.4.1.3 "><p id="en-us_topic_0000001052623010_p2630172062815"><a name="en-us_topic_0000001052623010_p2630172062815"></a><a name="en-us_topic_0000001052623010_p2630172062815"></a>Provides unified timer operation interfaces that can be used on different underlying chip components.</p> 41</td> 42</tr> 43<tr id="en-us_topic_0000001052623010_row363012202282"><td class="cellrowborder" valign="top" width="21.22%" headers="mcps1.2.4.1.1 "><p id="en-us_topic_0000001052623010_p4502105418285"><a name="en-us_topic_0000001052623010_p4502105418285"></a><a name="en-us_topic_0000001052623010_p4502105418285"></a>JavaScript API</p> 44</td> 45<td class="cellrowborder" valign="top" width="24.77%" headers="mcps1.2.4.1.2 "><p id="en-us_topic_0000001052623010_p199870135293"><a name="en-us_topic_0000001052623010_p199870135293"></a><a name="en-us_topic_0000001052623010_p199870135293"></a>LiteOS Cortex-A</p> 46</td> 47<td class="cellrowborder" valign="top" width="54.010000000000005%" headers="mcps1.2.4.1.3 "><p id="en-us_topic_0000001052623010_p1550005422814"><a name="en-us_topic_0000001052623010_p1550005422814"></a><a name="en-us_topic_0000001052623010_p1550005422814"></a>Provides JavaScript APIs for obtaining device information and storing data.</p> 48</td> 49</tr> 50</tbody> 51</table> 52 53## Directory Structure<a name="section1464106163817"></a> 54 55``` 56commonlibrary/utils_lite/ # Root directory 57├── file # Implementation of the file system APIs 58├── hals # HAL directory 59│ └── file # Header files of the hardware abstraction layer for file operations 60├── include # Header files of external APIs 61├── js # JavaScript APIs 62│ └── builtin 63│ ├── common # Builtin common function 64│ ├── deviceinfokit # Device information kit 65│ ├── filekit # File kit 66│ └── kvstorekit # KV store kit 67├── kal # KAL directory 68│ └── timer # KAL implementation of the timer 69├── memory 70│ └── include # Memory pool management APIs 71└── timer_task # Timer implementation 72``` 73 74## Usage<a name="section25021123178"></a> 75 76- **File operation** 77 78 ``` 79 // Open or create a file. 80 const char fileName[] = "testfile"; 81 int fd = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS | O_TRUNC_FS, 0); 82 83 // Write a specified length of data into a file with the specified file descriptor. 84 const char defValue[] = "test case of file system."; 85 int ret = UtilsFileWrite(fd, defValue, strlen(defValue)); 86 87 // Close a file with a specified file descriptor. 88 UtilsFileClose(fd); 89 90 // Obtain the file size. 91 int fileLen = 0; 92 ret = UtilsFileStat(fileName, &fileLen); 93 printf("file size = %d\n", fileLen); 94 95 // Adjust the read and write position offset in a file. 96 int fd1 = UtilsFileOpen(fileName, O_RDWR_FS, 0); 97 ret = UtilsFileSeek(fd1, 5, SEEK_SET_FS); 98 99 // Read a specified length of data from a file with the specified file descriptor and write the data into the buffer. 100 char buf[32] = {0}; 101 int readLen = UtilsFileRead(fd1, buf, 32); 102 ret = UtilsFileClose(fd1); 103 printf("read len = %d : buf = %s\n", readLen, buf); 104 105 // Delete a specified file. 106 ret = UtilsFileDelete(fileName); 107 ``` 108 109 110 111## Repositories Involved<a name="section4571352889"></a> 112 113[commonlibrary](https://gitee.com/openharmony/docs/blob/master/en/readme/utils.md) 114 115[**commonlibrary\_utils\_lite**](https://gitee.com/openharmony/commonlibrary_utils_lite)