Skip to content
Tcl Source Code Attachment Details
Login

Attachment Details

Overview

Artifact ID: 58f5407c29264e66974f59fafb4a67be6145f940
Ticket: 3092089fffffffffffffffffffffffffffffffff
Date: 2010-10-27 16:26:03
User: dunkfan
Artifact Attached: 62623f694665d49b0d7a8120266d336fcb11973f
Filename:otto371.c
Description:Illustration of possible API Calls for overcoming file normalize problems with junctions
Content:
 #include <stdio.h>
#include <windows.h>

static const char* GetLastErrorText(DWORD dwError)
{
    static char szMsgBuf[256];

    if (!FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM |
			FORMAT_MESSAGE_IGNORE_INSERTS |
			FORMAT_MESSAGE_MAX_WIDTH_MASK,
			NULL, dwError, 0,
			szMsgBuf, sizeof(szMsgBuf), NULL))
	(void)sprintf(szMsgBuf, "Win32 Error %lu", dwError);

  return szMsgBuf;
}

int main(void)
{
  static const char path[] = "C:/Documents and Settings";
  char   jpath[MAX_PATH];
  HANDLE hDir = CreateFile(path, 0,
		FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
		NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);

  if (hDir == INVALID_HANDLE_VALUE)
  {
    printf("CreateFile(%s) failed: %s\n",
	   path, GetLastErrorText(GetLastError()));
    return -1;
  }

  if (GetFinalPathNameByHandle(hDir, jpath, sizeof(jpath),
			       FILE_NAME_NORMALIZED) == 0)
  {
    printf("GetFinalPathNameByHandle() failed: %s\n",
	   GetLastErrorText(GetLastError()));
    (void)CloseHandle(hDir);
    return -1;
  }

  (void)CloseHandle(hDir);

  printf("junction: %s\n", jpath);

  return 0;
}