ArchiveLookup: return const strings
This commit is contained in:
parent
e132d10aec
commit
1b8a1d4140
@ -29,7 +29,9 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
bool archive_lookup(char *pathname, char **archive, char **inpath, char **suffix)
|
bool
|
||||||
|
archive_lookup(char *pathname, const char **archive,
|
||||||
|
const char **inpath, const char **suffix)
|
||||||
{
|
{
|
||||||
char *pathdupe;
|
char *pathdupe;
|
||||||
int len, idx;
|
int len, idx;
|
||||||
|
@ -37,7 +37,9 @@
|
|||||||
* inarchive pathname: Talco - Combat Circus/12 - A la pachenka.mp3
|
* inarchive pathname: Talco - Combat Circus/12 - A la pachenka.mp3
|
||||||
* and suffix: zip
|
* and suffix: zip
|
||||||
*/
|
*/
|
||||||
bool archive_lookup(char *pathname, char **archive, char **inpath, char **suffix);
|
bool
|
||||||
|
archive_lookup(char *pathname, const char **archive,
|
||||||
|
const char **inpath, const char **suffix);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -45,14 +45,14 @@ input_archive_open(const char *pathname,
|
|||||||
Error &error)
|
Error &error)
|
||||||
{
|
{
|
||||||
const struct archive_plugin *arplug;
|
const struct archive_plugin *arplug;
|
||||||
char *archive, *filename, *suffix, *pname;
|
|
||||||
struct input_stream *is;
|
struct input_stream *is;
|
||||||
|
|
||||||
if (!Path::IsAbsoluteFS(pathname))
|
if (!Path::IsAbsoluteFS(pathname))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
pname = g_strdup(pathname);
|
char *pname = g_strdup(pathname);
|
||||||
// archive_lookup will modify pname when true is returned
|
// archive_lookup will modify pname when true is returned
|
||||||
|
const char *archive, *filename, *suffix;
|
||||||
if (!archive_lookup(pname, &archive, &filename, &suffix)) {
|
if (!archive_lookup(pname, &archive, &filename, &suffix)) {
|
||||||
FormatDebug(archive_domain,
|
FormatDebug(archive_domain,
|
||||||
"not an archive, lookup %s failed", pname);
|
"not an archive, lookup %s failed", pname);
|
||||||
|
@ -23,7 +23,7 @@ public:
|
|||||||
void
|
void
|
||||||
ArchiveLookupTest::TestArchiveLookup()
|
ArchiveLookupTest::TestArchiveLookup()
|
||||||
{
|
{
|
||||||
char *archive, *inpath, *suffix;
|
const char *archive, *inpath, *suffix;
|
||||||
|
|
||||||
char *path = strdup("");
|
char *path = strdup("");
|
||||||
CPPUNIT_ASSERT_EQUAL(false,
|
CPPUNIT_ASSERT_EQUAL(false,
|
||||||
@ -48,16 +48,16 @@ ArchiveLookupTest::TestArchiveLookup()
|
|||||||
path = strdup("Makefile/foo/bar");
|
path = strdup("Makefile/foo/bar");
|
||||||
CPPUNIT_ASSERT_EQUAL(true,
|
CPPUNIT_ASSERT_EQUAL(true,
|
||||||
archive_lookup(path, &archive, &inpath, &suffix));
|
archive_lookup(path, &archive, &inpath, &suffix));
|
||||||
CPPUNIT_ASSERT_EQUAL(path, archive);
|
CPPUNIT_ASSERT_EQUAL((const char *)path, archive);
|
||||||
CPPUNIT_ASSERT_EQUAL(0, strcmp(archive, "Makefile"));
|
CPPUNIT_ASSERT_EQUAL(0, strcmp(archive, "Makefile"));
|
||||||
CPPUNIT_ASSERT_EQUAL(0, strcmp(inpath, "foo/bar"));
|
CPPUNIT_ASSERT_EQUAL(0, strcmp(inpath, "foo/bar"));
|
||||||
CPPUNIT_ASSERT_EQUAL((char *)nullptr, suffix);
|
CPPUNIT_ASSERT_EQUAL((const char *)nullptr, suffix);
|
||||||
g_free(path);
|
g_free(path);
|
||||||
|
|
||||||
path = strdup("config.h/foo/bar");
|
path = strdup("config.h/foo/bar");
|
||||||
CPPUNIT_ASSERT_EQUAL(true,
|
CPPUNIT_ASSERT_EQUAL(true,
|
||||||
archive_lookup(path, &archive, &inpath, &suffix));
|
archive_lookup(path, &archive, &inpath, &suffix));
|
||||||
CPPUNIT_ASSERT_EQUAL(path, archive);
|
CPPUNIT_ASSERT_EQUAL((const char *)path, archive);
|
||||||
CPPUNIT_ASSERT_EQUAL(0, strcmp(archive, "config.h"));
|
CPPUNIT_ASSERT_EQUAL(0, strcmp(archive, "config.h"));
|
||||||
CPPUNIT_ASSERT_EQUAL(0, strcmp(inpath, "foo/bar"));
|
CPPUNIT_ASSERT_EQUAL(0, strcmp(inpath, "foo/bar"));
|
||||||
CPPUNIT_ASSERT_EQUAL(0, strcmp(suffix, "h"));
|
CPPUNIT_ASSERT_EQUAL(0, strcmp(suffix, "h"));
|
||||||
|
Loading…
Reference in New Issue
Block a user