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 @@
...
@@ -22,8 +22,6 @@
#include "ArchiveDomain.hxx"
#include "ArchiveDomain.hxx"
#include "Log.hxx"
#include "Log.hxx"
#include <glib.h>
#include <string.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <unistd.h>
#include <unistd.h>
...
@@ -42,11 +40,11 @@ FindSlash(char *p, size_t i)
...
@@ -42,11 +40,11 @@ FindSlash(char *p, size_t i)
gcc_pure
gcc_pure
static
const
char
*
static
const
char
*
FindSuffix
(
const
char
*
p
,
size_t
i
)
FindSuffix
(
const
char
*
p
,
const
char
*
i
)
{
{
for
(;
i
>
0
;
--
i
)
{
for
(;
i
>
p
;
--
i
)
{
if
(
p
[
i
]
==
'.'
)
if
(
*
i
==
'.'
)
return
p
+
i
+
1
;
return
i
+
1
;
}
}
return
nullptr
;
return
nullptr
;
...
@@ -56,54 +54,51 @@ bool
...
@@ -56,54 +54,51 @@ bool
archive_lookup
(
char
*
pathname
,
const
char
**
archive
,
archive_lookup
(
char
*
pathname
,
const
char
**
archive
,
const
char
**
inpath
,
const
char
**
suffix
)
const
char
**
inpath
,
const
char
**
suffix
)
{
{
bool
ret
=
false
;
size_t
idx
=
strlen
(
pathname
)
;
char
*
const
pathdupe
=
g_strdup
(
pathname
);
char
*
slash
=
nullptr
;
const
size_t
len
=
strlen
(
pathname
);
size_t
idx
=
len
;
while
(
idx
>
0
)
{
while
(
true
)
{
//try to stat if its real directory
//try to stat if its real directory
struct
stat
st_info
;
struct
stat
st_info
;
if
(
stat
(
path
dup
e
,
&
st_info
)
==
-
1
)
{
if
(
stat
(
path
nam
e
,
&
st_info
)
==
-
1
)
{
if
(
errno
!=
ENOTDIR
)
{
if
(
errno
!=
ENOTDIR
)
{
FormatErrno
(
archive_domain
,
FormatErrno
(
archive_domain
,
"Failed to stat %s"
,
path
dup
e
);
"Failed to stat %s"
,
path
nam
e
);
break
;
return
false
;
}
}
}
else
{
}
else
{
//is something found ins original path (is not an archive)
//is something found ins original path (is not an archive)
if
(
idx
==
len
)
{
if
(
slash
==
nullptr
)
break
;
return
false
;
}
//its a file ?
//its a file ?
if
(
S_ISREG
(
st_info
.
st_mode
))
{
if
(
S_ISREG
(
st_info
.
st_mode
))
{
//so the upper should be file
//so the upper should be file
pathname
[
idx
]
=
0
;
ret
=
true
;
*
archive
=
pathname
;
*
archive
=
pathname
;
*
inpath
=
pathname
+
idx
+
1
;
*
inpath
=
slash
+
1
;
//try to get suffix
//try to get suffix
*
suffix
=
FindSuffix
(
pathname
,
idx
);
*
suffix
=
FindSuffix
(
pathname
,
slash
-
1
);
break
;
return
true
;
}
else
{
}
else
{
FormatError
(
archive_domain
,
FormatError
(
archive_domain
,
"Not a regular file: %s"
,
"Not a regular file: %s"
,
path
dup
e
);
path
nam
e
);
break
;
return
false
;
}
}
}
}
//find one dir up
//find one dir up
char
*
slash
=
FindSlash
(
pathdupe
,
idx
);
if
(
slash
!=
nullptr
)
*
slash
=
'/'
;
slash
=
FindSlash
(
pathname
,
idx
-
1
);
if
(
slash
==
nullptr
)
if
(
slash
==
nullptr
)
break
;
return
false
;
*
slash
=
0
;
*
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