Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sokol_fetch on Android #1074

Open
voidware opened this issue Jul 4, 2024 · 0 comments
Open

sokol_fetch on Android #1074

voidware opened this issue Jul 4, 2024 · 0 comments

Comments

@voidware
Copy link

voidware commented Jul 4, 2024

Not an issue. I haz fixes;

sokol_fetch.h POSIX section. no other changes needed.

#if _SFETCH_PLATFORM_POSIX

// XXX VOIDWARE
#ifdef __ANDROID__
_SOKOL_PRIVATE int android_read(void* a, char* buf, int size)
{
    return AAsset_read((AAsset*)a, buf, size);
}

_SOKOL_PRIVATE int android_write(void* a, const char* buf, int size)
{
    return EACCES;  // can't provide write access to the apk
}

_SOKOL_PRIVATE fpos_t android_seek(void* a, fpos_t offset, int whence) 
{
    return AAsset_seek((AAsset*)a, offset, whence);
}

_SOKOL_PRIVATE int android_close(void* a)
{
    AAsset_close((AAsset*)a);
    return 0;
}

_SOKOL_PRIVATE _sfetch_file_handle_t _sfetch_file_open(const _sfetch_path_t* path)
{
    _sfetch_file_handle_t h = _SFETCH_INVALID_FILE_HANDLE;
    auto act = (ANativeActivity*)sapp_android_get_native_activity();
    auto a = AAssetManager_open(act->assetManager, path->buf, 0);
    if (a)
    {
        h = funopen(a, android_read, android_write, android_seek,
                    android_close);
    }
    return h;
}

#else

_SOKOL_PRIVATE _sfetch_file_handle_t _sfetch_file_open(const _sfetch_path_t* path)
{
    return fopen(path->buf, "rb");
}

#endif // __ANDROID__ 

You can pay me later ! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants