diff options
| author | Meco Man <[email protected]> | 2021-03-07 08:34:04 +0800 |
|---|---|---|
| committer | Meco Man <[email protected]> | 2021-03-07 08:34:04 +0800 |
| commit | 08af426f01cf0321719c937d29a1d9315a0feab8 (patch) | |
| tree | cb9c4e5ba1db25c5878b732a2651ec3646efc4d1 /examples/file | |
| parent | ce86058201432e865b8d7c4096b3675642a43a42 (diff) | |
[example] 格式化整理
Diffstat (limited to 'examples/file')
| -rw-r--r-- | examples/file/listdir.c | 2 | ||||
| -rw-r--r-- | examples/file/readspeed.c | 6 | ||||
| -rw-r--r-- | examples/file/readwrite.c | 184 | ||||
| -rw-r--r-- | examples/file/seekdir.c | 52 | ||||
| -rw-r--r-- | examples/file/writespeed.c | 2 |
5 files changed, 123 insertions, 123 deletions
diff --git a/examples/file/listdir.c b/examples/file/listdir.c index d8ea7af82a..98fbc5ea2c 100644 --- a/examples/file/listdir.c +++ b/examples/file/listdir.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2020, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * diff --git a/examples/file/readspeed.c b/examples/file/readspeed.c index e5073856b4..ffc19635cf 100644 --- a/examples/file/readspeed.c +++ b/examples/file/readspeed.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2020, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -46,9 +46,9 @@ void readspeed(const char* filename, int block_size) } tick = rt_tick_get() - tick; - /* close file and release memory */ + /* close file and release memory */ close(fd); - rt_free(buff_ptr); + rt_free(buff_ptr); /* calculate read speed */ rt_kprintf("File read speed: %d byte/s\n", total_length /tick * RT_TICK_PER_SECOND); diff --git a/examples/file/readwrite.c b/examples/file/readwrite.c index 5738323805..56f3b7e16c 100644 --- a/examples/file/readwrite.c +++ b/examples/file/readwrite.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2020, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -17,21 +17,21 @@ /* file read write test */ void readwrite(const char* filename) { - int fd; - int index, length; - char* test_data; - char* buffer; - int block_size = TEST_DATA_LEN; + int fd; + int index, length; + char* test_data; + char* buffer; + int block_size = TEST_DATA_LEN; - /* open with write only & create */ - fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0); - if (fd < 0) - { - rt_kprintf("open file for write failed\n"); - return; - } + /* open with write only & create */ + fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0); + if (fd < 0) + { + rt_kprintf("open file for write failed\n"); + return; + } - test_data = rt_malloc(block_size); + test_data = rt_malloc(block_size); if (test_data == RT_NULL) { rt_kprintf("no memory\n"); @@ -48,94 +48,94 @@ void readwrite(const char* filename) return; } - /* prepare some data */ - for (index = 0; index < block_size; index ++) - { - test_data[index] = index + 27; - } + /* prepare some data */ + for (index = 0; index < block_size; index ++) + { + test_data[index] = index + 27; + } - /* write to file */ - length = write(fd, test_data, block_size); - if (length != block_size) - { - rt_kprintf("write data failed\n"); - close(fd); - goto __exit; - } + /* write to file */ + length = write(fd, test_data, block_size); + if (length != block_size) + { + rt_kprintf("write data failed\n"); + close(fd); + goto __exit; + } - /* close file */ - close(fd); + /* close file */ + close(fd); - /* reopen the file with append to the end */ - fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0); - if (fd < 0) - { - rt_kprintf("open file for append write failed\n"); - goto __exit;; - } + /* reopen the file with append to the end */ + fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0); + if (fd < 0) + { + rt_kprintf("open file for append write failed\n"); + goto __exit;; + } - length = write(fd, test_data, block_size); - if (length != block_size) - { - rt_kprintf("append write data failed\n"); - close(fd); - goto __exit; - } - /* close the file */ - close(fd); + length = write(fd, test_data, block_size); + if (length != block_size) + { + rt_kprintf("append write data failed\n"); + close(fd); + goto __exit; + } + /* close the file */ + close(fd); - /* open the file for data validation. */ - fd = open(filename, O_RDONLY, 0); - if (fd < 0) - { - rt_kprintf("check: open file for read failed\n"); - goto __exit; - } + /* open the file for data validation. */ + fd = open(filename, O_RDONLY, 0); + if (fd < 0) + { + rt_kprintf("check: open file for read failed\n"); + goto __exit; + } - /* read the data (should be the data written by the first time ) */ - length = read(fd, buffer, block_size); - if (length != block_size) - { - rt_kprintf("check: read file failed\n"); - close(fd); - goto __exit; - } + /* read the data (should be the data written by the first time ) */ + length = read(fd, buffer, block_size); + if (length != block_size) + { + rt_kprintf("check: read file failed\n"); + close(fd); + goto __exit; + } - /* validate */ - for (index = 0; index < block_size; index ++) - { - if (test_data[index] != buffer[index]) - { - rt_kprintf("check: check data failed at %d\n", index); - close(fd); - goto __exit; - } - } + /* validate */ + for (index = 0; index < block_size; index ++) + { + if (test_data[index] != buffer[index]) + { + rt_kprintf("check: check data failed at %d\n", index); + close(fd); + goto __exit; + } + } - /* read the data (should be the second time data) */ - length = read(fd, buffer, block_size); - if (length != block_size) - { - rt_kprintf("check: read file failed\n"); - close(fd); - goto __exit; - } + /* read the data (should be the second time data) */ + length = read(fd, buffer, block_size); + if (length != block_size) + { + rt_kprintf("check: read file failed\n"); + close(fd); + goto __exit; + } - /* validate */ - for (index = 0; index < block_size; index ++) - { - if (test_data[index] != buffer[index]) - { - rt_kprintf("check: check data failed at %d\n", index); - close(fd); - goto __exit; - } - } + /* validate */ + for (index = 0; index < block_size; index ++) + { + if (test_data[index] != buffer[index]) + { + rt_kprintf("check: check data failed at %d\n", index); + close(fd); + goto __exit; + } + } - /* close the file */ - close(fd); - /* print result */ - rt_kprintf("read/write test successful!\n"); + /* close the file */ + close(fd); + /* print result */ + rt_kprintf("read/write test successful!\n"); __exit: rt_free(test_data); diff --git a/examples/file/seekdir.c b/examples/file/seekdir.c index d6a33426b4..efadd3a1c8 100644 --- a/examples/file/seekdir.c +++ b/examples/file/seekdir.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2020, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -12,35 +12,35 @@ void seekdir_test(void) { - DIR * dirp; - long save3 = 0; - int i = 0; - struct dirent *dp; + DIR * dirp; + long save3 = 0; + int i = 0; + struct dirent *dp; - dirp = opendir ("/"); - save3 = telldir(dirp); - for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp)) - { - rt_kprintf("direntry: %s\n", dp->d_name); + dirp = opendir ("/"); + save3 = telldir(dirp); + for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp)) + { + rt_kprintf("direntry: %s\n", dp->d_name); - /* save the pointer of the third directory */ - if (i++ == 3) - { - save3 = telldir(dirp); - } - } + /* save the pointer of the third directory */ + if (i++ == 3) + { + save3 = telldir(dirp); + } + } - /* get back to the third directory */ - seekdir (dirp, save3); - rt_kprintf("seek dientry to: %d\n", save3); - for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp)) - { - rt_kprintf("direntry: %s\n", dp->d_name); - } + /* get back to the third directory */ + seekdir (dirp, save3); + rt_kprintf("seek dientry to: %d\n", save3); + for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp)) + { + rt_kprintf("direntry: %s\n", dp->d_name); + } - /* close the directory */ - closedir (dirp); -} + /* close the directory */ + closedir (dirp); +} #ifdef RT_USING_FINSH #include <finsh.h> diff --git a/examples/file/writespeed.c b/examples/file/writespeed.c index 60dd900a68..680761583c 100644 --- a/examples/file/writespeed.c +++ b/examples/file/writespeed.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2020, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * |
