3dphotoshoot

view src/android/assman.c @ 18:dccbd7d65517

moved to android-19 to make it work with android 4.x
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 10 Jun 2015 18:53:28 +0300
parents c6952cc82cca
children 4ca4e3c5a754
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 size_t ass_fread(void *buf, size_t size, size_t count, ass_file *fp)
56 {
57 return AAsset_read((AAsset*)fp, buf, size * count) / size;
58 }