lic/libgen: Remove g_retchar from basename/dirname
to avoid the race condtion Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: If55fba8eca7b98d6a8f0fb44393cf4858b9e9ae4
This commit is contained in:
parent
eb403bc996
commit
5a6e08e281
@ -27,12 +27,6 @@
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static char g_retchar[2];
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -65,16 +59,14 @@ static char g_retchar[2];
|
||||
|
||||
FAR char *basename(FAR char *path)
|
||||
{
|
||||
char *p;
|
||||
int len;
|
||||
int ch;
|
||||
FAR char *p;
|
||||
int len;
|
||||
|
||||
/* Handle some corner cases */
|
||||
|
||||
if (!path || *path == '\0')
|
||||
{
|
||||
ch = '.';
|
||||
goto out_retchar;
|
||||
return ".";
|
||||
}
|
||||
|
||||
/* Check for trailing slash characters */
|
||||
@ -91,8 +83,7 @@ FAR char *basename(FAR char *path)
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = '/';
|
||||
goto out_retchar;
|
||||
return "/";
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,9 +100,4 @@ FAR char *basename(FAR char *path)
|
||||
/* There is no '/' in the path */
|
||||
|
||||
return path;
|
||||
|
||||
out_retchar:
|
||||
g_retchar[0] = ch;
|
||||
g_retchar[1] = '\0';
|
||||
return g_retchar;
|
||||
}
|
||||
|
@ -27,12 +27,6 @@
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static char g_retchar[2];
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -65,16 +59,14 @@ static char g_retchar[2];
|
||||
|
||||
FAR char *dirname(FAR char *path)
|
||||
{
|
||||
char *p;
|
||||
int len;
|
||||
int ch;
|
||||
FAR char *p;
|
||||
int len;
|
||||
|
||||
/* Handle some corner cases */
|
||||
|
||||
if (!path || *path == '\0')
|
||||
{
|
||||
ch = '.';
|
||||
goto out_retchar;
|
||||
return ".";
|
||||
}
|
||||
|
||||
/* Check for trailing slash characters */
|
||||
@ -91,8 +83,7 @@ FAR char *dirname(FAR char *path)
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = '/';
|
||||
goto out_retchar;
|
||||
return "/";
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,8 +100,7 @@ FAR char *dirname(FAR char *path)
|
||||
|
||||
if (p == path)
|
||||
{
|
||||
ch = '/';
|
||||
goto out_retchar;
|
||||
return "/";
|
||||
}
|
||||
|
||||
/* No, the directory component is the substring before the '/'. */
|
||||
@ -121,10 +111,5 @@ FAR char *dirname(FAR char *path)
|
||||
|
||||
/* There is no '/' in the path */
|
||||
|
||||
ch = '.';
|
||||
|
||||
out_retchar:
|
||||
g_retchar[0] = ch;
|
||||
g_retchar[1] = '\0';
|
||||
return g_retchar;
|
||||
return ".";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user