httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Laurie <...@algroup.co.uk>
Subject Re: Win32 name canonicalisation
Date Mon, 11 Aug 1997 22:10:43 GMT
Actually, that wasn't quite perfect. I think this may be:

#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;
    WIN32_FIND_DATA d;

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

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

    if(szFilePart < buf+3)
    {
	strcpy(szCanon,buf);
	szCanon[2]='/';
	return;
    }
    if(szFilePart != buf+3)
    {
	char b2[_MAX_PATH];
	assert(szFilePart > buf+3);

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

	strcpy(szCanon,b2);
	strcat(szCanon,"/");
    }
    else
    {
	strcpy(szCanon,buf);
	szCanon[2]='/';
	szCanon[3]='\0';
    }
    if(h == INVALID_HANDLE_VALUE)
	strcat(szCanon,szFilePart);
    else
	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];
    char *szCanon=canonical_filename(szFile);

    printf("%s\n",szCanon);
}

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

Mime
View raw message