Skip to content

Commit 08af426

Browse files
committed
[example] 格式化整理
1 parent ce86058 commit 08af426

30 files changed

+1132
-1132
lines changed

examples/file/listdir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2020, RT-Thread Development Team
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*

examples/file/readspeed.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2020, RT-Thread Development Team
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -46,9 +46,9 @@ void readspeed(const char* filename, int block_size)
4646
}
4747
tick = rt_tick_get() - tick;
4848

49-
/* close file and release memory */
49+
/* close file and release memory */
5050
close(fd);
51-
rt_free(buff_ptr);
51+
rt_free(buff_ptr);
5252

5353
/* calculate read speed */
5454
rt_kprintf("File read speed: %d byte/s\n", total_length /tick * RT_TICK_PER_SECOND);

examples/file/readwrite.c

Lines changed: 104 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2020, RT-Thread Development Team
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -17,21 +17,21 @@
1717
/* file read write test */
1818
void readwrite(const char* filename)
1919
{
20-
int fd;
21-
int index, length;
22-
char* test_data;
23-
char* buffer;
24-
int block_size = TEST_DATA_LEN;
25-
26-
/* open with write only & create */
27-
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0);
28-
if (fd < 0)
29-
{
30-
rt_kprintf("open file for write failed\n");
31-
return;
32-
}
33-
34-
test_data = rt_malloc(block_size);
20+
int fd;
21+
int index, length;
22+
char* test_data;
23+
char* buffer;
24+
int block_size = TEST_DATA_LEN;
25+
26+
/* open with write only & create */
27+
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0);
28+
if (fd < 0)
29+
{
30+
rt_kprintf("open file for write failed\n");
31+
return;
32+
}
33+
34+
test_data = rt_malloc(block_size);
3535
if (test_data == RT_NULL)
3636
{
3737
rt_kprintf("no memory\n");
@@ -48,94 +48,94 @@ void readwrite(const char* filename)
4848
return;
4949
}
5050

51-
/* prepare some data */
52-
for (index = 0; index < block_size; index ++)
53-
{
54-
test_data[index] = index + 27;
55-
}
56-
57-
/* write to file */
58-
length = write(fd, test_data, block_size);
59-
if (length != block_size)
60-
{
61-
rt_kprintf("write data failed\n");
62-
close(fd);
63-
goto __exit;
64-
}
65-
66-
/* close file */
67-
close(fd);
68-
69-
/* reopen the file with append to the end */
70-
fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0);
71-
if (fd < 0)
72-
{
73-
rt_kprintf("open file for append write failed\n");
74-
goto __exit;;
75-
}
76-
77-
length = write(fd, test_data, block_size);
78-
if (length != block_size)
79-
{
80-
rt_kprintf("append write data failed\n");
81-
close(fd);
82-
goto __exit;
83-
}
84-
/* close the file */
85-
close(fd);
86-
87-
/* open the file for data validation. */
88-
fd = open(filename, O_RDONLY, 0);
89-
if (fd < 0)
90-
{
91-
rt_kprintf("check: open file for read failed\n");
92-
goto __exit;
93-
}
94-
95-
/* read the data (should be the data written by the first time ) */
96-
length = read(fd, buffer, block_size);
97-
if (length != block_size)
98-
{
99-
rt_kprintf("check: read file failed\n");
100-
close(fd);
101-
goto __exit;
102-
}
103-
104-
/* validate */
105-
for (index = 0; index < block_size; index ++)
106-
{
107-
if (test_data[index] != buffer[index])
108-
{
109-
rt_kprintf("check: check data failed at %d\n", index);
110-
close(fd);
111-
goto __exit;
112-
}
113-
}
114-
115-
/* read the data (should be the second time data) */
116-
length = read(fd, buffer, block_size);
117-
if (length != block_size)
118-
{
119-
rt_kprintf("check: read file failed\n");
120-
close(fd);
121-
goto __exit;
122-
}
123-
124-
/* validate */
125-
for (index = 0; index < block_size; index ++)
126-
{
127-
if (test_data[index] != buffer[index])
128-
{
129-
rt_kprintf("check: check data failed at %d\n", index);
130-
close(fd);
131-
goto __exit;
132-
}
133-
}
134-
135-
/* close the file */
136-
close(fd);
137-
/* print result */
138-
rt_kprintf("read/write test successful!\n");
51+
/* prepare some data */
52+
for (index = 0; index < block_size; index ++)
53+
{
54+
test_data[index] = index + 27;
55+
}
56+
57+
/* write to file */
58+
length = write(fd, test_data, block_size);
59+
if (length != block_size)
60+
{
61+
rt_kprintf("write data failed\n");
62+
close(fd);
63+
goto __exit;
64+
}
65+
66+
/* close file */
67+
close(fd);
68+
69+
/* reopen the file with append to the end */
70+
fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0);
71+
if (fd < 0)
72+
{
73+
rt_kprintf("open file for append write failed\n");
74+
goto __exit;;
75+
}
76+
77+
length = write(fd, test_data, block_size);
78+
if (length != block_size)
79+
{
80+
rt_kprintf("append write data failed\n");
81+
close(fd);
82+
goto __exit;
83+
}
84+
/* close the file */
85+
close(fd);
86+
87+
/* open the file for data validation. */
88+
fd = open(filename, O_RDONLY, 0);
89+
if (fd < 0)
90+
{
91+
rt_kprintf("check: open file for read failed\n");
92+
goto __exit;
93+
}
94+
95+
/* read the data (should be the data written by the first time ) */
96+
length = read(fd, buffer, block_size);
97+
if (length != block_size)
98+
{
99+
rt_kprintf("check: read file failed\n");
100+
close(fd);
101+
goto __exit;
102+
}
103+
104+
/* validate */
105+
for (index = 0; index < block_size; index ++)
106+
{
107+
if (test_data[index] != buffer[index])
108+
{
109+
rt_kprintf("check: check data failed at %d\n", index);
110+
close(fd);
111+
goto __exit;
112+
}
113+
}
114+
115+
/* read the data (should be the second time data) */
116+
length = read(fd, buffer, block_size);
117+
if (length != block_size)
118+
{
119+
rt_kprintf("check: read file failed\n");
120+
close(fd);
121+
goto __exit;
122+
}
123+
124+
/* validate */
125+
for (index = 0; index < block_size; index ++)
126+
{
127+
if (test_data[index] != buffer[index])
128+
{
129+
rt_kprintf("check: check data failed at %d\n", index);
130+
close(fd);
131+
goto __exit;
132+
}
133+
}
134+
135+
/* close the file */
136+
close(fd);
137+
/* print result */
138+
rt_kprintf("read/write test successful!\n");
139139

140140
__exit:
141141
rt_free(test_data);

examples/file/seekdir.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2020, RT-Thread Development Team
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -12,35 +12,35 @@
1212

1313
void seekdir_test(void)
1414
{
15-
DIR * dirp;
16-
long save3 = 0;
17-
int i = 0;
18-
struct dirent *dp;
15+
DIR * dirp;
16+
long save3 = 0;
17+
int i = 0;
18+
struct dirent *dp;
1919

20-
dirp = opendir ("/");
21-
save3 = telldir(dirp);
22-
for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp))
23-
{
24-
rt_kprintf("direntry: %s\n", dp->d_name);
20+
dirp = opendir ("/");
21+
save3 = telldir(dirp);
22+
for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp))
23+
{
24+
rt_kprintf("direntry: %s\n", dp->d_name);
2525

26-
/* save the pointer of the third directory */
27-
if (i++ == 3)
28-
{
29-
save3 = telldir(dirp);
30-
}
31-
}
26+
/* save the pointer of the third directory */
27+
if (i++ == 3)
28+
{
29+
save3 = telldir(dirp);
30+
}
31+
}
3232

33-
/* get back to the third directory */
34-
seekdir (dirp, save3);
35-
rt_kprintf("seek dientry to: %d\n", save3);
36-
for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp))
37-
{
38-
rt_kprintf("direntry: %s\n", dp->d_name);
39-
}
33+
/* get back to the third directory */
34+
seekdir (dirp, save3);
35+
rt_kprintf("seek dientry to: %d\n", save3);
36+
for (dp = readdir(dirp); dp != RT_NULL; dp = readdir(dirp))
37+
{
38+
rt_kprintf("direntry: %s\n", dp->d_name);
39+
}
4040

41-
/* close the directory */
42-
closedir (dirp);
43-
}
41+
/* close the directory */
42+
closedir (dirp);
43+
}
4444

4545
#ifdef RT_USING_FINSH
4646
#include <finsh.h>

examples/file/writespeed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2020, RT-Thread Development Team
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*

examples/kernel/tc_comm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __TC_COMM_H__
22
#define __TC_COMM_H__
33

4-
/*
4+
/*
55
* RT-Thread TestCase
66
*
77
*/

examples/kernel/timer_control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static rt_uint8_t count;
1414
static void timeout1(void* parameter)
1515
{
1616
rt_tick_t timeout = 50;
17-
17+
1818
rt_kprintf("periodic timer is timeout\n");
1919

2020
count ++;

0 commit comments

Comments
 (0)