httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Laurie <...@algroup.co.uk>
Subject Win32 name canonicalisation
Date Sun, 10 Aug 1997 12:50:36 GMT
Here's a not particularly efficient implementation of name
canonicalisation for Win32. Now all we need to do is figure out where to
slot it :-)

It isn't Apache-ised, just written as a simple test console program.

Cheers,

Ben.

#include <windows.h>
#include <stdio.h>
#include <assert.h>

void sub_canonical_filename(char *szCanon,const char *szFile)
{
    char buf[_MAX_PATH];
    int n;
    char *szFilePart;

    n=GetFullPathName(szFile,sizeof buf,buf,&szFilePart);
    assert(n);
    assert(n < sizeof buf);

    WIN32_FIND_DATA d;

    HANDLE h=FindFirstFile(buf,&d);
    assert(h != INVALID_HANDLE_VALUE);
    FindClose(h);

    if(szFilePart != buf+3) // "x:\" == 4
    {
	char b2[_MAX_PATH];
	assert(szFilePart > buf+3);

	szFilePart[-1]='\0';
	sub_canonical_filename(b2,buf);

	strcpy(szCanon,b2);
	strcat(szCanon,"/");
	strcat(szCanon,d.cFileName);
    }
    else
    {
	strcpy(szCanon,buf);
	szCanon[2]='/';
	szCanon[3]='\0';
	strcat(szCanon,d.cFileName);
    }
}

char *canonical_filename(const char *szFile)
{
    char buf[_MAX_PATH];

    sub_canonical_filename(buf,szFile);
    strlwr(buf);
    return strdup(buf);
}

void main(int argc,char **argv)
{
    char *szFile=argv[1];

    printf("%s\n",canonical_filename(szFile));
}

-- 
Ben Laurie                Phone: +44 (181) 994 6435  Email:
ben@algroup.co.uk
Freelance Consultant and  Fax:   +44 (181) 994 6472
Technical Director        URL: http://www.algroup.co.uk/Apache-SSL
A.L. Digital Ltd,         Apache Group member (http://www.apache.org)
London, England.          Apache-SSL author

Mime
View raw message