示例#1
0
 void handle(lua_State* L) const
 {
     try
     {
         try_next(L);
     }
     catch (argument e)
     {
         handler(L, e);
     }
 }
示例#2
0
MULTI_FILE *open_multi_file(const char *path)
{
	__int64 len;
	
	MULTI_FILE *r;
	MF_PRIVATE_DATA *prv;
	int fd;

	int i,n;
	char *work;
	void *tmp;

	int mode;
	
	r = (MULTI_FILE *)calloc(1, sizeof(MULTI_FILE));
	if(r == NULL){
		return NULL;
	}

	prv = (MF_PRIVATE_DATA *)calloc(1, sizeof(MF_PRIVATE_DATA));
	if(prv == NULL){
		free(r);
		return NULL;
	}

	fd = _open(path, _O_BINARY|_O_RDONLY|_O_SEQUENTIAL);
	if(fd < 0){
		free(prv);
		free(r);
		return NULL;
	}

	n = strlen(path)+1;
	work = (char *)malloc(n);
	if(work == NULL){
		_close(fd);
		free(prv);
		free(r);
		return NULL;
	}
	memcpy(work, path, n);
	
	prv->info = (MF_FILE_INFO *)malloc(sizeof(MF_FILE_INFO));
	if(prv->info == NULL){
		free(work);
		_close(fd);
		free(prv);
		free(r);
		return NULL;
	}

	mode = get_file_mode();

	while(fd >= 0){
		tmp = realloc(prv->info, sizeof(MF_FILE_INFO)*(prv->count+1));
		if(tmp == NULL){
			_close(fd);
			fd = -1;
			break;
		}
		prv->info = (MF_FILE_INFO *)tmp;

		len = _lseeki64(fd, 0, SEEK_END);
		_lseeki64(fd, 0, SEEK_SET);
		_close(fd);
		
		i = prv->count;

		prv->info[i].length = len;
		prv->info[i].offset = prv->total;
		prv->info[i].fd = -1;
		prv->info[i].path = malloc(n);
		if(prv->info[i].path == NULL){
			break;
		}
		memcpy(prv->info[i].path, work, n);
		
		prv->total += len;

		prv->count += 1;

		if(mode & M2V_CONFIG_MULTI_FILE){
			fd = try_next(work);
		}else{
			fd = -1;
		}
	}

	if(prv->count == 0){
		free(prv->info);
		free(work);
		if(fd >= 0){
			_close(fd);
		}
		free(prv);
		free(r);
		return NULL;
	}

	free(work);

	r->private_data = prv;
	r->close = mf_close;
	if(prv->count == 1){
		r->tell = sf_tell;
		r->seek = sf_seek;
		r->read = sf_read;
		prv->info[0].fd = _open(prv->info[0].path, _O_BINARY|_O_RDONLY|_O_SEQUENTIAL);
	}else{
		r->tell = mf_tell;
		r->seek = mf_seek;
		r->read = mf_read;
	}
	r->count = mf_count;
	r->border = mf_border;
	
	return r;
}