Mailing List Archive

[clamav-users] Cannot get 'fd' when using API 'cl_scanfile'
Hi there,
I am trying to use API to scan a file with the file's absolute file path under Windows system. But it returns CL_EOPEN, Can't open file or directory. So, I debug step by step. The 'cl_scanfile' calls 'cl_scanfile_callback' and 'cl_scanfile_callback' calls 'safe_open (fname, O_RDONLY | O_BINARY)' , in the 'safe_open', there is a function called '_wopen' and it returns -1. So, the code can't find file descriptor.
I don't know why '_wopen' returns -1 and how to debug it. So, any suggestion could be helpful.
Also, I try to use GetLastError but find nothing.

int safe_open(const char *path, int flags, ...)
{
wchar_t *wpath = uncpath(path);
int ret;

if (!wpath)
return -1;
if (flags & O_CREAT) {
int mode;
va_list ap;
va_start(ap, flags);
mode = va_arg(ap, int);
va_end(ap);
ret = _wopen(wpath, flags, mode);
}
else {
ret = _wopen(wpath, flags);
}
free(wpath);
return ret;
}

Thanks!
Jack Gao