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