This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [maybe-ITP] gamin


Corinna Vinschen wrote:
> Just to dismiss NT4 instead of implementing
> these 10 lines of code is a bit strange, isn't it?
>   
I hardly call this 10 lines of code, it was more than 1 hour worth of
work, emulating that pesky function ;-)
(of course I completely ignored UNC paths and the very idea that
"C:\mnt\driveC" can be a mount point)

Anyway, I wrote something "close enough".
Unfortunately I am well over the free time I had so I have to GTG Yakoov
package another evening =(

% wc -l GVPN.c
88 GVPN.c
% cat GVPN.c
#include <windows.h>
#include <string.h>

BOOL EmGetVolumePathName(
LPCTSTR lpszFileName,
LPTSTR lpszVolumePathName,
DWORD cchBufferLength
)
{
if (cchBufferLength < 4)
return 0;
if (isalpha(lpszFileName[0])) {
lpszVolumePathName[0] = lpszFileName[1] == ':' ? lpszFileName[0] : 'C';
lpszVolumePathName[1] = ':';
lpszVolumePathName[2] = '\\';
lpszVolumePathName[3] = 0;
return 1;
}
if (lpszFileName[0] == '\\' && lpszFileName[1] == '\\' &&
isalpha(lpszFileName[2])) {
int slash = 0;
while (*lpszFileName != 0 && slash < 4) {
if (*lpszFileName == '\\')
++slash;
if (cchBufferLength-- > 1)
*lpszVolumePathName++ = *lpszFileName++;
else
return 0;
}
if (slash == 2)
return 0;
else if (slash == 3) {
if (cchBufferLength-- > 1)
*lpszVolumePathName++ = '\\';
else
return 0;
}
*lpszVolumePathName = 0;
return 1;
}
return 0;
}

BOOL MyGetVolumePathName(
LPCTSTR lpszFileName,
LPTSTR lpszVolumePathName,
DWORD cchBufferLength
)
{
HINSTANCE hinstLib = LoadLibrary("Kernel32");
if (hinstLib != NULL) {
BOOL (*fun)(LPCTSTR, LPTSTR, DWORD) = (BOOL (*)(LPCTSTR, LPTSTR, DWORD))
GetProcAddress(hinstLib, "GetVolumePathNameA");
// If the function address is valid, call the function.
if (fun != NULL) {
BOOL ret = fun(lpszFileName, lpszVolumePathName, cchBufferLength);
FreeLibrary(hinstLib);
return ret;
}
FreeLibrary(hinstLib);
}
return EmGetVolumePathName(lpszFileName, lpszVolumePathName,
cchBufferLength);
}

main() {
char try[][80] = {
"Z",
"Z:",
"Z:\\ciao",
"\\\\cyberone",
"\\\\cyberone\\Musica",
"\\\\cyberone\\Musica\\ciao",
"\\\\cyberone\\Musica-ciao-too-much--way-too-much",
"\\\\\\cyberone"
};
char root[40];
int i;
BOOL b;
for (i = 0; i < sizeof(try) / sizeof(try[0]); ++i) {
printf("Orig = %s\n", try[i]);
strcpy(root, "--------------------");
b = MyGetVolumePathName(try[i], root, 40);
printf("Real = %d %s\n", b, root);
strcpy(root, "--------------------");
b = EmGetVolumePathName(try[i], root, 40);
printf("Emul = %d %s\n", b, root);
putchar('\n');
}
}
% gcc -o GVPN.exe GVPN.c && ./GVPN.exe
Orig = Z
Real = 1 C:\
Emul = 1 C:\

Orig = Z:
Real = 1 Z:\
Emul = 1 Z:\

Orig = Z:\ciao
Real = 1 Z:\
Emul = 1 Z:\

Orig = \\cyberone
Real = 0 --------------------
Emul = 0 \\cyberone----------

Orig = \\cyberone\Musica
Real = 1 \\cyberone\Musica\
Emul = 1 \\cyberone\Musica\

Orig = \\cyberone\Musica\ciao
Real = 1 \\cyberone\Musica\
Emul = 1 \\cyberone\Musica\

Orig = \\cyberone\Musica-ciao-too-much--way-too-much
[some seconds delay, as this share doesn't actually exist]
Real = 0 --------------------
Emul = 0 \\cyberone\Musica-ciao-too-much--way-to

Orig = \\\cyberone
Real = 0 --------------------
Emul = 0 --------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]