fix: 修复shell 模块存在大量的编译告警及codeCheck。
【背景】 代码中存在规范问题和编译告警。 如:error: unused variable 'taskID2' [-Werror=unused-variable] 应该去掉不用的变量。 【修改方案】 1. 修改变量类型宏的使用。 2. 根据告警信息修复问题代码。 【影响】 对现有的产品编译不会有影响。 re #I48V2J Change-Id: I7f364fcf974d2a439639f35ba428e04f7de7338a Signed-off-by: pef <cyd1997@126.com>
This commit is contained in:
parent
badf1e9557
commit
e0d8b5328f
|
@ -50,6 +50,8 @@ static_library("shell") {
|
||||||
"./include",
|
"./include",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
configs += [ "$LITEOSTOPDIR:los_config" ]
|
||||||
|
|
||||||
if (enable_ohos_kernel_liteos_m_lwip) {
|
if (enable_ohos_kernel_liteos_m_lwip) {
|
||||||
defines = [ "LWIP_SHELLCMD_ENABLE" ]
|
defines = [ "LWIP_SHELLCMD_ENABLE" ]
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ extern UINT32 OsCmdKeyShift(const CHAR *cmdKey, CHAR *cmdOut, UINT32 size);
|
||||||
extern UINT32 OsShellKeyInit(ShellCB *shellCB);
|
extern UINT32 OsShellKeyInit(ShellCB *shellCB);
|
||||||
extern VOID OsShellKeyDeInit(CmdKeyLink *cmdKeyLink);
|
extern VOID OsShellKeyDeInit(CmdKeyLink *cmdKeyLink);
|
||||||
extern UINT32 OsShellSysCmdRegister(VOID);
|
extern UINT32 OsShellSysCmdRegister(VOID);
|
||||||
extern int VfsNormalizePath(const char *directory, const char *filename, char **pathname);
|
extern INT32 VfsNormalizePath(const CHAR *directory, const CHAR *filename, CHAR **pathname);
|
||||||
extern INT32 OsShellCmdDate(INT32 argc, const CHAR **argv);
|
extern INT32 OsShellCmdDate(INT32 argc, const CHAR **argv);
|
||||||
extern INT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv);
|
extern INT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv);
|
||||||
extern UINT32 OsShellCmdFree(INT32 argc, const CHAR **argv);
|
extern UINT32 OsShellCmdFree(INT32 argc, const CHAR **argv);
|
||||||
|
@ -106,7 +106,7 @@ extern INT32 OsShellCmdRmdir(INT32 argc, const CHAR **argv);
|
||||||
extern INT32 OsShellCmdMkdir(INT32 argc, const CHAR **argv);
|
extern INT32 OsShellCmdMkdir(INT32 argc, const CHAR **argv);
|
||||||
extern INT32 OsShellCmdCp(INT32 argc, const CHAR **argv);
|
extern INT32 OsShellCmdCp(INT32 argc, const CHAR **argv);
|
||||||
extern INT32 OsShellCmdHelp(INT32 argc, const CHAR **argv);
|
extern INT32 OsShellCmdHelp(INT32 argc, const CHAR **argv);
|
||||||
|
extern UINT32 OsCmdInit(VOID);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
|
|
|
@ -42,7 +42,7 @@ extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
extern UINT32 ShellMsgTypeGet(CmdParsed *cmdParsed, const CHAR *cmdType);
|
extern UINT32 ShellMsgTypeGet(CmdParsed *cmdParsed, const CHAR *cmdType);
|
||||||
extern void ExecCmdline(const char *cmdline);
|
extern VOID ExecCmdline(const CHAR *cmdline);
|
||||||
|
|
||||||
#define SHELL_CMD_PARSE_EVENT 0x111
|
#define SHELL_CMD_PARSE_EVENT 0x111
|
||||||
|
|
||||||
|
|
|
@ -46,12 +46,12 @@ extern CHAR *OsShellGetWorkingDirtectory(VOID);
|
||||||
extern UINT32 OsShellInit(INT32 consoleId);
|
extern UINT32 OsShellInit(INT32 consoleId);
|
||||||
extern INT32 OsShellDeinit(INT32 consoleId);
|
extern INT32 OsShellDeinit(INT32 consoleId);
|
||||||
|
|
||||||
static inline void SetErrno(int errcode)
|
STATIC INLINE VOID SetErrno(INT32 errcode)
|
||||||
{
|
{
|
||||||
errno = errcode;
|
errno = errcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void SetErr(int errcode, const char *errMessage)
|
STATIC INLINE VOID SetErr(INT32 errcode, const CHAR *errMessage)
|
||||||
{
|
{
|
||||||
SetErrno(errcode);
|
SetErrno(errcode);
|
||||||
PRINTK(errMessage);
|
PRINTK(errMessage);
|
||||||
|
|
|
@ -330,14 +330,14 @@ ShellCB *OsGetShellCb(VOID)
|
||||||
return g_shellCB;
|
return g_shellCB;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *OsShellGetWorkingDirtectory(VOID)
|
CHAR *OsShellGetWorkingDirtectory(VOID)
|
||||||
{
|
{
|
||||||
return OsGetShellCb()->shellWorkingDirectory;
|
return OsGetShellCb()->shellWorkingDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID OsShellCBInit(VOID)
|
VOID OsShellCBInit(VOID)
|
||||||
{
|
{
|
||||||
int ret;
|
INT32 ret;
|
||||||
ShellCB *shellCB = NULL;
|
ShellCB *shellCB = NULL;
|
||||||
|
|
||||||
shellCB = (ShellCB *)malloc(sizeof(ShellCB));
|
shellCB = (ShellCB *)malloc(sizeof(ShellCB));
|
||||||
|
@ -349,17 +349,17 @@ VOID OsShellCBInit(VOID)
|
||||||
goto ERR_OUT1;
|
goto ERR_OUT1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = (int)OsShellKeyInit(shellCB);
|
ret = (INT32)OsShellKeyInit(shellCB);
|
||||||
if (ret != SH_OK) {
|
if (ret != SH_OK) {
|
||||||
goto ERR_OUT1;
|
goto ERR_OUT1;
|
||||||
}
|
}
|
||||||
(void)strncpy_s(shellCB->shellWorkingDirectory, PATH_MAX, "/", 2); /* 2:space for "/" */
|
(VOID)strncpy_s(shellCB->shellWorkingDirectory, PATH_MAX, "/", 2); /* 2:space for "/" */
|
||||||
|
|
||||||
g_shellCB = shellCB;
|
g_shellCB = shellCB;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ERR_OUT1:
|
ERR_OUT1:
|
||||||
(void)free(shellCB);
|
(VOID)free(shellCB);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,7 @@ END:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID ParseAndExecCmdline(CmdParsed *cmdParsed, const CHAR *cmdline, UINT32 len)
|
STATIC VOID ParseAndExecCmdline(CmdParsed *cmdParsed, const CHAR *cmdline, UINT32 len)
|
||||||
{
|
{
|
||||||
INT32 i;
|
INT32 i;
|
||||||
UINT32 ret;
|
UINT32 ret;
|
||||||
|
@ -259,7 +259,7 @@ VOID ShellTaskEntry(VOID)
|
||||||
LITE_OS_SEC_TEXT_MINOR UINT32 LosShellInit(VOID)
|
LITE_OS_SEC_TEXT_MINOR UINT32 LosShellInit(VOID)
|
||||||
{
|
{
|
||||||
UINT32 ret;
|
UINT32 ret;
|
||||||
UINT32 taskID1, taskID2;
|
UINT32 taskID1;
|
||||||
TSK_INIT_PARAM_S task1 = { 0 };
|
TSK_INIT_PARAM_S task1 = { 0 };
|
||||||
|
|
||||||
ret = LOS_EventInit(&g_shellInputEvent);
|
ret = LOS_EventInit(&g_shellInputEvent);
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <securec.h>
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
@ -39,9 +40,9 @@
|
||||||
|
|
||||||
#define TEMP_PATH_MAX (PATH_MAX + SHOW_MAX_LEN)
|
#define TEMP_PATH_MAX (PATH_MAX + SHOW_MAX_LEN)
|
||||||
|
|
||||||
static unsigned int VfsStrnlen(const char *str, size_t maxlen)
|
STATIC UINT32 VfsStrnlen(const CHAR *str, size_t maxlen)
|
||||||
{
|
{
|
||||||
const char *p = NULL;
|
const CHAR *p = NULL;
|
||||||
|
|
||||||
for (p = str; ((maxlen-- != 0) && (*p != '\0')); ++p) {}
|
for (p = str; ((maxlen-- != 0) && (*p != '\0')); ++p) {}
|
||||||
|
|
||||||
|
@ -49,10 +50,10 @@ static unsigned int VfsStrnlen(const char *str, size_t maxlen)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* abandon the redundant '/' in the path, only keep one. */
|
/* abandon the redundant '/' in the path, only keep one. */
|
||||||
static char *StrPath(char *path)
|
STATIC CHAR *StrPath(CHAR *path)
|
||||||
{
|
{
|
||||||
char *dest = path;
|
CHAR *dest = path;
|
||||||
char *src = path;
|
CHAR *src = path;
|
||||||
|
|
||||||
while (*src != '\0') {
|
while (*src != '\0') {
|
||||||
if (*src == '/') {
|
if (*src == '/') {
|
||||||
|
@ -68,7 +69,7 @@ static char *StrPath(char *path)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void StrRemovePathEndSlash(char *dest, const char *fullpath)
|
STATIC VOID StrRemovePathEndSlash(CHAR *dest, const CHAR *fullpath)
|
||||||
{
|
{
|
||||||
if ((*dest == '.') && (*(dest - 1) == '/')) {
|
if ((*dest == '.') && (*(dest - 1) == '/')) {
|
||||||
*dest = '\0';
|
*dest = '\0';
|
||||||
|
@ -79,10 +80,10 @@ static void StrRemovePathEndSlash(char *dest, const char *fullpath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *StrNormalizePath(char *fullpath)
|
STATIC CHAR *StrNormalizePath(CHAR *fullpath)
|
||||||
{
|
{
|
||||||
char *dest = fullpath;
|
CHAR *dest = fullpath;
|
||||||
char *src = fullpath;
|
CHAR *src = fullpath;
|
||||||
|
|
||||||
/* 2: The position of the path character: / and the end character /0 */
|
/* 2: The position of the path character: / and the end character /0 */
|
||||||
while (*src != '\0') {
|
while (*src != '\0') {
|
||||||
|
@ -131,10 +132,10 @@ static char *StrNormalizePath(char *fullpath)
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int VfsNormalizePathParameCheck(const char *filename, char **pathname)
|
STATIC INT32 VfsNormalizePathParameCheck(const CHAR *filename, CHAR **pathname)
|
||||||
{
|
{
|
||||||
int namelen;
|
INT32 namelen;
|
||||||
char *name = NULL;
|
CHAR *name = NULL;
|
||||||
|
|
||||||
if (pathname == NULL) {
|
if (pathname == NULL) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -156,7 +157,7 @@ static int VfsNormalizePathParameCheck(const char *filename, char **pathname)
|
||||||
return -ENAMETOOLONG;
|
return -ENAMETOOLONG;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (name = (char *)filename + namelen; ((name != filename) && (*name != '/')); name--) {
|
for (name = (CHAR *)filename + namelen; ((name != filename) && (*name != '/')); name--) {
|
||||||
if (strlen(name) > NAME_MAX) {
|
if (strlen(name) > NAME_MAX) {
|
||||||
*pathname = NULL;
|
*pathname = NULL;
|
||||||
return -ENAMETOOLONG;
|
return -ENAMETOOLONG;
|
||||||
|
@ -166,47 +167,47 @@ static int VfsNormalizePathParameCheck(const char *filename, char **pathname)
|
||||||
return namelen;
|
return namelen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *VfsNotAbsolutePath(const char *directory, const char *filename, char **pathname, int namelen)
|
STATIC CHAR *VfsNotAbsolutePath(const CHAR *directory, const CHAR *filename, CHAR **pathname, INT32 namelen)
|
||||||
{
|
{
|
||||||
int ret;
|
INT32 ret;
|
||||||
char *fullpath = NULL;
|
CHAR *fullpath = NULL;
|
||||||
|
|
||||||
/* 2: The position of the path character: / and the end character /0 */
|
/* 2: The position of the path character: / and the end character /0 */
|
||||||
|
|
||||||
if ((namelen > 1) && (filename[0] == '.') && (filename[1] == '/')) {
|
if ((namelen > 1) && (filename[0] == '.') && (filename[1] == '/')) {
|
||||||
filename += 2; /* 2, sizeof "./" */
|
filename += 2; /* 2, size of "./" */
|
||||||
}
|
}
|
||||||
|
|
||||||
fullpath = (char *)malloc(strlen(directory) + namelen + 2);
|
fullpath = (CHAR *)malloc(strlen(directory) + namelen + 2); /* 2, size of "./" */
|
||||||
if (fullpath == NULL) {
|
if (fullpath == NULL) {
|
||||||
*pathname = NULL;
|
*pathname = NULL;
|
||||||
SetErrno(ENOMEM);
|
SetErrno(ENOMEM);
|
||||||
return (char *)NULL;
|
return (CHAR *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 2, sizeof "./", join path and file name */
|
/* 2, size of "./", join path and file name */
|
||||||
ret = snprintf_s(fullpath, strlen(directory) + namelen + 2, strlen(directory) + namelen + 1,
|
ret = snprintf_s(fullpath, strlen(directory) + namelen + 2, strlen(directory) + namelen + 1,
|
||||||
"%s/%s", directory, filename);
|
"%s/%s", directory, filename);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
*pathname = NULL;
|
*pathname = NULL;
|
||||||
free(fullpath);
|
free(fullpath);
|
||||||
SetErrno(ENAMETOOLONG);
|
SetErrno(ENAMETOOLONG);
|
||||||
return (char *)NULL;
|
return (CHAR *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fullpath;
|
return fullpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *VfsNormalizeFullpath(const char *directory, const char *filename, char **pathname, int namelen)
|
STATIC CHAR *VfsNormalizeFullpath(const CHAR *directory, const CHAR *filename, CHAR **pathname, INT32 namelen)
|
||||||
{
|
{
|
||||||
char *fullpath = NULL;
|
CHAR *fullpath = NULL;
|
||||||
|
|
||||||
if (filename[0] != '/') {
|
if (filename[0] != '/') {
|
||||||
/* not a absolute path */
|
/* not a absolute path */
|
||||||
|
|
||||||
fullpath = VfsNotAbsolutePath(directory, filename, pathname, namelen);
|
fullpath = VfsNotAbsolutePath(directory, filename, pathname, namelen);
|
||||||
if (fullpath == NULL) {
|
if (fullpath == NULL) {
|
||||||
return (char *)NULL;
|
return (CHAR *)NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* it's a absolute path, use it directly */
|
/* it's a absolute path, use it directly */
|
||||||
|
@ -215,23 +216,23 @@ static char *VfsNormalizeFullpath(const char *directory, const char *filename, c
|
||||||
if (fullpath == NULL) {
|
if (fullpath == NULL) {
|
||||||
*pathname = NULL;
|
*pathname = NULL;
|
||||||
SetErrno(ENOMEM);
|
SetErrno(ENOMEM);
|
||||||
return (char *)NULL;
|
return (CHAR *)NULL;
|
||||||
}
|
}
|
||||||
if (filename[1] == '/') {
|
if (filename[1] == '/') {
|
||||||
*pathname = NULL;
|
*pathname = NULL;
|
||||||
free(fullpath);
|
free(fullpath);
|
||||||
SetErrno(EINVAL);
|
SetErrno(EINVAL);
|
||||||
return (char *)NULL;
|
return (CHAR *)NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fullpath;
|
return fullpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VfsNormalizePath(const char *directory, const char *filename, char **pathname)
|
INT32 VfsNormalizePath(const CHAR *directory, const CHAR *filename, CHAR **pathname)
|
||||||
{
|
{
|
||||||
char *fullpath = NULL;
|
CHAR *fullpath = NULL;
|
||||||
int namelen;
|
INT32 namelen;
|
||||||
|
|
||||||
namelen = VfsNormalizePathParameCheck(filename, pathname);
|
namelen = VfsNormalizePathParameCheck(filename, pathname);
|
||||||
if (namelen < 0) {
|
if (namelen < 0) {
|
||||||
|
@ -254,8 +255,8 @@ int VfsNormalizePath(const char *directory, const char *filename, char **pathnam
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)StrPath(fullpath);
|
(VOID)StrPath(fullpath);
|
||||||
(void)StrNormalizePath(fullpath);
|
(VOID)StrNormalizePath(fullpath);
|
||||||
if (strlen(fullpath) >= PATH_MAX) {
|
if (strlen(fullpath) >= PATH_MAX) {
|
||||||
*pathname = NULL;
|
*pathname = NULL;
|
||||||
free(fullpath);
|
free(fullpath);
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "shcmd.h"
|
#include "shcmd.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
|
#include "los_memory.h"
|
||||||
|
|
||||||
#define MEM_SIZE_1K 0x400
|
#define MEM_SIZE_1K 0x400
|
||||||
#define MEM_SIZE_1M 0x100000
|
#define MEM_SIZE_1M 0x100000
|
||||||
|
|
|
@ -67,13 +67,13 @@ typedef enum {
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
int OsShellCmdDoChdir(const char *path)
|
INT32 OsShellCmdDoChdir(const CHAR *path)
|
||||||
{
|
{
|
||||||
char *fullpath = NULL;
|
CHAR *fullpath = NULL;
|
||||||
char *fullpathBak = NULL;
|
CHAR *fullpathBak = NULL;
|
||||||
DIR *dirent = NULL;
|
DIR *dirent = NULL;
|
||||||
int ret;
|
INT32 ret;
|
||||||
char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
CHAR *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
||||||
if (shellWorkingDirectory == NULL) {
|
if (shellWorkingDirectory == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ int OsShellCmdDoChdir(const char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* close directory stream */
|
/* close directory stream */
|
||||||
(void)closedir(dirent);
|
(VOID)closedir(dirent);
|
||||||
|
|
||||||
/* copy full path to working directory */
|
/* copy full path to working directory */
|
||||||
LOS_TaskLock();
|
LOS_TaskLock();
|
||||||
|
@ -117,48 +117,50 @@ int OsShellCmdDoChdir(const char *path)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *OsLsGetFullpath(const char *path, struct dirent *pdirent)
|
STATIC CHAR *OsLsGetFullpath(const CHAR *path, struct dirent *pdirent)
|
||||||
{
|
{
|
||||||
char *fullpath = NULL;
|
CHAR *fullpath = NULL;
|
||||||
int ret;
|
INT32 ret;
|
||||||
|
size_t pathLen;
|
||||||
|
|
||||||
if (path[1] != '\0') {
|
if (path[1] != '\0') {
|
||||||
fullpath = (char *)malloc(strlen(path) + strlen(pdirent->d_name) + 2);
|
pathLen = strlen(path) + strlen(pdirent->d_name) + 2; /* 2, path + '/' + d_name + '\0' */
|
||||||
|
fullpath = (CHAR *)malloc(pathLen);
|
||||||
if (fullpath == NULL) {
|
if (fullpath == NULL) {
|
||||||
goto exit_with_nomem;
|
goto exit_with_nomem;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = snprintf_s(fullpath, strlen(path) + strlen(pdirent->d_name) + 2,
|
ret = snprintf_s(fullpath, pathLen, pathLen, "%s/%s", path, pdirent->d_name);
|
||||||
strlen(path) + strlen(pdirent->d_name) + 1, "%s/%s", path, pdirent->d_name);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
free(fullpath);
|
free(fullpath);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fullpath = (char *)malloc(strlen(pdirent->d_name) + 2);
|
pathLen = strlen(pdirent->d_name) + 2; /* 2, '/' + d_name + '\0' */
|
||||||
|
fullpath = (CHAR *)malloc(pathLen);
|
||||||
if (fullpath == NULL) {
|
if (fullpath == NULL) {
|
||||||
goto exit_with_nomem;
|
goto exit_with_nomem;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = snprintf_s(fullpath, strlen(pdirent->d_name) + 2, strlen(pdirent->d_name) + 1,
|
ret = snprintf_s(fullpath, pathLen, pathLen, "/%s", pdirent->d_name);
|
||||||
"/%s", pdirent->d_name);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
free(fullpath);
|
free(fullpath);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fullpath;
|
|
||||||
|
return fullpath;
|
||||||
exit_with_nomem:
|
exit_with_nomem:
|
||||||
return (char *)NULL;
|
return (CHAR *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OsLs(const char *pathname)
|
VOID OsLs(const CHAR *pathname)
|
||||||
{
|
{
|
||||||
struct dirent *pdirent = NULL;
|
struct dirent *pdirent = NULL;
|
||||||
char *path = NULL;
|
CHAR *path = NULL;
|
||||||
char *fullpath = NULL;
|
CHAR *fullpath = NULL;
|
||||||
char *fullpathBak = NULL;
|
CHAR *fullpathBak = NULL;
|
||||||
int ret;
|
INT32 ret;
|
||||||
struct stat statInfo = { 0 };
|
struct stat statInfo = { 0 };
|
||||||
DIR *d = NULL;
|
DIR *d = NULL;
|
||||||
|
|
||||||
|
@ -184,11 +186,11 @@ void OsLs(const char *pathname)
|
||||||
do {
|
do {
|
||||||
pdirent = readdir(d);
|
pdirent = readdir(d);
|
||||||
if (pdirent != NULL) {
|
if (pdirent != NULL) {
|
||||||
(void)memset_s(&statInfo, sizeof(struct stat), 0, sizeof(struct stat));
|
(VOID)memset_s(&statInfo, sizeof(struct stat), 0, sizeof(struct stat));
|
||||||
fullpath = OsLsGetFullpath(path, pdirent);
|
fullpath = OsLsGetFullpath(path, pdirent);
|
||||||
if (fullpath == NULL) {
|
if (fullpath == NULL) {
|
||||||
free(path);
|
free(path);
|
||||||
(void)closedir(d);
|
(VOID)closedir(d);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,16 +209,16 @@ void OsLs(const char *pathname)
|
||||||
}
|
}
|
||||||
} while (pdirent != NULL);
|
} while (pdirent != NULL);
|
||||||
|
|
||||||
(void)closedir(d);
|
(VOID)closedir(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int OsShellCmdLs(int argc, const char **argv)
|
INT32 OsShellCmdLs(INT32 argc, const CHAR **argv)
|
||||||
{
|
{
|
||||||
char *fullpath = NULL;
|
CHAR *fullpath = NULL;
|
||||||
const char *filename = NULL;
|
const CHAR *filename = NULL;
|
||||||
int ret;
|
INT32 ret;
|
||||||
char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
CHAR *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
||||||
if (shellWorkingDirectory == NULL) {
|
if (shellWorkingDirectory == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -238,10 +240,10 @@ int OsShellCmdLs(int argc, const char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OsShellCmdCd(int argc, const char **argv)
|
INT32 OsShellCmdCd(INT32 argc, const CHAR **argv)
|
||||||
{
|
{
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
(void)OsShellCmdDoChdir("/");
|
(VOID)OsShellCmdDoChdir("/");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,14 +256,14 @@ int OsShellCmdCd(int argc, const char **argv)
|
||||||
#define CAT_TASK_STACK_SIZE 0x3000
|
#define CAT_TASK_STACK_SIZE 0x3000
|
||||||
pthread_mutex_t g_mutex_cat = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t g_mutex_cat = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
int OsShellCmdCat(int argc, const char **argv)
|
INT32 OsShellCmdCat(INT32 argc, const CHAR **argv)
|
||||||
{
|
{
|
||||||
char *fullpath = NULL;
|
CHAR *fullpath = NULL;
|
||||||
int ret;
|
INT32 ret;
|
||||||
CHAR buf[CAT_BUF_SIZE];
|
CHAR buf[CAT_BUF_SIZE];
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
CHAR *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
||||||
|
|
||||||
if (shellWorkingDirectory == NULL) {
|
if (shellWorkingDirectory == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -272,7 +274,7 @@ int OsShellCmdCat(int argc, const char **argv)
|
||||||
ret = VfsNormalizePath(shellWorkingDirectory, argv[0], &fullpath);
|
ret = VfsNormalizePath(shellWorkingDirectory, argv[0], &fullpath);
|
||||||
ERROR_OUT_IF(ret < 0, SetErr(-ret, "cat error"), return -1);
|
ERROR_OUT_IF(ret < 0, SetErr(-ret, "cat error"), return -1);
|
||||||
|
|
||||||
int fd = open(fullpath, O_RDONLY, 0666);
|
INT32 fd = open(fullpath, O_RDONLY, 0666);
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
@ -280,15 +282,15 @@ int OsShellCmdCat(int argc, const char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
(void)memset_s(buf, sizeof(buf), 0, CAT_BUF_SIZE);
|
(VOID)memset_s(buf, sizeof(buf), 0, CAT_BUF_SIZE);
|
||||||
size = read(fd, buf, CAT_BUF_SIZE - 1);
|
size = read(fd, buf, CAT_BUF_SIZE - 1);
|
||||||
if ((int)size < 0) {
|
if ((INT32)size < 0) {
|
||||||
free(fullpath);
|
free(fullpath);
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
PRINTK("%s", buf);
|
PRINTK("%s", buf);
|
||||||
(void)LOS_TaskDelay(1);
|
(VOID)LOS_TaskDelay(1);
|
||||||
} while (size == CAT_BUF_SIZE);
|
} while (size == CAT_BUF_SIZE);
|
||||||
|
|
||||||
free(fullpath);
|
free(fullpath);
|
||||||
|
@ -297,12 +299,12 @@ int OsShellCmdCat(int argc, const char **argv)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OsShellCmdMkdir(int argc, const char **argv)
|
INT32 OsShellCmdMkdir(INT32 argc, const CHAR **argv)
|
||||||
{
|
{
|
||||||
int ret;
|
INT32 ret;
|
||||||
char *fullpath = NULL;
|
CHAR *fullpath = NULL;
|
||||||
const char *filename = NULL;
|
const CHAR *filename = NULL;
|
||||||
char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
CHAR *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
||||||
if (shellWorkingDirectory == NULL) {
|
if (shellWorkingDirectory == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -321,11 +323,10 @@ int OsShellCmdMkdir(int argc, const char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OsShellCmdPwd(int argc, const char **argv)
|
INT32 OsShellCmdPwd(INT32 argc, const CHAR **argv)
|
||||||
{
|
{
|
||||||
char buf[SHOW_MAX_LEN] = {0};
|
CHAR buf[SHOW_MAX_LEN] = {0};
|
||||||
DIR *dir = NULL;
|
CHAR *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
||||||
char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
|
||||||
if (shellWorkingDirectory == NULL) {
|
if (shellWorkingDirectory == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -344,13 +345,13 @@ int OsShellCmdPwd(int argc, const char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OsShellCmdTouch(int argc, const char **argv)
|
INT32 OsShellCmdTouch(INT32 argc, const CHAR **argv)
|
||||||
{
|
{
|
||||||
int ret;
|
INT32 ret;
|
||||||
int fd = -1;
|
INT32 fd = -1;
|
||||||
char *fullpath = NULL;
|
CHAR *fullpath = NULL;
|
||||||
const char *filename = NULL;
|
const CHAR *filename = NULL;
|
||||||
char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
CHAR *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
||||||
if (shellWorkingDirectory == NULL) {
|
if (shellWorkingDirectory == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -368,33 +369,33 @@ int OsShellCmdTouch(int argc, const char **argv)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)close(fd);
|
(VOID)close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CP_BUF_SIZE 4096
|
#define CP_BUF_SIZE 4096
|
||||||
pthread_mutex_t g_mutexCp = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t g_mutexCp = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static int OsShellCmdDoCp(const char *srcFilePath, const char *dstFileName)
|
STATIC INT32 OsShellCmdDoCp(const CHAR *srcFilePath, const CHAR *dstFileName)
|
||||||
{
|
{
|
||||||
int ret;
|
INT32 ret;
|
||||||
char *srcFullPath = NULL;
|
CHAR *srcFullPath = NULL;
|
||||||
char *drcFullPath = NULL;
|
CHAR *drcFullPath = NULL;
|
||||||
const char *srcFileName = NULL;
|
const CHAR *srcFileName = NULL;
|
||||||
char *dstFilePath = NULL;
|
CHAR *dstFilePath = NULL;
|
||||||
char *buf = NULL;
|
CHAR *buf = NULL;
|
||||||
const char *filename = NULL;
|
const CHAR *filename = NULL;
|
||||||
size_t rdSize, wrSize;
|
size_t rdSize, wrSize;
|
||||||
int srcFd = -1;
|
INT32 srcFd = -1;
|
||||||
int dstFd = -1;
|
INT32 dstFd = -1;
|
||||||
struct stat statBuf;
|
struct stat statBuf;
|
||||||
mode_t srcMode;
|
mode_t srcMode;
|
||||||
char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
CHAR *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
||||||
if (shellWorkingDirectory == NULL) {
|
if (shellWorkingDirectory == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = (char *)malloc(CP_BUF_SIZE);
|
buf = (CHAR *)malloc(CP_BUF_SIZE);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
PRINTK("cp error: Out of memory!\n");
|
PRINTK("cp error: Out of memory!\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -461,7 +462,7 @@ static int OsShellCmdDoCp(const char *srcFilePath, const char *dstFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy begins. */
|
/* Copy begins. */
|
||||||
(void)pthread_mutex_lock(&g_mutexCp);
|
(VOID)pthread_mutex_lock(&g_mutexCp);
|
||||||
srcFd = open(srcFullPath, O_RDONLY);
|
srcFd = open(srcFullPath, O_RDONLY);
|
||||||
if (srcFd < 0) {
|
if (srcFd < 0) {
|
||||||
PRINTK("cp error: can't open %s. %s.\n", srcFullPath, strerror(errno));
|
PRINTK("cp error: can't open %s. %s.\n", srcFullPath, strerror(errno));
|
||||||
|
@ -475,7 +476,7 @@ static int OsShellCmdDoCp(const char *srcFilePath, const char *dstFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
(void)memset_s(buf, CP_BUF_SIZE, 0, CP_BUF_SIZE);
|
(VOID)memset_s(buf, CP_BUF_SIZE, 0, CP_BUF_SIZE);
|
||||||
rdSize = read(srcFd, buf, CP_BUF_SIZE);
|
rdSize = read(srcFd, buf, CP_BUF_SIZE);
|
||||||
if (rdSize < 0) {
|
if (rdSize < 0) {
|
||||||
PRINTK("cp %s %s failed. %s.\n", srcFullPath, drcFullPath, strerror(errno));
|
PRINTK("cp %s %s failed. %s.\n", srcFullPath, drcFullPath, strerror(errno));
|
||||||
|
@ -492,17 +493,17 @@ static int OsShellCmdDoCp(const char *srcFilePath, const char *dstFileName)
|
||||||
free(buf);
|
free(buf);
|
||||||
free(srcFullPath);
|
free(srcFullPath);
|
||||||
free(drcFullPath);
|
free(drcFullPath);
|
||||||
(void)close(srcFd);
|
(VOID)close(srcFd);
|
||||||
(void)close(dstFd);
|
(VOID)close(dstFd);
|
||||||
(void)pthread_mutex_unlock(&g_mutexCp);
|
(VOID)pthread_mutex_unlock(&g_mutexCp);
|
||||||
return LOS_OK;
|
return LOS_OK;
|
||||||
|
|
||||||
errout_with_fd:
|
errout_with_fd:
|
||||||
(void)close(dstFd);
|
(VOID)close(dstFd);
|
||||||
errout_with_srcfd:
|
errout_with_srcfd:
|
||||||
(void)close(srcFd);
|
(VOID)close(srcFd);
|
||||||
errout_with_mutex:
|
errout_with_mutex:
|
||||||
(void)pthread_mutex_unlock(&g_mutexCp);
|
(VOID)pthread_mutex_unlock(&g_mutexCp);
|
||||||
errout_with_path:
|
errout_with_path:
|
||||||
free(drcFullPath);
|
free(drcFullPath);
|
||||||
errout_with_srcpath:
|
errout_with_srcpath:
|
||||||
|
@ -514,15 +515,15 @@ errout_with_srcpath:
|
||||||
/* The separator and EOF for a directory fullpath: '/'and '\0' */
|
/* The separator and EOF for a directory fullpath: '/'and '\0' */
|
||||||
#define SEPARATOR_EOF_LEN 2
|
#define SEPARATOR_EOF_LEN 2
|
||||||
|
|
||||||
static int OsShellCmdDoRmdir(const char *pathname)
|
STATIC INT32 OsShellCmdDoRmdir(const CHAR *pathname)
|
||||||
{
|
{
|
||||||
struct dirent *dirent = NULL;
|
struct dirent *dirent = NULL;
|
||||||
struct stat statInfo;
|
struct stat statInfo;
|
||||||
DIR *d = NULL;
|
DIR *d = NULL;
|
||||||
char *fullpath = NULL;
|
CHAR *fullpath = NULL;
|
||||||
int ret;
|
INT32 ret;
|
||||||
|
|
||||||
(void)memset_s(&statInfo, sizeof(statInfo), 0, sizeof(struct stat));
|
(VOID)memset_s(&statInfo, sizeof(statInfo), 0, sizeof(struct stat));
|
||||||
if (stat(pathname, &statInfo) != 0) {
|
if (stat(pathname, &statInfo) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -543,34 +544,34 @@ static int OsShellCmdDoRmdir(const char *pathname)
|
||||||
size_t fullPathBufSize = strlen(pathname) + strlen(dirent->d_name) + SEPARATOR_EOF_LEN;
|
size_t fullPathBufSize = strlen(pathname) + strlen(dirent->d_name) + SEPARATOR_EOF_LEN;
|
||||||
if (fullPathBufSize <= 0) {
|
if (fullPathBufSize <= 0) {
|
||||||
PRINTK("buffer size is invalid!\n");
|
PRINTK("buffer size is invalid!\n");
|
||||||
(void)closedir(d);
|
(VOID)closedir(d);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fullpath = (char *)malloc(fullPathBufSize);
|
fullpath = (CHAR *)malloc(fullPathBufSize);
|
||||||
if (fullpath == NULL) {
|
if (fullpath == NULL) {
|
||||||
PRINTK("malloc failure!\n");
|
PRINTK("malloc failure!\n");
|
||||||
(void)closedir(d);
|
(VOID)closedir(d);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = snprintf_s(fullpath, fullPathBufSize, fullPathBufSize - 1, "%s/%s", pathname, dirent->d_name);
|
ret = snprintf_s(fullpath, fullPathBufSize, fullPathBufSize - 1, "%s/%s", pathname, dirent->d_name);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
PRINTK("name is too long!\n");
|
PRINTK("name is too long!\n");
|
||||||
free(fullpath);
|
free(fullpath);
|
||||||
(void)closedir(d);
|
(VOID)closedir(d);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
(void)OsShellCmdDoRmdir(fullpath);
|
(VOID)OsShellCmdDoRmdir(fullpath);
|
||||||
free(fullpath);
|
free(fullpath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(void)closedir(d);
|
(VOID)closedir(d);
|
||||||
return rmdir(pathname);
|
return rmdir(pathname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wildcard matching operations */
|
/* Wildcard matching operations */
|
||||||
static int OsWildcardMatch(const char *src, const char *filename)
|
STATIC INT32 OsWildcardMatch(const CHAR *src, const CHAR *filename)
|
||||||
{
|
{
|
||||||
int ret;
|
INT32 ret;
|
||||||
|
|
||||||
if (*src != '\0') {
|
if (*src != '\0') {
|
||||||
if (*filename == '*') {
|
if (*filename == '*') {
|
||||||
|
@ -616,7 +617,7 @@ static int OsWildcardMatch(const char *src, const char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* To determine whether a wildcard character exists in a path */
|
/* To determine whether a wildcard character exists in a path */
|
||||||
static int OsIsContainersWildcard(const char *filename)
|
STATIC INT32 OsIsContainersWildcard(const CHAR *filename)
|
||||||
{
|
{
|
||||||
while (*filename != '\0') {
|
while (*filename != '\0') {
|
||||||
if ((*filename == '*') || (*filename == '?')) {
|
if ((*filename == '*') || (*filename == '?')) {
|
||||||
|
@ -629,9 +630,9 @@ static int OsIsContainersWildcard(const char *filename)
|
||||||
|
|
||||||
/* Delete a matching file or directory */
|
/* Delete a matching file or directory */
|
||||||
|
|
||||||
static int OsWildcardDeleteFileOrDir(const char *fullpath, wildcard_type mark)
|
STATIC INT32 OsWildcardDeleteFileOrDir(const CHAR *fullpath, wildcard_type mark)
|
||||||
{
|
{
|
||||||
int ret;
|
INT32 ret;
|
||||||
|
|
||||||
switch (mark) {
|
switch (mark) {
|
||||||
case RM_RECURSIVER:
|
case RM_RECURSIVER:
|
||||||
|
@ -658,12 +659,12 @@ static int OsWildcardDeleteFileOrDir(const char *fullpath, wildcard_type mark)
|
||||||
|
|
||||||
/* Split the path with wildcard characters */
|
/* Split the path with wildcard characters */
|
||||||
|
|
||||||
static char* OsWildcardSplitPath(char *fullpath, char **handle, char **wait)
|
STATIC CHAR *OsWildcardSplitPath(CHAR *fullpath, CHAR **handle, CHAR **wait)
|
||||||
{
|
{
|
||||||
int n;
|
INT32 n;
|
||||||
int a = 0;
|
INT32 a = 0;
|
||||||
int b = 0;
|
INT32 b = 0;
|
||||||
int len = strlen(fullpath);
|
INT32 len = strlen(fullpath);
|
||||||
|
|
||||||
for (n = 0; n < len; n++) {
|
for (n = 0; n < len; n++) {
|
||||||
if (fullpath[n] == '/') {
|
if (fullpath[n] == '/') {
|
||||||
|
@ -688,18 +689,18 @@ static char* OsWildcardSplitPath(char *fullpath, char **handle, char **wait)
|
||||||
|
|
||||||
/* Handling entry of the path with wildcard characters */
|
/* Handling entry of the path with wildcard characters */
|
||||||
|
|
||||||
static int OsWildcardExtractDirectory(char *fullpath, void *dst, wildcard_type mark)
|
STATIC INT32 OsWildcardExtractDirectory(CHAR *fullpath, VOID *dst, wildcard_type mark)
|
||||||
{
|
{
|
||||||
char separator[] = "/";
|
CHAR separator[] = "/";
|
||||||
char src[PATH_MAX] = {0};
|
CHAR src[PATH_MAX] = {0};
|
||||||
struct dirent *dirent = NULL;
|
struct dirent *dirent = NULL;
|
||||||
char *f = NULL;
|
CHAR *f = NULL;
|
||||||
char *s = NULL;
|
CHAR *s = NULL;
|
||||||
char *t = NULL;
|
CHAR *t = NULL;
|
||||||
int ret = 0;
|
INT32 ret = 0;
|
||||||
DIR *d = NULL;
|
DIR *d = NULL;
|
||||||
struct stat statBuf;
|
struct stat statBuf;
|
||||||
int deleteFlag = 0;
|
INT32 deleteFlag = 0;
|
||||||
|
|
||||||
f = OsWildcardSplitPath(fullpath, &s, &t);
|
f = OsWildcardSplitPath(fullpath, &s, &t);
|
||||||
|
|
||||||
|
@ -709,7 +710,7 @@ static int OsWildcardExtractDirectory(char *fullpath, void *dst, wildcard_type m
|
||||||
} else if (mark == CP_COUNT) {
|
} else if (mark == CP_COUNT) {
|
||||||
ret = stat(fullpath, &statBuf);
|
ret = stat(fullpath, &statBuf);
|
||||||
if (ret == 0 && (S_ISREG(statBuf.st_mode) || S_ISLNK(statBuf.st_mode))) {
|
if (ret == 0 && (S_ISREG(statBuf.st_mode) || S_ISLNK(statBuf.st_mode))) {
|
||||||
(*(int *)dst)++;
|
(*(INT32 *)dst)++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ret = OsWildcardDeleteFileOrDir(fullpath, mark);
|
ret = OsWildcardDeleteFileOrDir(fullpath, mark);
|
||||||
|
@ -751,8 +752,8 @@ static int OsWildcardExtractDirectory(char *fullpath, void *dst, wildcard_type m
|
||||||
} else if (mark == CP_COUNT) {
|
} else if (mark == CP_COUNT) {
|
||||||
ret = stat(src, &statBuf);
|
ret = stat(src, &statBuf);
|
||||||
if (ret == 0 && (S_ISREG(statBuf.st_mode) || S_ISLNK(statBuf.st_mode))) {
|
if (ret == 0 && (S_ISREG(statBuf.st_mode) || S_ISLNK(statBuf.st_mode))) {
|
||||||
(*(int *)dst)++;
|
(*(INT32 *)dst)++;
|
||||||
if ((*(int *)dst) > 1) {
|
if ((*(INT32 *)dst) > 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -772,32 +773,32 @@ static int OsWildcardExtractDirectory(char *fullpath, void *dst, wildcard_type m
|
||||||
goto closedir_out;
|
goto closedir_out;
|
||||||
}
|
}
|
||||||
ret = OsWildcardExtractDirectory(src, dst, mark);
|
ret = OsWildcardExtractDirectory(src, dst, mark);
|
||||||
if (mark == CP_COUNT && (*(int *)dst) > 1) {
|
if (mark == CP_COUNT && (*(INT32 *)dst) > 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(void)closedir(d);
|
(VOID)closedir(d);
|
||||||
if (deleteFlag == 1) {
|
if (deleteFlag == 1) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
closedir_out:
|
closedir_out:
|
||||||
(void)closedir(d);
|
(VOID)closedir(d);
|
||||||
return VFS_ERROR;
|
return VFS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OsShellCmdCp(int argc, const char **argv)
|
INT32 OsShellCmdCp(INT32 argc, const CHAR **argv)
|
||||||
{
|
{
|
||||||
int ret;
|
INT32 ret;
|
||||||
const char *src = NULL;
|
const CHAR *src = NULL;
|
||||||
const char *dst = NULL;
|
const CHAR *dst = NULL;
|
||||||
char *srcFullPath = NULL;
|
CHAR *srcFullPath = NULL;
|
||||||
char *drcFullPath = NULL;
|
CHAR *drcFullPath = NULL;
|
||||||
struct stat statBuf;
|
struct stat statBuf;
|
||||||
int count = 0;
|
INT32 count = 0;
|
||||||
char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
CHAR *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
||||||
if (shellWorkingDirectory == NULL) {
|
if (shellWorkingDirectory == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -847,12 +848,12 @@ int OsShellCmdCp(int argc, const char **argv)
|
||||||
|
|
||||||
if (OsIsContainersWildcard(srcFullPath)) {
|
if (OsIsContainersWildcard(srcFullPath)) {
|
||||||
if (ret < 0 || S_ISREG(statBuf.st_mode) || S_ISLNK(statBuf.st_mode)) {
|
if (ret < 0 || S_ISREG(statBuf.st_mode) || S_ISLNK(statBuf.st_mode)) {
|
||||||
char *srcCopy = strdup(srcFullPath);
|
CHAR *srcCopy = strdup(srcFullPath);
|
||||||
if (srcCopy == NULL) {
|
if (srcCopy == NULL) {
|
||||||
PRINTK("cp error : Out of memory.\n");
|
PRINTK("cp error : Out of memory.\n");
|
||||||
goto errout_with_path;
|
goto errout_with_path;
|
||||||
}
|
}
|
||||||
(void)OsWildcardExtractDirectory(srcCopy, &count, CP_COUNT);
|
(VOID)OsWildcardExtractDirectory(srcCopy, &count, CP_COUNT);
|
||||||
free(srcCopy);
|
free(srcCopy);
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
PRINTK("cp error : %s is not a directory.\n", drcFullPath);
|
PRINTK("cp error : %s is not a directory.\n", drcFullPath);
|
||||||
|
@ -874,17 +875,17 @@ errout_with_srcpath:
|
||||||
return VFS_ERROR;
|
return VFS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void PrintRmUsage(void)
|
STATIC INLINE VOID PrintRmUsage(VOID)
|
||||||
{
|
{
|
||||||
PRINTK("rm [FILE] or rm [-r/-R] [FILE]\n");
|
PRINTK("rm [FILE] or rm [-r/-R] [FILE]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int OsShellCmdRm(int argc, const char **argv)
|
INT32 OsShellCmdRm(INT32 argc, const CHAR **argv)
|
||||||
{
|
{
|
||||||
int ret;
|
INT32 ret;
|
||||||
char *fullpath = NULL;
|
CHAR *fullpath = NULL;
|
||||||
const char *filename = NULL;
|
const CHAR *filename = NULL;
|
||||||
char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
CHAR *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
||||||
|
|
||||||
if (shellWorkingDirectory == NULL) {
|
if (shellWorkingDirectory == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -922,12 +923,12 @@ int OsShellCmdRm(int argc, const char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OsShellCmdRmdir(int argc, const char **argv)
|
INT32 OsShellCmdRmdir(INT32 argc, const CHAR **argv)
|
||||||
{
|
{
|
||||||
int ret;
|
INT32 ret;
|
||||||
char *fullpath = NULL;
|
CHAR *fullpath = NULL;
|
||||||
const char *filename = NULL;
|
const CHAR *filename = NULL;
|
||||||
char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
CHAR *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
||||||
if (shellWorkingDirectory == NULL) {
|
if (shellWorkingDirectory == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue