3 #include <android/asset_manager.h>
5 #include "android_native_app_glue.h"
7 struct android_app *app; /* defined in android/amain.c */
9 static int putback_buf = -1;
11 ass_file *ass_fopen(const char *fname, const char *mode)
14 unsigned int flags = 0;
32 if(prev == 'w' || prev == 'a') {
44 assert(app->activity);
45 assert(app->activity->assetManager);
46 if(!(ass = AAssetManager_open(app->activity->assetManager, fname, flags))) {
49 return (ass_file*)ass;
52 void ass_fclose(ass_file *fp)
54 AAsset_close((AAsset*)fp);
57 long ass_fseek(ass_file *fp, long offs, int whence)
59 return AAsset_seek((AAsset*)fp, offs, whence);
62 long ass_ftell(ass_file *fp)
64 return AAsset_seek((AAsset*)fp, 0, SEEK_CUR);
67 int ass_feof(ass_file *fp)
69 return AAsset_getRemainingLength((AAsset*)fp) == 0 ? 1 : 0;
72 size_t ass_fread(void *buf, size_t size, size_t count, ass_file *fp)
74 size_t nbytes = size * count;
77 if(putback_buf >= 0) {
78 *(unsigned char*)buf = (unsigned char)putback_buf;
82 buf = (unsigned char*)buf + 1;
85 return (rdbytes + AAsset_read((AAsset*)fp, buf, nbytes)) / size;
88 int ass_ungetc(int c, ass_file *fp)