namespace antlr3 { template ANTLR_FDSC FileUtils::AntlrFopen(const ANTLR_UINT8* filename, const char * mode) { return (ANTLR_FDSC)fopen((const char *)filename, mode); } template void FileUtils::AntlrFclose (ANTLR_FDSC fd) { fclose(fd); } template ANTLR_UINT32 FileUtils::AntlrFsize(const ANTLR_UINT8* filename) { struct _stat statbuf; _stat((const char *)filename, &statbuf); return (ANTLR_UINT32)statbuf.st_size; } template ANTLR_UINT32 FileUtils::AntlrFread(ANTLR_FDSC fdsc, ANTLR_UINT32 count, void* data) { return (ANTLR_UINT32)fread(data, (size_t)count, 1, fdsc); } template template ANTLR_UINT32 FileUtils::AntlrRead8Bit(InputStreamType* input, const ANTLR_UINT8* fileName) { ANTLR_FDSC infile; ANTLR_UINT32 fSize; /* Open the OS file in read binary mode */ infile = FileUtils::AntlrFopen(fileName, "rb"); /* Check that it was there */ if (infile == NULL) { ParseFileAbsentException ex; throw ex; } /* It was there, so we can read the bytes now */ fSize = FileUtils::AntlrFsize(fileName); /* Size of input file */ /* Allocate buffer for this input set */ void* data = ImplTraits::AllocPolicyType::alloc(fSize); /* Now we read the file. Characters are not converted to * the internal ANTLR encoding until they are read from the buffer */ FileUtils::AntlrFread(infile, fSize, data ); input->set_data( (unsigned char*) data ); input->set_sizeBuf( fSize ); input->set_isAllocated(true); /* And close the file handle */ FileUtils::AntlrFclose(infile); return ANTLR_SUCCESS; } }