Skip to content

Commit

Permalink
android: Use Android bionic's arc4random_uniform (which isn't in head…
Browse files Browse the repository at this point in the history
…ers but is available on all versions so far)
  • Loading branch information
zhuowei committed Jan 7, 2016
1 parent 97dfba0 commit 20dbe89
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions stdlib/public/stubs/LibcShims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ static_assert(std::is_same<ssize_t, swift::__swift_ssize_t>::value,
#ifdef __ANDROID__
extern "C" {
extern size_t dlmalloc_usable_size(void*);
// arc4random_random is missing in headers but does exist
extern unsigned int arc4random_uniform(unsigned int upper_bound);
}
#endif

Expand Down Expand Up @@ -73,21 +75,12 @@ size_t _swift_stdlib_malloc_size(const void *ptr) {
#error No malloc_size analog known for this platform/libc.
#endif

#ifndef __ANDROID__
__swift_uint32_t _swift_stdlib_arc4random(void) { return arc4random(); }

__swift_uint32_t
_swift_stdlib_arc4random_uniform(__swift_uint32_t upper_bound) {
return arc4random_uniform(upper_bound);
}
#else
// FIXME: Android: chosen by fair dice roll
__swift_uint32_t _swift_stdlib_arc4random(void) { return 4; }
__swift_uint32_t
_swift_stdlib_arc4random_uniform(__swift_uint32_t upper_bound) {
return 0;
}
#endif

} // namespace swift

0 comments on commit 20dbe89

Please sign in to comment.