istereo2

view src/android/assman.c @ 24:9d53a4938ce8

port to android mostly complete, ads not done, and needs some polishing
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 04 Oct 2015 08:15:24 +0300
parents 7d795dade0bc
children
line source
1 #include <assert.h>
2 #include <fcntl.h>
3 #include <android/asset_manager.h>
4 #include "assman.h"
5 #include "android_native_app_glue.h"
7 struct android_app *app; /* defined in android/amain.c */
9 ass_file *ass_fopen(const char *fname, const char *mode)
10 {
11 AAsset *ass;
12 unsigned int flags = 0;
13 char prev = 0;
15 while(*mode) {
16 switch(*mode) {
17 case 'r':
18 flags |= O_RDONLY;
19 break;
21 case 'w':
22 flags |= O_WRONLY;
23 break;
25 case 'a':
26 flags |= O_APPEND;
27 break;
29 case '+':
30 if(prev == 'w' || prev == 'a') {
31 flags |= O_CREAT;
32 }
33 break;
35 default:
36 break;
37 }
38 prev = *mode++;
39 }
41 assert(app);
42 assert(app->activity);
43 assert(app->activity->assetManager);
44 if(!(ass = AAssetManager_open(app->activity->assetManager, fname, flags))) {
45 return 0;
46 }
47 return (ass_file*)ass;
48 }
50 void ass_fclose(ass_file *fp)
51 {
52 AAsset_close((AAsset*)fp);
53 }
55 long ass_fseek(ass_file *fp, long offs, int whence)
56 {
57 return AAsset_seek((AAsset*)fp, offs, whence);
58 }
60 long ass_ftell(ass_file *fp)
61 {
62 return AAsset_seek((AAsset*)fp, 0, SEEK_SET);
63 }
65 size_t ass_fread(void *buf, size_t size, size_t count, ass_file *fp)
66 {
67 return AAsset_read((AAsset*)fp, buf, size * count) / size;
68 }