Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
67ae033d
Commit
67ae033d
authored
Oct 17, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ArchiveLookup: in-place editing, avoid string copy
parent
161f7ced
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
29 deletions
+24
-29
ArchiveLookup.cxx
src/ArchiveLookup.cxx
+24
-29
No files found.
src/ArchiveLookup.cxx
View file @
67ae033d
...
...
@@ -22,8 +22,6 @@
#include "ArchiveDomain.hxx"
#include "Log.hxx"
#include <glib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
...
...
@@ -42,11 +40,11 @@ FindSlash(char *p, size_t i)
gcc_pure
static
const
char
*
FindSuffix
(
const
char
*
p
,
size_t
i
)
FindSuffix
(
const
char
*
p
,
const
char
*
i
)
{
for
(;
i
>
0
;
--
i
)
{
if
(
p
[
i
]
==
'.'
)
return
p
+
i
+
1
;
for
(;
i
>
p
;
--
i
)
{
if
(
*
i
==
'.'
)
return
i
+
1
;
}
return
nullptr
;
...
...
@@ -56,54 +54,51 @@ bool
archive_lookup
(
char
*
pathname
,
const
char
**
archive
,
const
char
**
inpath
,
const
char
**
suffix
)
{
bool
ret
=
false
;
size_t
idx
=
strlen
(
pathname
)
;
char
*
const
pathdupe
=
g_strdup
(
pathname
);
const
size_t
len
=
strlen
(
pathname
);
size_t
idx
=
len
;
char
*
slash
=
nullptr
;
while
(
idx
>
0
)
{
while
(
true
)
{
//try to stat if its real directory
struct
stat
st_info
;
if
(
stat
(
path
dup
e
,
&
st_info
)
==
-
1
)
{
if
(
stat
(
path
nam
e
,
&
st_info
)
==
-
1
)
{
if
(
errno
!=
ENOTDIR
)
{
FormatErrno
(
archive_domain
,
"Failed to stat %s"
,
path
dup
e
);
break
;
"Failed to stat %s"
,
path
nam
e
);
return
false
;
}
}
else
{
//is something found ins original path (is not an archive)
if
(
idx
==
len
)
{
break
;
}
if
(
slash
==
nullptr
)
return
false
;
//its a file ?
if
(
S_ISREG
(
st_info
.
st_mode
))
{
//so the upper should be file
pathname
[
idx
]
=
0
;
ret
=
true
;
*
archive
=
pathname
;
*
inpath
=
pathname
+
idx
+
1
;
*
inpath
=
slash
+
1
;
//try to get suffix
*
suffix
=
FindSuffix
(
pathname
,
idx
);
break
;
*
suffix
=
FindSuffix
(
pathname
,
slash
-
1
);
return
true
;
}
else
{
FormatError
(
archive_domain
,
"Not a regular file: %s"
,
path
dup
e
);
break
;
path
nam
e
);
return
false
;
}
}
//find one dir up
char
*
slash
=
FindSlash
(
pathdupe
,
idx
);
if
(
slash
!=
nullptr
)
*
slash
=
'/'
;
slash
=
FindSlash
(
pathname
,
idx
-
1
);
if
(
slash
==
nullptr
)
break
;
return
false
;
*
slash
=
0
;
idx
=
slash
-
path
dup
e
;
idx
=
slash
-
path
nam
e
;
}
g_free
(
pathdupe
);
return
ret
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment