From 1873ebdddc9d0656c593fd1aa2b3cd1df4dc2b5c Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 17 Oct 2008 14:12:19 +0200 Subject: [PATCH] kernel32: Delete the .windows-label file if the label is empty. Add a trailing \n to the label file. --- dlls/kernel32/volume.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dlls/kernel32/volume.c b/dlls/kernel32/volume.c index 4214cca1f3f..823d163008e 100644 --- a/dlls/kernel32/volume.c +++ b/dlls/kernel32/volume.c @@ -723,6 +723,10 @@ BOOL WINAPI SetVolumeLabelW( LPCWSTR root, LPCWSTR label ) WCHAR labelW[] = {'A',':','\\','.','w','i','n','d','o','w','s','-','l','a','b','e','l',0}; labelW[0] = device[4]; + + if (!label[0]) /* delete label file when setting an empty label */ + return DeleteFileW( labelW ) || GetLastError() == ERROR_FILE_NOT_FOUND; + handle = CreateFileW( labelW, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, 0 ); if (handle != INVALID_HANDLE_VALUE) @@ -730,8 +734,9 @@ BOOL WINAPI SetVolumeLabelW( LPCWSTR root, LPCWSTR label ) char buffer[64]; DWORD size; - if (!WideCharToMultiByte( CP_UNIXCP, 0, label, -1, buffer, sizeof(buffer), NULL, NULL )) - buffer[sizeof(buffer)-1] = 0; + if (!WideCharToMultiByte( CP_UNIXCP, 0, label, -1, buffer, sizeof(buffer)-1, NULL, NULL )) + buffer[sizeof(buffer)-2] = 0; + strcat( buffer, "\n" ); WriteFile( handle, buffer, strlen(buffer), &size, NULL ); CloseHandle( handle ); return TRUE;