Add get_architectures() and C++ versions
* get_architectures() returns the primary and the secondary architectures in one array. That turned out to be convenient. * Add C++ versions for get[_secondary]_architectures(), returning a BStringList.
This commit is contained in:
parent
2c2f3ab4e1
commit
c39c9283aa
@ -18,10 +18,25 @@ const char* get_architecture();
|
||||
const char* get_primary_architecture();
|
||||
size_t get_secondary_architectures(const char** architectures,
|
||||
size_t count);
|
||||
size_t get_architectures(const char** architectures, size_t count);
|
||||
const char* guess_architecture_for_path(const char* path);
|
||||
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
||||
/* C++ API */
|
||||
#ifdef __cplusplus
|
||||
|
||||
|
||||
#include <StringList.h>
|
||||
|
||||
|
||||
status_t get_secondary_architectures(BStringList& _architectures);
|
||||
status_t get_architectures(BStringList& _architectures);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _SUPPORT_ARCHITECTURE_H */
|
||||
|
@ -16,6 +16,7 @@ const char* __get_architecture();
|
||||
const char* __get_primary_architecture();
|
||||
size_t __get_secondary_architectures(const char** architectures,
|
||||
size_t count);
|
||||
size_t __get_architectures(const char** architectures, size_t count);
|
||||
const char* __guess_architecture_for_path(const char* path);
|
||||
|
||||
|
||||
|
53
src/kits/support/Architecture.cpp
Normal file
53
src/kits/support/Architecture.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <Architecture.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <StringList.h>
|
||||
|
||||
|
||||
static const size_t kMaxArchitectureCount = 16;
|
||||
|
||||
|
||||
static status_t
|
||||
string_array_to_string_list(const char* const* architectures, size_t count,
|
||||
BStringList& _architectures)
|
||||
{
|
||||
_architectures.MakeEmpty();
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
BString architecture(architectures[i]);
|
||||
if (architecture.IsEmpty() || !_architectures.Add(architecture)) {
|
||||
_architectures.MakeEmpty();
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
get_secondary_architectures(BStringList& _architectures)
|
||||
{
|
||||
const char* architectures[kMaxArchitectureCount];
|
||||
size_t count = get_secondary_architectures(architectures,
|
||||
kMaxArchitectureCount);
|
||||
return string_array_to_string_list(architectures,
|
||||
std::min(count, kMaxArchitectureCount), _architectures);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
get_architectures(BStringList& _architectures)
|
||||
{
|
||||
const char* architectures[kMaxArchitectureCount];
|
||||
size_t count = get_architectures(architectures, kMaxArchitectureCount);
|
||||
return string_array_to_string_list(architectures,
|
||||
std::min(count, kMaxArchitectureCount), _architectures);
|
||||
}
|
@ -10,6 +10,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
local architecture = $(TARGET_PACKAGING_ARCH) ;
|
||||
|
||||
MergeObject <libbe!$(architecture)>support_kit.o :
|
||||
Architecture.cpp
|
||||
Archivable.cpp
|
||||
ArchivingManagers.cpp
|
||||
Beep.cpp
|
||||
|
@ -85,6 +85,17 @@ __get_secondary_architectures(const char** architectures, size_t count)
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
__get_architectures(const char** architectures, size_t count)
|
||||
{
|
||||
if (count == 0)
|
||||
return __get_secondary_architectures(NULL, 0) + 1;
|
||||
|
||||
architectures[0] = __get_primary_architecture();
|
||||
return __get_secondary_architectures(architectures + 1, count -1) + 1;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
__guess_architecture_for_path(const char* path)
|
||||
{
|
||||
@ -114,4 +125,5 @@ __guess_architecture_for_path(const char* path)
|
||||
B_DEFINE_WEAK_ALIAS(__get_architecture, get_architecture);
|
||||
B_DEFINE_WEAK_ALIAS(__get_primary_architecture, get_primary_architecture);
|
||||
B_DEFINE_WEAK_ALIAS(__get_secondary_architectures, get_secondary_architectures);
|
||||
B_DEFINE_WEAK_ALIAS(__get_architectures, get_architectures);
|
||||
B_DEFINE_WEAK_ALIAS(__guess_architecture_for_path, guess_architecture_for_path);
|
||||
|
Loading…
Reference in New Issue
Block a user