00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <mxcpcStreamFile.h>
00018 #include <mxcpc_exceptions.h>
00019
00020 #ifdef WIN32
00021 #include <io.h>
00022 #else
00023 #include <unistd.h>
00024 #endif
00025 #include <fcntl.h>
00026
00027
00028
00029 mxcpcStreamFile::mxcpcStreamFile(const char *filename) {
00030
00031 InFile = open(filename, O_RDONLY);
00032 if(InFile == -1) throw mxcpcIOFailure();
00033
00034 StillUp = true;
00035 }
00036
00037
00038 mxcpcStreamFile::~mxcpcStreamFile() {
00039
00040 close(InFile);
00041 }
00042
00043
00044
00045 int mxcpcStreamFile::fetchBytes(unsigned char *buffer, int num) {
00046
00047 int actually_read;
00048
00049 if(!StillUp) return(0);
00050
00051 actually_read = read(InFile, buffer, num);
00052
00053 if(actually_read <= 0) {
00054
00055 StillUp = false;
00056 return(0);
00057 }
00058
00059 return(actually_read);
00060 }