| 1089 | } |
| 1090 | |
| 1091 | char *loadfile(const char *fn, int *size, const char *mode) |
| 1092 | { |
| 1093 | stream *f = openfile(fn, mode ? mode : "rb"); |
| 1094 | if(!f) return NULL; |
| 1095 | int len = f->size(); |
| 1096 | if(len<=0) { delete f; return NULL; } |
| 1097 | char *buf = new char[len+1]; |
| 1098 | if(!buf) { delete f; return NULL; } |
| 1099 | buf[len] = 0; |
| 1100 | int rlen = f->read(buf, len); |
| 1101 | delete f; |
| 1102 | if(len!=rlen && (!mode || strchr(mode, 'b'))) |
| 1103 | { |
| 1104 | delete[] buf; |
| 1105 | return NULL; |
| 1106 | } |
| 1107 | if(size!=NULL) *size = len; |
| 1108 | return buf; |
| 1109 | } |
| 1110 | |
| 1111 | int streamcopy(stream *dest, stream *source, int maxlen) |
| 1112 | { |
no test coverage detected