Skip to content

Commit 88a3064

Browse files
committed
libutil/fname: optimize the way to detect . and ..
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 0e75950 commit 88a3064

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

main/fname.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,26 @@ static char *fsimplify_abs0 (char *fname, struct comp *parent)
151151
return fsimplify_abs0 (next + 1, &comp);
152152
}
153153

154+
static bool is_special_link(const char *name)
155+
{
156+
/* strcmp (comp.str, "..") || !strcmp (comp.str, ".") */
157+
if (name [0] != '.')
158+
return false;
159+
if (name [1] == '\0')
160+
return true;
161+
if (name [1] != '.')
162+
return false;
163+
if (name [2] == '\0')
164+
return true;
165+
return false;
166+
}
167+
154168
extern char *canonicalizeAbsoluteFileName (char *fname)
155169
{
156170
char *next = strchr (fname, '/');
157171
if (next == NULL)
158172
{
159-
if (!strcmp (fname, "..") || !strcmp (fname, "."))
173+
if (is_special_link(fname))
160174
{
161175
fname [0] = '/';
162176
fname [1] = '\0';
@@ -175,7 +189,7 @@ extern char *canonicalizeAbsoluteFileName (char *fname)
175189
.parent = NULL,
176190
.child = NULL
177191
};
178-
if (!strcmp (comp.str, "..") || !strcmp (comp.str, "."))
192+
if (is_special_link (comp.str))
179193
{
180194
comp.str[0] = '\0';
181195
comp.len = 0;

0 commit comments

Comments
 (0)