istereo2

view src/android/assman.c @ 7:a3c4fcc9f8f3

- started a goatkit UI theme - font rendering with drawtext and shaders - asset manager (only used by drawtext for now, will replace respath eventually)
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 24 Sep 2015 06:49:25 +0300
parents
children 7d795dade0bc
line source
1 #include <fcntl.h>
2 #include <android/asset_manager.h>
3 #include "assman.h"
4 #include "native_glue.h"
5 #include "amain.h"
7 ass_file *ass_fopen(const char *fname, const char *mode)
8 {
9 AAsset *ass;
10 unsigned int flags = 0;
11 char prev = 0;
13 while(*mode) {
14 switch(*mode) {
15 case 'r':
16 flags |= O_RDONLY;
17 break;
19 case 'w':
20 flags |= O_WRONLY;
21 break;
23 case 'a':
24 flags |= O_APPEND;
25 break;
27 case '+':
28 if(prev == 'w' || prev == 'a') {
29 flags |= O_CREAT;
30 }
31 break;
33 default:
34 break;
35 }
36 prev = *mode++;
37 }
39 if(!(ass = AAssetManager_open(app->activity->assetManager, fname, flags))) {
40 return 0;
41 }
42 return (ass_file*)ass;
43 }
45 void ass_fclose(ass_file *fp)
46 {
47 AAsset_close((AAsset*)fp);
48 }
50 long ass_fseek(ass_file *fp, long offs, int whence)
51 {
52 return AAsset_seek((AAsset*)fp, offs, whence);
53 }
55 long ass_ftell(ass_file *fp)
56 {
57 return AAsset_seek((AAsset*)fp, 0, SEEK_SET);
58 }
60 size_t ass_fread(void *buf, size_t size, size_t count, ass_file *fp)
61 {
62 return AAsset_read((AAsset*)fp, buf, size * count) / size;
63 }