示例#1
0
文件: engine.go 项目: eaigner/clam
func (e *clEngine) Scan(file *os.File) error {
	e.mtx.Lock()
	defer e.mtx.Unlock()

	var ret C.int
	var fd C.int = C.int(file.Fd())
	var virname *C.char
	var size C.ulong = 0

	// Scan file
	var virName string
	ret = C.cl_scandesc(fd, &virname, &size, e.engine, C.CL_SCAN_STDOPT)
	if ret == C.CL_VIRUS {
		virName = C.GoString(virname)
	} else if ret == C.CL_CLEAN {
		// do nothing
	} else {
		return fmt.Errorf("error scanning file: %s", C.GoString(C.cl_strerror(ret)))
	}
	if len(virName) > 0 {
		return &VirusError{
			VirusName:    virName,
			BytesScanned: uint64(size * C.CL_COUNT_PRECISION),
		}
	}
	return nil
}
示例#2
0
func (e *Engine) ScanDesc(desc int, opts uint) (string, uint, error) {
	var name *C.char
	var scanned C.ulong
	err := ErrorCode(C.cl_scandesc(C.int(desc), &name, &scanned, (*C.struct_cl_engine)(e), C.uint(opts)))
	if err == Success {
		return "", 0, nil
	}
	if err == Virus {
		return C.GoString(name), uint(scanned), fmt.Errorf(StrError(err))
	}
	return "", 0, fmt.Errorf(StrError(err))
}