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:
Xiang Xiao
2021-06-23 02:00:20 +08:00
committed by Abdelatif Guettouche
parent eb403bc996
commit 5a6e08e281
2 changed files with 10 additions and 39 deletions
+4 -18
View File
@@ -27,12 +27,6 @@
#include <string.h> #include <string.h>
#include <libgen.h> #include <libgen.h>
/****************************************************************************
* Private Data
****************************************************************************/
static char g_retchar[2];
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@@ -65,16 +59,14 @@ static char g_retchar[2];
FAR char *basename(FAR char *path) FAR char *basename(FAR char *path)
{ {
char *p; FAR char *p;
int len; int len;
int ch;
/* Handle some corner cases */ /* Handle some corner cases */
if (!path || *path == '\0') if (!path || *path == '\0')
{ {
ch = '.'; return ".";
goto out_retchar;
} }
/* Check for trailing slash characters */ /* Check for trailing slash characters */
@@ -91,8 +83,7 @@ FAR char *basename(FAR char *path)
} }
else else
{ {
ch = '/'; return "/";
goto out_retchar;
} }
} }
@@ -109,9 +100,4 @@ FAR char *basename(FAR char *path)
/* There is no '/' in the path */ /* There is no '/' in the path */
return path; return path;
out_retchar:
g_retchar[0] = ch;
g_retchar[1] = '\0';
return g_retchar;
} }
+6 -21
View File
@@ -27,12 +27,6 @@
#include <string.h> #include <string.h>
#include <libgen.h> #include <libgen.h>
/****************************************************************************
* Private Data
****************************************************************************/
static char g_retchar[2];
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@@ -65,16 +59,14 @@ static char g_retchar[2];
FAR char *dirname(FAR char *path) FAR char *dirname(FAR char *path)
{ {
char *p; FAR char *p;
int len; int len;
int ch;
/* Handle some corner cases */ /* Handle some corner cases */
if (!path || *path == '\0') if (!path || *path == '\0')
{ {
ch = '.'; return ".";
goto out_retchar;
} }
/* Check for trailing slash characters */ /* Check for trailing slash characters */
@@ -91,8 +83,7 @@ FAR char *dirname(FAR char *path)
} }
else else
{ {
ch = '/'; return "/";
goto out_retchar;
} }
} }
@@ -109,8 +100,7 @@ FAR char *dirname(FAR char *path)
if (p == path) if (p == path)
{ {
ch = '/'; return "/";
goto out_retchar;
} }
/* No, the directory component is the substring before the '/'. */ /* 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 */ /* There is no '/' in the path */
ch = '.'; return ".";
out_retchar:
g_retchar[0] = ch;
g_retchar[1] = '\0';
return g_retchar;
} }