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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47#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; }