msvcrt: add support for _chsize_s (try #2)

Piotr Caban piotr.caban at gmail.com
Mon Oct 7 05:29:10 CDT 2013


Hi,

On 10/06/13 00:45, morphiend wrote:
> + *		_chsize_s (MSVCRT.@)
> + */
> +int CDECL MSVCRT__chsize_s(int fd, __int64 size)
> +{
> +    LARGE_INTEGER cur, pos;
> +    LARGE_INTEGER temp = { 0 };
This causes compilation warnings. There's also a trailing space in this 
line.

> +    TRACE("(fd=%d, size=%lld)\n", fd, size);
You can't print 64-bit numbers this way, it's not portable. You can use 
wine_dbgstr_longlong function.

> +    handle = msvcrt_fdtoh(fd);
> +    if (!MSVCRT_CHECK_PMT_ERR(handle == INVALID_HANDLE_VALUE, MSVCRT_EBADF) ||
> +        !MSVCRT_CHECK_PMT_ERR(size < 0, MSVCRT_EINVAL))
You're validating parameters incorrectly. Did you test this patch?

> +            {
> +                ret = SetEndOfFile(handle);
> +                if (!ret)
> +                {
> +                    msvcrt_set_errno(GetLastError());
> +                    ret = *MSVCRT__errno();
> +                }
This causes the _chsize_s function to return TRUE in case of success.

> +               /* restore the file pointer */
> +               MSVCRT__lseek(fd, cur.QuadPart, SEEK_SET);
MSVCRT__lseek takes LONG as second argument.

Cheers,
Piotr



More information about the wine-devel mailing list