Пример #1
0
   bool FSLock::obtain()
   {
	   	if ( !Misc::dir_Exists(lockDir) ){
	      if ( _mkdir(lockDir) == -1 ){
	   		  char* err = _CL_NEWARRAY(char,34+strlen(lockDir)+1); //34: len of "Couldn't create lock directory: "
	   		  strcpy(err,"Couldn't create lock directory: ");
	   		  strcat(err,lockDir);
	   		  _CLTHROWA_DEL(CL_ERR_IO, err );
	      }
	    }
Пример #2
0
	MMapIndexInput::MMapIndexInput(const char* path):
	    _internal(_CLNEW Internal)
	{
	//Func - Constructor.
	//       Opens the file named path
	//Pre  - path != NULL
	//Post - if the file could not be opened  an exception is thrown.

	  CND_PRECONDITION(path != NULL, "path is NULL");

#if defined(_CL_HAVE_FUNCTION_MAPVIEWOFFILE)
	  _internal->mmaphandle = NULL;
	  _internal->fhandle = CreateFileA(path,GENERIC_READ,FILE_SHARE_READ, 0,OPEN_EXISTING,0,0);
	  
	  //Check if a valid fhandle was retrieved
	  if (_internal->fhandle < 0){
		_cl_dword_t err = GetLastError();
        if ( err == ERROR_FILE_NOT_FOUND )
		    _CLTHROWA(CL_ERR_IO, "File does not exist");
        else if ( err == ERROR_ACCESS_DENIED )
            _CLTHROWA(ERROR_ACCESS_DENIED, "File Access denied");
        else if ( err == ERROR_TOO_MANY_OPEN_FILES )
            _CLTHROWA(CL_ERR_IO, "Too many open files");
		else
			_CLTHROWA(CL_ERR_IO, "File IO Error");
	  }

	  _cl_dword_t dummy=0;
	  _internal->_length = GetFileSize(_internal->fhandle, &dummy);

	  if ( _internal->_length > 0 ){
			_internal->mmaphandle = CreateFileMappingA(_internal->fhandle,NULL,PAGE_READONLY,0,0,NULL);
			if ( _internal->mmaphandle != NULL ){
				void* address = MapViewOfFile(_internal->mmaphandle,FILE_MAP_READ,0,0,0);
				if ( address != NULL ){
					_internal->data = (uint8_t*)address;
					return; //SUCCESS!
				}
			}
			
			//failure:
			int errnum = GetLastError(); 
			
			CloseHandle(_internal->mmaphandle);
	
			char* lpMsgBuf=strerror(errnum);
			size_t len = strlen(lpMsgBuf)+80;
			char* errstr = _CL_NEWARRAY(char, len); 
			cl_sprintf(errstr, "MMapIndexInput::MMapIndexInput failed with error %d: %s", len, errnum, lpMsgBuf); 
	
			_CLTHROWA_DEL(CL_ERR_IO,errstr);
	  }