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