[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wine-devel
Subject:    Re: MSVCRT: implement _chsize
From:       Alexandre Julliard <julliard () winehq ! org>
Date:       2005-03-30 15:58:56
Message-ID: 87sm2d3z27.fsf () wine ! dyndns ! org
[Download RAW message or body]

Hans Leidekker <hans@it.vu.nl> writes:

>  int _chsize(int fd, long size)
>  {
> -    FIXME("(fd=%d, size=%ld): stub\n", fd, size);
> -    return -1;
> +    DWORD cur, pos;
> +    HANDLE handle;
> +    BOOL ret = FALSE;
> +
> +    TRACE("(fd=%d, size=%ld)\n", fd, size);
> +
> +    LOCK_FILES();
> +
> +    handle = msvcrt_fdtoh(fd);
> +    if (handle != INVALID_HANDLE_VALUE)
> +    {
> +        /* save the current file pointer */
> +        cur = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
> +        if (cur != INVALID_SET_FILE_POINTER)
> +        {
> +            pos = SetFilePointer(handle, size, NULL, FILE_BEGIN);
> +            if (pos != INVALID_SET_FILE_POINTER)
> +                ret = SetEndOfFile(handle);
> +
> +            /* restore the file pointer */
> +            pos = SetFilePointer(handle, cur, NULL, FILE_BEGIN);
> +        }
> +    }
> +
> +    UNLOCK_FILES();
> +    return ret ? 0 : -1;
>  }

SetFilePointer can return INVALID_SET_FILE_POINTER on success if the
current pointer is 0xffffffff, you have to check last error in that
case. Also you need to set errno on failure. It may be easier to use
_lseek instead of SetFilePointer as it takes care of all that already.

-- 
Alexandre Julliard
julliard@winehq.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic