Fix error: conflicting types for built-in function 'execl'; expected 'int(const char *, const char *, ...)

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-03-18 15:10:04 +08:00 committed by Petro Karashchenko
parent 15960f25a5
commit eea014efb7
2 changed files with 37 additions and 47 deletions

View File

@ -367,7 +367,7 @@ int lchown(FAR const char *path, uid_t owner, gid_t group);
/* Execution of programs from files */
#ifdef CONFIG_LIBC_EXECFUNCS
int execl(FAR const char *path, ...);
int execl(FAR const char *path, FAR const char *arg0, ...);
int execv(FAR const char *path, FAR char * const argv[]);
#endif

View File

@ -113,10 +113,10 @@
*
****************************************************************************/
int execl(FAR const char *path, ...)
int execl(FAR const char *path, FAR const char *arg0, ...)
{
FAR char **argv = (FAR char **)NULL;
FAR char *arg;
FAR char **argv = NULL;
FAR char *arg = (FAR char *)arg0;
size_t nargs;
va_list ap;
int argc;
@ -124,14 +124,10 @@ int execl(FAR const char *path, ...)
/* Count the number of arguments */
va_start(ap, path);
va_start(ap, arg0);
nargs = 0;
do
{
/* Check if the next argument is present */
arg = va_arg(ap, FAR char *);
if (arg)
while (arg != NULL)
{
/* Yes.. increment the number of arguments. Here is a sanity
* check to prevent running away with an unterminated argv[] list.
@ -145,46 +141,40 @@ int execl(FAR const char *path, ...)
va_end(ap);
return ERROR;
}
arg = va_arg(ap, FAR char *);
}
}
while (arg);
va_end(ap);
/* Allocate a temporary argv[] array */
if (nargs > 0)
{
argv = (FAR char **)lib_malloc((nargs + 1) * sizeof(FAR char *));
if (argv == (FAR char **)NULL)
if (argv == NULL)
{
set_errno(ENOMEM);
return ERROR;
}
argv[0] = (FAR char *)arg0;
/* Collect the arguments into the argv[] array */
va_start(ap, path);
for (argc = 0; argc < nargs; argc++)
va_start(ap, arg0);
for (argc = 1; argc <= nargs; argc++)
{
argv[argc] = va_arg(ap, FAR char *);
}
argv[nargs] = NULL;
va_end(ap);
}
/* Then let execv() do the real work */
ret = execv(path, (FAR char * const *)argv);
ret = execv(path, argv);
/* Free the allocated argv[] list */
if (argv)
{
lib_free(argv);
}
return ret;
}