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