Boost logo

Boost-Build :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-03-26 11:07:37


bjorn.karlsson_at_[hidden] wrote:
> > From: David Abrahams [mailto:dave_at_[hidden]]
> >
> > I don't think converting this to 'C' should be very difficult. I
> > might give it a shot if I can get my travel plans firmed up first.
>
> Below is a dirty hack that might do the trick.
>
> Bjorn

Hi Bjorn,

thanks a lot! I'm gonna try this when I get access to a windows box.
If anybody has the time now, I attach the modified 'pwd.c' (which might not
compile, since I could not even try that).

Thanks,
Volodya

 --------------Boundary-00=_P46D9EUNAWCUZCX6430A Content-Type: text/x-csrc;
charset="iso-8859-1";
name="pwd.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="pwd.c"

#include "jam.h"
#include "lists.h"
#include "newstr.h"

#ifdef NT
#include <direct.h>
#define PATH_MAX _MAX_PATH
#else
#include <unistd.h>
#endif

#include <limits.h>

#ifdef NT
#include <tchar.h>
#include <windows.h>

DWORD ShortPathToLongPath(LPCTSTR lpszShortPath,LPTSTR lpszLongPath,DWORD
cchBuffer)
{
DWORD i=0;
TCHAR path[_MAX_PATH]={0};
TCHAR ret[_MAX_PATH]={0};
DWORD pos=0;
DWORD len=_tcslen(lpszShortPath);

// Is the string valid?
if (!lpszShortPath) {
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
}

// Is the path valid?
if (GetFileAttributes(lpszShortPath)==INVALID_FILE_ATTRIBUTES)
return 0;

// Convert "/" to "\"
for (i=0;i<len;++i) {
if (lpszShortPath[i]==_T('/'))
path[i]=_T('\\');
else
path[i]=lpszShortPath[i];
}

// UNC path?
if (path[0]==_T('\\') && path[1]==_T('\\')) {
pos=2;
for (i=0;i<2;++i) {
while (path[pos]!=_T('\\') && path[pos]!=_T('\0'))
++pos;
++pos;
}
_tcsncpy(ret,path,pos-1);
} // Drive letter?
else if (path[1]==_T(':')) {
if (path[2]==_T('\\'))
pos=3;
if (len==3) {
if (cchBuffer>3)
_tcscpy(lpszLongPath,lpszShortPath);
return len;
}
_tcsncpy(ret,path,2);
}

// Expand the path for each subpath, and strip trailing backslashes
for (;pos<=len;++pos) {
if (path[pos]==_T('\\') || (path[pos]==_T('\0') &&
path[pos-1]!=_T('\\'))) {
WIN32_FIND_DATA fd;
HANDLE hf=0;
TCHAR c=path[pos];
path[pos]=_T('\0');

hf=FindFirstFile(path, &fd);
if (hf==INVALID_HANDLE_VALUE)
return 0;

// Append the result
_tcscat(ret,_T("\\"));
_tcscat(ret,fd.cFileName);
path[pos]=c;
FindClose(hf);
}
}

len=_tcslen(ret)+1;
if (cchBuffer>=len)
_tcscpy(lpszLongPath,ret);

return len;
}
#endif

LIST*
pwd(void)
{
char buffer[PATH_MAX];
if (getcwd(buffer, sizeof(buffer)) == NULL)
{
perror("can not get current directory");
return L0;
}
else
{
#ifdef NT
char buffer2[_MAX_PATH];
ShortPathToLongPath(buffer, buffer2, _MAX_PATH);
return list_new(L0, newstr(buffer2));
#else
return list_new(L0, newstr(buffer));
#endif
}
}

 --------------Boundary-00=_P46D9EUNAWCUZCX6430A--


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk