Skip to content

Commit 29fb860

Browse files
illustriousnessRbb666
authored andcommitted
finsh: replace str/mem functions with rt-prefixed versions
Replace standard string and memory functions with RT-Thread's rt-prefixed equivalents where available: - strcpy -> rt_strcpy - strncpy -> rt_strncpy - strcmp -> rt_strcmp - strncmp -> rt_strncmp - strlen -> rt_strlen - strstr -> rt_strstr - memcpy -> rt_memcpy - memcmp -> rt_memcmp Functions like strcat, strchr remain unchanged as RT-Thread does not provide rt-prefixed versions.
1 parent 6ab057b commit 29fb860

File tree

4 files changed

+49
-49
lines changed

4 files changed

+49
-49
lines changed

components/finsh/cmd.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -940,64 +940,64 @@ static int cmd_list(int argc, char **argv)
940940
{
941941
if(argc == 2)
942942
{
943-
if(strcmp(argv[1], "thread") == 0)
943+
if(rt_strcmp(argv[1], "thread") == 0)
944944
{
945945
list_thread();
946946
}
947-
else if(strcmp(argv[1], "timer") == 0)
947+
else if(rt_strcmp(argv[1], "timer") == 0)
948948
{
949949
list_timer();
950950
}
951951
#ifdef RT_USING_SEMAPHORE
952-
else if(strcmp(argv[1], "sem") == 0)
952+
else if(rt_strcmp(argv[1], "sem") == 0)
953953
{
954954
list_sem();
955955
}
956956
#endif /* RT_USING_SEMAPHORE */
957957
#ifdef RT_USING_EVENT
958-
else if(strcmp(argv[1], "event") == 0)
958+
else if(rt_strcmp(argv[1], "event") == 0)
959959
{
960960
list_event();
961961
}
962962
#endif /* RT_USING_EVENT */
963963
#ifdef RT_USING_MUTEX
964-
else if(strcmp(argv[1], "mutex") == 0)
964+
else if(rt_strcmp(argv[1], "mutex") == 0)
965965
{
966966
list_mutex();
967967
}
968968
#endif /* RT_USING_MUTEX */
969969
#ifdef RT_USING_MAILBOX
970-
else if(strcmp(argv[1], "mailbox") == 0)
970+
else if(rt_strcmp(argv[1], "mailbox") == 0)
971971
{
972972
list_mailbox();
973973
}
974974
#endif /* RT_USING_MAILBOX */
975975
#ifdef RT_USING_MESSAGEQUEUE
976-
else if(strcmp(argv[1], "msgqueue") == 0)
976+
else if(rt_strcmp(argv[1], "msgqueue") == 0)
977977
{
978978
list_msgqueue();
979979
}
980980
#endif /* RT_USING_MESSAGEQUEUE */
981981
#ifdef RT_USING_MEMHEAP
982-
else if(strcmp(argv[1], "memheap") == 0)
982+
else if(rt_strcmp(argv[1], "memheap") == 0)
983983
{
984984
list_memheap();
985985
}
986986
#endif /* RT_USING_MEMHEAP */
987987
#ifdef RT_USING_MEMPOOL
988-
else if(strcmp(argv[1], "mempool") == 0)
988+
else if(rt_strcmp(argv[1], "mempool") == 0)
989989
{
990990
list_mempool();
991991
}
992992
#endif /* RT_USING_MEMPOOL */
993993
#ifdef RT_USING_DEVICE
994-
else if(strcmp(argv[1], "device") == 0)
994+
else if(rt_strcmp(argv[1], "device") == 0)
995995
{
996996
list_device();
997997
}
998998
#endif /* RT_USING_DEVICE */
999999
#ifdef RT_USING_DFS
1000-
else if(strcmp(argv[1], "fd") == 0)
1000+
else if(rt_strcmp(argv[1], "fd") == 0)
10011001
{
10021002
extern int list_fd(void);
10031003
list_fd();

components/finsh/msh.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static int cmd_ps(int argc, char **argv)
6363
extern int list_module(void);
6464

6565
#ifdef RT_USING_MODULE
66-
if ((argc == 2) && (strcmp(argv[1], "-m") == 0))
66+
if ((argc == 2) && (rt_strcmp(argv[1], "-m") == 0))
6767
list_module();
6868
else
6969
#endif
@@ -237,7 +237,7 @@ static cmd_function_t msh_get_cmd(char *cmd, int size)
237237
index < _syscall_table_end;
238238
FINSH_NEXT_SYSCALL(index))
239239
{
240-
if (strncmp(index->name, cmd, size) == 0 &&
240+
if (rt_strncmp(index->name, cmd, size) == 0 &&
241241
index->name[size] == '\0')
242242
{
243243
cmd_func = (cmd_function_t)index->func;
@@ -276,7 +276,7 @@ int msh_exec_module(const char *cmd_line, int size)
276276
rt_memcpy(pg_name, cmd_line, cmd_length);
277277
pg_name[cmd_length] = '\0';
278278

279-
if (strstr(pg_name, ".mo") != RT_NULL || strstr(pg_name, ".MO") != RT_NULL)
279+
if (rt_strstr(pg_name, ".mo") != RT_NULL || rt_strstr(pg_name, ".MO") != RT_NULL)
280280
{
281281
/* try to open program */
282282
fd = open(pg_name, O_RDONLY, 0);
@@ -374,12 +374,12 @@ static rt_bool_t _msh_lwp_cmd_exists(const char *path)
374374
static char *_msh_exec_search_path(const char *path, const char *pg_name)
375375
{
376376
char *path_buffer = RT_NULL;
377-
ssize_t pg_len = strlen(pg_name);
377+
ssize_t pg_len = rt_strlen(pg_name);
378378
ssize_t base_len = 0;
379379

380380
if (path)
381381
{
382-
base_len = strlen(path);
382+
base_len = rt_strlen(path);
383383
}
384384

385385
path_buffer = rt_malloc(base_len + pg_len + 6);
@@ -390,7 +390,7 @@ static char *_msh_exec_search_path(const char *path, const char *pg_name)
390390

391391
if (base_len > 0)
392392
{
393-
memcpy(path_buffer, path, base_len);
393+
rt_memcpy(path_buffer, path, base_len);
394394
path_buffer[base_len] = '/';
395395
path_buffer[base_len + 1] = '\0';
396396
}
@@ -405,7 +405,7 @@ static char *_msh_exec_search_path(const char *path, const char *pg_name)
405405
return path_buffer;
406406
}
407407

408-
if (strstr(path_buffer, ".elf") != NULL)
408+
if (rt_strstr(path_buffer, ".elf") != NULL)
409409
{
410410
goto not_found;
411411
}
@@ -506,7 +506,7 @@ int _msh_exec_lwp(int debug, char *cmd, rt_size_t length)
506506

507507
/* only check these paths when the first argument doesn't contain path
508508
seperator */
509-
if (strstr(argv[0], "/"))
509+
if (rt_strstr(argv[0], "/"))
510510
{
511511
return -1;
512512
}
@@ -704,14 +704,14 @@ void msh_auto_complete_path(char *path)
704704
if (dirent == RT_NULL) break;
705705

706706
/* matched the prefix string */
707-
if (strncmp(index, dirent->d_name, rt_strlen(index)) == 0)
707+
if (rt_strncmp(index, dirent->d_name, rt_strlen(index)) == 0)
708708
{
709709
multi ++;
710710
if (min_length == 0)
711711
{
712712
min_length = rt_strlen(dirent->d_name);
713713
/* save dirent name */
714-
strcpy(full_path, dirent->d_name);
714+
rt_strcpy(full_path, dirent->d_name);
715715
}
716716

717717
length = str_common(dirent->d_name, full_path);
@@ -735,7 +735,7 @@ void msh_auto_complete_path(char *path)
735735
dirent = readdir(dir);
736736
if (dirent == RT_NULL) break;
737737

738-
if (strncmp(index, dirent->d_name, rt_strlen(index)) == 0)
738+
if (rt_strncmp(index, dirent->d_name, rt_strlen(index)) == 0)
739739
rt_kprintf("%s\n", dirent->d_name);
740740
}
741741
}
@@ -822,14 +822,14 @@ void msh_auto_complete(char *prefix)
822822
{
823823
/* skip finsh shell function */
824824
cmd_name = (const char *) index->name;
825-
if (strncmp(prefix, cmd_name, strlen(prefix)) == 0)
825+
if (rt_strncmp(prefix, cmd_name, rt_strlen(prefix)) == 0)
826826
{
827827
if (min_length == 0)
828828
{
829829
/* set name_ptr */
830830
name_ptr = cmd_name;
831831
/* set initial length */
832-
min_length = strlen(name_ptr);
832+
min_length = rt_strlen(name_ptr);
833833
}
834834

835835
length = str_common(name_ptr, cmd_name);
@@ -865,14 +865,14 @@ static msh_cmd_opt_t *msh_get_cmd_opt(char *opt_str)
865865
}
866866
else
867867
{
868-
len = strlen(opt_str);
868+
len = rt_strlen(opt_str);
869869
}
870870
#if defined(FINSH_USING_SYMTAB)
871871
for (index = _syscall_table_begin;
872872
index < _syscall_table_end;
873873
FINSH_NEXT_SYSCALL(index))
874874
{
875-
if (strncmp(index->name, opt_str, len) == 0 && index->name[len] == '\0')
875+
if (rt_strncmp(index->name, opt_str, len) == 0 && index->name[len] == '\0')
876876
{
877877
opt = index->opt;
878878
break;
@@ -906,18 +906,18 @@ static void msh_opt_complete(char *opts_str, struct msh_cmd_opt *cmd_opt)
906906
const char *name_ptr = RT_NULL;
907907
int min_length = 0, length, opts_str_len;
908908

909-
opts_str_len = strlen(opts_str);
909+
opts_str_len = rt_strlen(opts_str);
910910

911911
for (opt = cmd_opt; opt->id; opt++)
912912
{
913-
if (!strncmp(opt->name, opts_str, opts_str_len))
913+
if (!rt_strncmp(opt->name, opts_str, opts_str_len))
914914
{
915915
if (min_length == 0)
916916
{
917917
/* set name_ptr */
918918
name_ptr = opt->name;
919919
/* set initial length */
920-
min_length = strlen(name_ptr);
920+
min_length = rt_strlen(name_ptr);
921921
}
922922

923923
length = str_common(name_ptr, opt->name);
@@ -933,7 +933,7 @@ static void msh_opt_complete(char *opts_str, struct msh_cmd_opt *cmd_opt)
933933

934934
if (name_ptr != NULL)
935935
{
936-
strncpy(opts_str, name_ptr, min_length);
936+
rt_strncpy(opts_str, name_ptr, min_length);
937937
}
938938
}
939939

@@ -959,7 +959,7 @@ void msh_opt_auto_complete(char *prefix)
959959
{
960960
opt = msh_get_cmd_opt(prefix);
961961
}
962-
else if (!msh_get_cmd(prefix, strlen(prefix)) && (' ' == prefix[strlen(prefix) - 1]))
962+
else if (!msh_get_cmd(prefix, rt_strlen(prefix)) && (' ' == prefix[rt_strlen(prefix) - 1]))
963963
{
964964
opt = msh_get_cmd_opt(prefix);
965965
}
@@ -989,7 +989,7 @@ int msh_cmd_opt_id_get(int argc, char *argv[], void *options)
989989

990990
for (opt_id = 0; (argc >= 2) && opt && opt->id; opt++)
991991
{
992-
if (!strcmp(opt->name, argv[1]))
992+
if (!rt_strcmp(opt->name, argv[1]))
993993
{
994994
opt_id = opt->id;
995995
break;

components/finsh/msh_file.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ int msh_exec_script(const char *cmd_line, int size)
9090
rt_memcpy(pg_name, cmd_line, cmd_length);
9191
pg_name[cmd_length] = '\0';
9292

93-
if (strstr(pg_name, ".sh") != RT_NULL || strstr(pg_name, ".SH") != RT_NULL)
93+
if (rt_strstr(pg_name, ".sh") != RT_NULL || rt_strstr(pg_name, ".SH") != RT_NULL)
9494
{
9595
/* try to open program */
9696
fd = open(pg_name, O_RDONLY, 0);
@@ -351,7 +351,7 @@ static void directory_delete_for_msh(const char *pathname, char f, char v)
351351
if (rt_strcmp(".", dirent->d_name) != 0 &&
352352
rt_strcmp("..", dirent->d_name) != 0)
353353
{
354-
if (strlen(pathname) + 1 + strlen(dirent->d_name) > DFS_PATH_MAX)
354+
if (rt_strlen(pathname) + 1 + rt_strlen(dirent->d_name) > DFS_PATH_MAX)
355355
{
356356
rt_kprintf("cannot remove '%s/%s', path too long.\n", pathname, dirent->d_name);
357357
continue;
@@ -518,7 +518,7 @@ static int cmd_mkfs(int argc, char **argv)
518518
}
519519
else if (argc == 4)
520520
{
521-
if (strcmp(argv[1], "-t") == 0)
521+
if (rt_strcmp(argv[1], "-t") == 0)
522522
{
523523
type = argv[2];
524524
result = dfs_mkfs(type, argv[3]);
@@ -585,7 +585,7 @@ static int cmd_mount(int argc, char **argv)
585585

586586
/* mount a filesystem to the specified directory */
587587
rt_kprintf("mount device %s(%s) onto %s ... ", device, fstype, path);
588-
if (strcmp(fstype, "nfs") == 0)
588+
if (rt_strcmp(fstype, "nfs") == 0)
589589
{
590590
data = argv[1];
591591
device = 0;
@@ -663,7 +663,7 @@ static int cmd_umount(int argc, char **argv)
663663

664664
if (argc > 2)
665665
{
666-
flags = strcmp(argv[1], "-f") == 0 ? MNT_FORCE : 0;
666+
flags = rt_strcmp(argv[1], "-f") == 0 ? MNT_FORCE : 0;
667667
path = argv[2];
668668
}
669669

@@ -693,7 +693,7 @@ static int cmd_df(int argc, char **argv)
693693
}
694694
else
695695
{
696-
if ((strcmp(argv[1], "--help") == 0) || (strcmp(argv[1], "-h") == 0))
696+
if ((rt_strcmp(argv[1], "--help") == 0) || (rt_strcmp(argv[1], "-h") == 0))
697697
{
698698
rt_kprintf("df [path]\n");
699699
}
@@ -721,7 +721,7 @@ static int cmd_echo(int argc, char **argv)
721721
fd = open(argv[2], O_RDWR | O_APPEND | O_CREAT, 0);
722722
if (fd >= 0)
723723
{
724-
write(fd, argv[1], strlen(argv[1]));
724+
write(fd, argv[1], rt_strlen(argv[1]));
725725
close(fd);
726726
}
727727
else
@@ -875,7 +875,7 @@ static void directory_setattr(const char *pathname, struct dfs_attr *attr, char
875875
if (rt_strcmp(".", dirent->d_name) != 0 &&
876876
rt_strcmp("..", dirent->d_name) != 0)
877877
{
878-
if (strlen(pathname) + 1 + strlen(dirent->d_name) > DFS_PATH_MAX)
878+
if (rt_strlen(pathname) + 1 + rt_strlen(dirent->d_name) > DFS_PATH_MAX)
879879
{
880880
rt_kprintf("'%s/%s' setattr failed, path too long.\n", pathname, dirent->d_name);
881881
continue;

components/finsh/shell.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ int finsh_set_prompt(const char *prompt)
7979
/* strdup */
8080
if (prompt)
8181
{
82-
finsh_prompt_custom = (char *)rt_malloc(strlen(prompt) + 1);
82+
finsh_prompt_custom = (char *)rt_malloc(rt_strlen(prompt) + 1);
8383
if (finsh_prompt_custom)
8484
{
85-
strcpy(finsh_prompt_custom, prompt);
85+
rt_strcpy(finsh_prompt_custom, prompt);
8686
}
8787
}
8888

@@ -105,11 +105,11 @@ const char *finsh_get_prompt(void)
105105

106106
if (finsh_prompt_custom)
107107
{
108-
strncpy(finsh_prompt, finsh_prompt_custom, sizeof(finsh_prompt) - 1);
108+
rt_strncpy(finsh_prompt, finsh_prompt_custom, sizeof(finsh_prompt) - 1);
109109
}
110110
else
111111
{
112-
strcpy(finsh_prompt, _MSH_PROMPT);
112+
rt_strcpy(finsh_prompt, _MSH_PROMPT);
113113
}
114114

115115
#if defined(DFS_USING_POSIX) && defined(DFS_USING_WORKDIR)
@@ -423,7 +423,7 @@ static void shell_push_history(struct finsh_shell *shell)
423423
if (shell->history_count >= FINSH_HISTORY_LINES)
424424
{
425425
/* if current cmd is same as last cmd, don't push */
426-
if (memcmp(&shell->cmd_history[FINSH_HISTORY_LINES - 1], shell->line, FINSH_CMD_SIZE))
426+
if (rt_memcmp(&shell->cmd_history[FINSH_HISTORY_LINES - 1], shell->line, FINSH_CMD_SIZE))
427427
{
428428
/* move history */
429429
int index;
@@ -442,7 +442,7 @@ static void shell_push_history(struct finsh_shell *shell)
442442
else
443443
{
444444
/* if current cmd is same as last cmd, don't push */
445-
if (shell->history_count == 0 || memcmp(&shell->cmd_history[shell->history_count - 1], shell->line, FINSH_CMD_SIZE))
445+
if (shell->history_count == 0 || rt_memcmp(&shell->cmd_history[shell->history_count - 1], shell->line, FINSH_CMD_SIZE))
446446
{
447447
shell->current_history = shell->history_count;
448448
rt_memset(&shell->cmd_history[shell->history_count][0], 0, FINSH_CMD_SIZE);
@@ -597,7 +597,7 @@ static void finsh_thread_entry(void *parameter)
597597
/* copy the history command */
598598
rt_memcpy(shell->line, &shell->cmd_history[shell->current_history][0],
599599
FINSH_CMD_SIZE);
600-
shell->line_curpos = shell->line_position = (rt_uint16_t)strlen(shell->line);
600+
shell->line_curpos = shell->line_position = (rt_uint16_t)rt_strlen(shell->line);
601601
shell_handle_history(shell);
602602
#endif
603603
continue;
@@ -619,7 +619,7 @@ static void finsh_thread_entry(void *parameter)
619619

620620
rt_memcpy(shell->line, &shell->cmd_history[shell->current_history][0],
621621
FINSH_CMD_SIZE);
622-
shell->line_curpos = shell->line_position = (rt_uint16_t)strlen(shell->line);
622+
shell->line_curpos = shell->line_position = (rt_uint16_t)rt_strlen(shell->line);
623623
shell_handle_history(shell);
624624
#endif
625625
continue;
@@ -758,7 +758,7 @@ static void finsh_thread_entry(void *parameter)
758758
/* auto complete */
759759
shell_auto_complete(&shell->line[0]);
760760
/* re-calculate position */
761-
shell->line_curpos = shell->line_position = (rt_uint16_t)strlen(shell->line);
761+
shell->line_curpos = shell->line_position = (rt_uint16_t)rt_strlen(shell->line);
762762

763763
continue;
764764
}

0 commit comments

Comments
 (0)