In message <200302031928.h13JSEG02846@...
> of Mon, 3 Feb 2003
20:28:14 in , Bram Moolenaar <Bram@...
>Walter Briscoe wrote:
>> >Looking at this, I wonder if we should do anything with "cch", the
>> >length that GetComputerName() returns. If not, can't we directly get
>> >the host name into "s"?
>> We sure can!
>> In W2K SP3, I abstracted the code into a one compilation unit program to
>> develop the following.
>> The truncated result behaviour of the two versions differ.
>> GetComputerName() fails if the input buffer is not long enough. My
>> computer name is "D3CY200J". mch_get_host_name(x,3) sets x to "D3" with
>> the old code and "PC" with the new.
>> As the only call of mch_get_host_name() passes a 256 byte buffer, this
>> change of behaviour never happens in practice.
>> I ported the code back to os_win32.c and confirmed hostname() continues
>> to work.
>Passing "len" to GetComputerName() violates types. It might work if
>"DWORD" == "int", but let's not risk that. It probably breaks on Win64.
I would be surprised if it does break - given the abomination that is
long long in C99. However, I agree that your idea is better than mine!
If it does break, VC gives a diagnostic.
warning C4133: 'function' : incompatible types - from 'short *' to 'long *'
>How about this then:
> char_u *s,
> int len)
> DWORD cch = len;
> if (!GetComputerName(s, &cch))
> STRNCPY(s, "PC (Win32 Vim)", len);
> s[len - 1] = NUL; /* make sure it's terminated */
I did a quick check with no problem with that code with Make_ivc.dsw.