3dphotoshoot
annotate src/android/assman.c @ 17:aef7f51f6397
resource loading works
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 10 Jun 2015 06:56:27 +0300 |
parents | c6952cc82cca |
children | 4ca4e3c5a754 |
rev | line source |
---|---|
nuclear@16 | 1 #include <fcntl.h> |
nuclear@15 | 2 #include <android/asset_manager.h> |
nuclear@16 | 3 #include "assman.h" |
nuclear@16 | 4 #include "native_glue.h" |
nuclear@16 | 5 #include "amain.h" |
nuclear@15 | 6 |
nuclear@17 | 7 ass_file *ass_fopen(const char *fname, const char *mode) |
nuclear@15 | 8 { |
nuclear@16 | 9 AAsset *ass; |
nuclear@17 | 10 unsigned int flags = 0; |
nuclear@17 | 11 char prev = 0; |
nuclear@16 | 12 |
nuclear@17 | 13 while(*mode) { |
nuclear@17 | 14 switch(*mode) { |
nuclear@17 | 15 case 'r': |
nuclear@17 | 16 flags |= O_RDONLY; |
nuclear@17 | 17 break; |
nuclear@17 | 18 |
nuclear@17 | 19 case 'w': |
nuclear@17 | 20 flags |= O_WRONLY; |
nuclear@17 | 21 break; |
nuclear@17 | 22 |
nuclear@17 | 23 case 'a': |
nuclear@17 | 24 flags |= O_APPEND; |
nuclear@17 | 25 break; |
nuclear@17 | 26 |
nuclear@17 | 27 case '+': |
nuclear@17 | 28 if(prev == 'w' || prev == 'a') { |
nuclear@17 | 29 flags |= O_CREAT; |
nuclear@17 | 30 } |
nuclear@17 | 31 break; |
nuclear@17 | 32 |
nuclear@17 | 33 default: |
nuclear@17 | 34 break; |
nuclear@17 | 35 } |
nuclear@17 | 36 prev = *mode++; |
nuclear@17 | 37 } |
nuclear@17 | 38 |
nuclear@17 | 39 if(!(ass = AAssetManager_open(app->activity->assetManager, fname, flags))) { |
nuclear@16 | 40 return 0; |
nuclear@16 | 41 } |
nuclear@16 | 42 return (ass_file*)ass; |
nuclear@15 | 43 } |
nuclear@16 | 44 |
nuclear@16 | 45 void ass_fclose(ass_file *fp) |
nuclear@16 | 46 { |
nuclear@16 | 47 AAsset_close((AAsset*)fp); |
nuclear@16 | 48 } |
nuclear@16 | 49 |
nuclear@16 | 50 long ass_fseek(ass_file *fp, long offs, int whence) |
nuclear@16 | 51 { |
nuclear@16 | 52 return AAsset_seek((AAsset*)fp, offs, whence); |
nuclear@16 | 53 } |
nuclear@16 | 54 |
nuclear@16 | 55 size_t ass_fread(void *buf, size_t size, size_t count, ass_file *fp) |
nuclear@16 | 56 { |
nuclear@16 | 57 return AAsset_read((AAsset*)fp, buf, size * count) / size; |
nuclear@16 | 58 } |