1 module allegro5.file; 2 3 import allegro5.internal.da5; 4 import allegro5.path; 5 import allegro5.utf8; 6 7 version (Tango) 8 { 9 import tango.core.Vararg : va_list; 10 } 11 else 12 { 13 version(D_Version2) 14 { 15 import core.stdc.stdarg : va_list; 16 } 17 else 18 { 19 import std.c.stdarg : va_list; 20 } 21 } 22 23 version(Windows) 24 { 25 private alias long off_t; 26 } 27 else 28 { 29 version(Tango) 30 { 31 import tango.stdc.posix.sys.types : off_t; 32 } 33 else 34 { 35 version(D_Version2) 36 { 37 import core.sys.posix.sys.types : off_t; 38 } 39 else 40 { 41 version(linux) 42 { 43 import std.c.linux.linux : off_t; 44 } 45 else 46 { 47 import std.c.freebsd.freebsd : off_t; 48 } 49 } 50 } 51 } 52 53 nothrow @nogc extern (C) 54 { 55 struct ALLEGRO_FILE_INTERFACE 56 { 57 void* function(in char* path, in char* mode) fi_fopen; 58 bool function(ALLEGRO_FILE* handle) fi_fclose; 59 size_t function(ALLEGRO_FILE* f, void* ptr, size_t size) fi_fread; 60 size_t function(ALLEGRO_FILE* f, in void* ptr, size_t size) fi_fwrite; 61 bool function(ALLEGRO_FILE* f) fi_fflush; 62 long function(ALLEGRO_FILE* f) fi_ftell; 63 bool function(ALLEGRO_FILE* f, long offset, int whence) fi_fseek; 64 bool function(ALLEGRO_FILE* f) fi_feof; 65 int function(ALLEGRO_FILE* f) fi_ferror; 66 const_char* function(ALLEGRO_FILE* f) fi_ferrmsg(ALLEGRO_FILE *f); 67 void function(ALLEGRO_FILE* f) fi_fclearerr; 68 int function(ALLEGRO_FILE* f, int c) fi_fungetc; 69 off_t function(ALLEGRO_FILE* f) fi_fsize; 70 } 71 72 struct ALLEGRO_FILE 73 { 74 } 75 76 enum ALLEGRO_SEEK 77 { 78 ALLEGRO_SEEK_SET = 0, 79 ALLEGRO_SEEK_CUR, 80 ALLEGRO_SEEK_END 81 } 82 83 84 /* The basic operations. */ 85 ALLEGRO_FILE* al_fopen(in char* path, in char* mode); 86 ALLEGRO_FILE* al_fopen_interface(in ALLEGRO_FILE_INTERFACE* vt, in char* path, in char* mode); 87 ALLEGRO_FILE* al_create_file_handle(in ALLEGRO_FILE_INTERFACE* vt, void* userdata); 88 bool al_fclose(ALLEGRO_FILE* f); 89 size_t al_fread(ALLEGRO_FILE* f, void* ptr, size_t size); 90 size_t al_fwrite(ALLEGRO_FILE* f, in void* ptr, size_t size); 91 bool al_fflush(ALLEGRO_FILE* f); 92 long al_ftell(ALLEGRO_FILE* f); 93 bool al_fseek(ALLEGRO_FILE* f, long offset, int whence); 94 bool al_feof(ALLEGRO_FILE* f); 95 int al_ferror(ALLEGRO_FILE* f); 96 const_char* al_ferrmsg(ALLEGRO_FILE *f); 97 void al_fclearerr(ALLEGRO_FILE *f); 98 int al_fungetc(ALLEGRO_FILE* f, int c); 99 long al_fsize(ALLEGRO_FILE* f); 100 101 /* Convenience functions. */ 102 int al_fgetc(ALLEGRO_FILE* f); 103 int al_fputc(ALLEGRO_FILE* f, int c); 104 short al_fread16le(ALLEGRO_FILE* f); 105 short al_fread16be(ALLEGRO_FILE* f); 106 size_t al_fwrite16le(ALLEGRO_FILE* f, short w); 107 size_t al_fwrite16be(ALLEGRO_FILE* f, short w); 108 int al_fread32le(ALLEGRO_FILE* f); 109 int al_fread32be(ALLEGRO_FILE* f); 110 size_t al_fwrite32le(ALLEGRO_FILE* f, int l); 111 size_t al_fwrite32be(ALLEGRO_FILE* f, int l); 112 char* al_fgets(ALLEGRO_FILE* f, in char* p, size_t max); 113 ALLEGRO_USTR* al_fget_ustr(ALLEGRO_FILE* f); 114 int al_fputs(ALLEGRO_FILE* f, in char* p); 115 int al_fprintf(ALLEGRO_FILE *f, const char *format, ...); 116 int al_vfprintf(ALLEGRO_FILE *f, const char* format, va_list args); 117 118 /* Specific to stdio backend. */ 119 ALLEGRO_FILE* al_fopen_fd(int fd, in char* mode); 120 ALLEGRO_FILE* al_make_temp_file(in char* tmpl, ALLEGRO_PATH **ret_path); 121 122 /* Specific to slices. */ 123 ALLEGRO_FILE* al_fopen_slice(ALLEGRO_FILE* fp, size_t initial_size, in char *mode); 124 125 /* Thread-local state. */ 126 ALLEGRO_FILE_INTERFACE* al_get_new_file_interface(); 127 void al_set_new_file_interface(in ALLEGRO_FILE_INTERFACE* file_interface); 128 void al_set_standard_file_interface(); 129 void* al_get_file_userdata(ALLEGRO_FILE *f); 130 }