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