Changeset 38413
- Timestamp:
- 09/05/10 03:52:54 (3 years ago)
- Location:
- lang/c/NetworkUpdater/trunk/Build
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/c/NetworkUpdater/trunk/Build/Copy.cpp
r38404 r38413 3 3 #endif 4 4 5 #undef STRICT 6 #define STRICT 5 7 #define _WIN32_WINNT 0x0500 /* Windows 2000 */ 6 8 … … 60 62 SYSTEMTIME st; 61 63 int len = 0; 62 TCHAR* buf = NULL;64 Buffer<TCHAR> buf; 63 65 GetLocalTime(&st); 64 66 len = GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, time_format, NULL, 0); 65 67 if (len >= 1) { 66 buf = (TCHAR*)calloc(len * sizeof(TCHAR), 1);68 buf.setBytes(len * sizeof(TCHAR)); 67 69 if (buf) { 68 70 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, time_format, buf, len); 69 71 WriteFile(StdOut, buf, (len - 1) * sizeof(buf[0]), &written, NULL); 70 free(buf);71 72 } 72 73 } … … 89 90 } 90 91 }; 91 H ANDLEmutex;92 H ANDLEmap;92 Handle mutex; 93 Handle map; 93 94 94 95 public: … … 103 104 } 104 105 }; 105 void lock() const{106 void lock() { 106 107 WaitForSingleObject(mutex, WAIT_LIMIT); 107 108 } 108 void unlock() const{109 void unlock() { 109 110 ReleaseMutex(mutex); 110 111 } 111 112 SharedMemory() { 112 TCHAR* name = NULL;113 113 size_t i = 0; 114 114 size_t len = 0; 115 115 116 116 len = GetCurrentDirectory(0, NULL); 117 name = (TCHAR*)calloc((len + (/* object sign */ 1)) * sizeof(TCHAR), 1);117 Buffer<TCHAR> name(len); 118 118 if (!name) { 119 119 Log(_T("calloc() name failed")); 120 goto clean_up;120 return; 121 121 } 122 122 GetCurrentDirectory(len, name); 123 Log(_T("cd=%s"), name);123 Log(_T("cd=%s"), (TCHAR*)name); 124 124 for (i = 0; i < len; ++i) { 125 125 if (!IsCharAlphaNumeric(name[i])) { … … 128 128 } 129 129 name[0] = _T('M'); 130 Log(_T("mapping name=%s"), name);130 Log(_T("mapping name=%s"), static_cast<TCHAR*>(name)); 131 131 132 132 map = CreateFileMapping( … … 139 139 140 140 name[0] = _T('X'); 141 Log(_T("mutex name=%s"), name);141 Log(_T("mutex name=%s"), static_cast<TCHAR*>(name)); 142 142 mutex = CreateMutex(NULL, FALSE, name); 143 144 clean_up:145 free(name);146 143 } 147 144 148 145 ~SharedMemory() { 149 if (map) { 150 CloseHandle(map); 151 } 152 if (mutex) { 153 CloseHandle(mutex); 154 } 155 } 156 157 Data read() const { 146 } 147 148 Data read() { 158 149 Data data; 159 150 memset(&data, 0, sizeof(data)); 160 void* r ead= NULL;161 r ead= MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);162 if (r ead) {163 memcpy(&data, r ead, sizeof(data));164 UnmapViewOfFile(r ead);151 void* r = NULL; 152 r = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0); 153 if (r) { 154 memcpy(&data, r, sizeof(data)); 155 UnmapViewOfFile(r); 165 156 } 166 157 return data; 167 158 } 168 159 169 void write(Data data) const{170 void* w rite= NULL;171 w rite= MapViewOfFile(map, FILE_MAP_WRITE, 0, 0, 0);172 if (w rite) {173 memcpy(w rite, &data, sizeof(data));174 UnmapViewOfFile(w rite);160 void write(Data data) { 161 void* w = NULL; 162 w = MapViewOfFile(map, FILE_MAP_WRITE, 0, 0, 0); 163 if (w) { 164 memcpy(w, &data, sizeof(data)); 165 UnmapViewOfFile(w); 175 166 } 176 167 } … … 413 404 BOOL CopyDirectory(const TCHAR* from, const TCHAR* to, SharedMemory& shared) 414 405 { 415 TCHAR* glob = NULL;416 406 WIN32_FIND_DATA find_data; 417 HANDLE hFind = NULL;418 407 BOOL result = TRUE; 419 408 … … 423 412 } 424 413 425 glob = PathAppendDup(from, _T("*"));414 Buffer<TCHAR> glob(PathAppendDup(from, _T("*"))); 426 415 if (!glob) { 427 416 Log(_T("CopyDirectory(): (!glob)")); … … 429 418 /* Log(_T("glob: %s"), glob); */ 430 419 431 hFind = FindFirstFile(glob, &find_data);432 if ( hFind == INVALID_HANDLE_VALUE) {420 Handle hFind(FindFirstFile(glob, &find_data)); 421 if (!hFind) { 433 422 Log(_T("CopyDirectory(): (hFind == INVALID_HANDLE_VALUE)")); 434 423 return FALSE; … … 436 425 437 426 do { 438 TCHAR* next_from = NULL;439 TCHAR* next_to = NULL;440 441 427 /* Log(_T("<%s>"), find_data.cFileName); */ 442 428 if (lstrcmp(find_data.cFileName, _T(".")) == 0) { … … 447 433 } 448 434 449 next_from = PathAppendDup(from, find_data.cFileName);450 next_to = PathAppendDup(to, find_data.cFileName);435 Buffer<TCHAR> next_from(PathAppendDup(from, find_data.cFileName)); 436 Buffer<TCHAR> next_to(PathAppendDup(to, find_data.cFileName)); 451 437 452 438 /* Log(_T("%s -> %s"), next_from, next_to); */ … … 473 459 } 474 460 } 475 476 free(next_to);477 free(next_from);478 461 } while(FindNextFile(hFind, &find_data)); 479 462 480 FindClose(hFind);481 free(glob);482 463 return result; 483 464 } 484 465 485 486 487 void LaunchMainProcess2(const TCHAR* path, const TCHAR* cd, int complete)488 {489 BOOL se = FALSE;490 DWORD e = 0;491 int hInstApp = 0;492 SHELLEXECUTEINFO sei;493 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);494 495 memset(&sei, 0, sizeof(sei));496 sei.cbSize = sizeof(sei);497 sei.fMask = 0;498 sei.lpFile = path;499 sei.lpVerb = _T("open");500 sei.lpDirectory = cd;501 if (complete) {502 sei.lpParameters = _T("UPDATE_COMPLETE");503 } else {504 sei.lpParameters = _T("UPDATE_ERROR");505 }506 Log(_T("ShellExecuteEx(): lpFile=%s, lpDirectory=%s"), sei.lpFile, sei.lpDirectory);507 se = ShellExecuteEx(&sei);508 e = GetLastError();509 hInstApp = (int)sei.hInstApp; /* http://msdn.microsoft.com/en-us/library/bb762154%28VS.85%29.aspx */510 511 Log(_T("ShellExecuteEx(): return=0x%x, GetLastError()=0x%x, hInstApp=0x%x"),512 se, e, hInstApp);513 514 if(!se || hInstApp <= 32) {515 Log(_T("ShellExecuteEx(): error"));516 goto clean_up;517 }518 519 Log(_T("ShellExecuteEx(): OK"));520 521 clean_up:522 CoUninitialize();523 }524 466 525 467 void LaunchMainProcess(const TCHAR* path, const TCHAR* cd, int complete) … … 533 475 TCHAR error_arg[] = _T("UPDATE_ERROR"); 534 476 int command_len = 0; 535 TCHAR* command = NULL;536 477 537 478 if (complete) { … … 544 485 command_len += lstrlen(arg); 545 486 546 command = (TCHAR*)calloc(1, (unsigned)command_len * sizeof(TCHAR));487 Buffer<TCHAR> command((unsigned)command_len); 547 488 if (!command) { 548 489 goto clean_up; … … 559 500 CloseHandle(pi.hProcess); 560 501 clean_up: 561 free(command);502 ; 562 503 } 563 504 … … 567 508 PROCESS_INFORMATION pi; 568 509 DWORD e = 0; 569 TCHAR comspec[MAX_PATH];570 510 TCHAR clean_command_format[] = _T("\"%s\" /c rd /s /q \"%s\""); 571 TCHAR* clean_command = NULL; 572 TCHAR* my_dir = NULL; 511 573 512 size_t clean_command_len = 0; 574 TCHAR* system_temp_path = NULL; 513 Buffer<TCHAR> clean_command; 514 Buffer<TCHAR> my_dir; 515 Buffer<TCHAR> system_temp_path; 516 Buffer<TCHAR> comspec; 517 Handle hProcess; 518 Handle hThread; 575 519 576 520 memset(&pi, 0, sizeof(pi)); 577 521 578 if (GetEnvironmentVariable(_T("COMSPEC"), comspec, sizeof(comspec) / sizeof(comspec[0])) == 0) { 579 Log(_T("no COMSPEC environment variable")); 580 goto clean_up; 581 } 522 { 523 size_t len = GetEnvironmentVariable(_T("COMSPEC"), NULL, 0); 524 if (len) { 525 Log(_T("no COMSPEC environment variable")); 526 return; 527 } 528 comspec.setBytes(len * sizeof(comspec[0])); 529 if (!comspec) { 530 Log(_T("calloc() comspec failed")); 531 return; 532 } 533 if (GetEnvironmentVariable(_T("COMSPEC"), comspec, len) == 0) { 534 Log(_T("no COMSPEC environment variable 2")); 535 return; 536 } 537 } 538 582 539 583 540 { 584 541 size_t len = GetTempPath(0, NULL); 585 system_temp_path = (TCHAR*)calloc(1,len * sizeof(TCHAR));542 system_temp_path.setBytes(len * sizeof(TCHAR)); 586 543 if (!system_temp_path) { 587 544 Log(_T("calloc() system_temp_path failed")); 588 goto clean_up;545 return; 589 546 } 590 547 GetTempPath(len, system_temp_path); … … 594 551 { 595 552 size_t len = GetCurrentDirectory(0, NULL); 596 my_dir = (TCHAR*)calloc(1,len * sizeof(TCHAR));553 my_dir.setBytes(len * sizeof(TCHAR)); 597 554 if (!my_dir) { 598 555 Log(_T("calloc() my_dir failed")); 599 goto clean_up;556 return; 600 557 } 601 558 GetCurrentDirectory(len, my_dir); … … 604 561 605 562 clean_command_len = lstrlen(comspec) + lstrlen(clean_command_format) + lstrlen(my_dir); 606 clean_command = (TCHAR*)calloc(clean_command_len * sizeof(TCHAR), 1);563 clean_command.setBytes(clean_command_len * sizeof(TCHAR)); 607 564 if (!clean_command) { 608 goto clean_up;609 } 610 wsprintf(clean_command, clean_command_format, comspec,my_dir);565 return; 566 } 567 wsprintf(clean_command, clean_command_format, (TCHAR*)comspec, (TCHAR*)my_dir); 611 568 612 569 memset(&si, 0, sizeof(si)); … … 615 572 si.wShowWindow = SW_HIDE; 616 573 CreateProcess(NULL, clean_command, NULL, NULL, FALSE, 0, NULL, system_temp_path, &si, &pi); 574 hProcess = pi.hProcess; 575 hThread = pi.hThread; 576 617 577 e = GetLastError(); 618 578 Log(_T("CreateProcess(): \r\n command=%s \r\n cd=%s \r\n error=0x%x"), clean_command, system_temp_path, e); 619 620 clean_up:621 if (pi.hThread) {622 CloseHandle(pi.hThread);623 }624 if (pi.hProcess) {625 CloseHandle(pi.hProcess);626 }627 free(system_temp_path);628 free(my_dir);629 free(clean_command);630 579 } 631 580 … … 637 586 DWORD bytes = 0; 638 587 DWORD bytes_got = 0; 639 TCHAR* data = NULL;640 588 DWORD written = 0; 641 H ANDLE config_file =CreateFile(ADMIN_OUTPUT_FILE_NAME, GENERIC_READ, FILE_SHARE_READ, NULL,642 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);589 Handle config_file(CreateFile(ADMIN_OUTPUT_FILE_NAME, GENERIC_READ, FILE_SHARE_READ, NULL, 590 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); 643 591 e = GetLastError(); 644 592 if (config_file == INVALID_HANDLE_VALUE) { 645 593 Log(_T("admin log open error 0x%x"), e); 646 goto log_end;594 return; 647 595 } 648 596 649 597 bytes = GetFileSize(config_file, NULL); 650 data = (TCHAR*)calloc(1,bytes + (/* null terminate */ sizeof(TCHAR)));598 Buffer<char> data(bytes + (/* null terminate */ sizeof(TCHAR))); 651 599 if (!data) { 652 goto log_end;600 return; 653 601 } 654 602 … … 656 604 e = GetLastError(); 657 605 Log(_T("admin log read error 0x%x"), e); 658 goto log_end;606 return; 659 607 } 660 608 Log(_T("--- admin mode log start ---")); … … 665 613 Log(_T("--- admin mode log error error=0x%x, written=0x%x ---"), e, written); 666 614 } 667 668 log_end:669 free(data);670 CloseHandle(config_file);671 615 } 672 616 … … 678 622 SHELLEXECUTEINFO sei; 679 623 size_t len = 33000; 680 TCHAR* my_path = NULL; 624 Buffer<TCHAR> my_path(len); 625 Handle hProcess; 626 627 struct CleanUp { 628 ~CleanUp() { 629 OutputAdminLog(); 630 CoUninitialize(); 631 } 632 } CleanUp; 681 633 682 634 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); 683 my_path = (TCHAR*)calloc(len * sizeof(TCHAR), 1); 684 GetModuleFileName(GetModuleHandle(NULL), my_path, len); 635 GetModuleFileName(GetModuleHandle(NULL), my_path, len - (1 /* for null terminate */)); 685 636 686 637 memset(&sei, 0, sizeof(sei)); … … 694 645 e = GetLastError(); 695 646 hInstApp = (int)sei.hInstApp; /* http://msdn.microsoft.com/en-us/library/bb762154%28VS.85%29.aspx */ 647 hProcess = sei.hProcess; 696 648 697 649 Log(_T("ShellExecuteEx(): return=0x%x, GetLastError()=0x%x, hInstApp=0x%x"), … … 700 652 if(!se || hInstApp <= 32) { 701 653 Log(_T("ShellExecuteEx(): error")); 702 goto clean_up;654 return; 703 655 } 704 656 … … 723 675 break; 724 676 } 725 726 clean_up:727 if (sei.hProcess) {728 CloseHandle(sei.hProcess);729 }730 731 CoUninitialize();732 free(my_path);733 734 OutputAdminLog();735 677 } 736 678 737 679 int WriteCheck(const TCHAR* dir) { 738 680 unsigned int retry = 0; 739 TCHAR* check_path = NULL;740 681 for (retry = 10; retry != 0; --retry) { 741 682 TCHAR name[1024]; … … 743 684 wsprintf(name, _T("NetworkUpdater.AccessCheck.%1!x!.%2!x!.txt"), 744 685 GetCurrentThreadId(), GetTickCount() - retry); 745 free(check_path); 746 check_path = PathAppendDup(dir, name); 686 Buffer<TCHAR> check_path(PathAppendDup(dir, name)); 687 if (!check_path) { 688 return 0; 689 } 747 690 if (PathFileExists(check_path)) { 748 691 continue; 749 692 } 750 693 if (check_path) { 751 H ANDLE check =CreateFile(694 Handle check(CreateFile( 752 695 check_path, GENERIC_WRITE | DELETE, 0, NULL, CREATE_NEW, 753 FILE_ATTRIBUTE_HIDDEN | FILE_FLAG_DELETE_ON_CLOSE, NULL) ;696 FILE_ATTRIBUTE_HIDDEN | FILE_FLAG_DELETE_ON_CLOSE, NULL)); 754 697 if (check != INVALID_HANDLE_VALUE) { 755 698 TCHAR data[] = _T("write test data"); 756 699 DWORD written = 0; 757 700 if (WriteFile(check, data, lstrlen(data) * sizeof(data[0]), &written, NULL)) { 758 CloseHandle(check);759 701 break; 760 702 } 761 CloseHandle(check); 762 } 763 } 764 } 765 free(check_path); 703 } 704 } 705 } 766 706 767 707 return (retry != 0); … … 770 710 int main(void) 771 711 { 772 H ANDLE thread = NULL;773 H ANDLE config_file = INVALID_HANDLE_VALUE;774 H ANDLE caller_process = NULL;775 TCHAR* data = NULL;712 Handle thread; 713 Handle config_file; 714 Handle caller_process; 715 Buffer<TCHAR> data; 776 716 const TCHAR* new_program = NULL; 777 717 const TCHAR* new_program_cd = NULL; … … 828 768 829 769 bytes = GetFileSize(config_file, NULL); 830 data = (TCHAR*)calloc(1,bytes + (/* null terminate */ sizeof(TCHAR)));770 data.setBytes(bytes + (/* null terminate */ sizeof(TCHAR))); 831 771 if (!data) { 832 772 goto clean_up; … … 965 905 } 966 906 967 if (config_file != INVALID_HANDLE_VALUE) {968 CloseHandle(config_file);969 }970 971 if (caller_process) {972 CloseHandle(caller_process);973 }974 975 if (thread) {976 CloseHandle(thread);977 }978 979 907 if (data) { 980 908 free(data); -
lang/c/NetworkUpdater/trunk/Build/MSW.am
r38393 r38413 17 17 -fstack-protector -Wno-missing-field-initializers 18 18 19 copy_SOURCES = Copy.c 19 copy_SOURCES = Copy.cpp 20 20 copy_CPPFLAGS = -DUNICODE -D_UNICODE -DSTRICT 21 copy_C FLAGS = -O0 -g $(C_WARNINGS)21 copy_CXXFLAGS = -O0 -g $(CXX_WARNINGS) 22 22 copy_LDFLAGS = -Wl,-nostdlib -L/usr/lib/w32api 23 23 -
lang/c/NetworkUpdater/trunk/Build/Nodefaultlib.h
r38392 r38413 1 1 2 #define calloc(num, size) NUI_calloc(num, size)3 #define free(memblock) NUI_free(memblock)2 #define calloc(num, size) ((void*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, num * size)) 3 #define free(memblock) (void)(memblock ? HeapFree(GetProcessHeap(), 0, memblock): 0) 4 4 #define _wcsdup(s) NUI_wcsdup(s) 5 5 #define wcsdup(s) NUI_wcsdup(s) … … 36 36 } 37 37 return dest; 38 }39 40 /* http://msdn.microsoft.com/en-US/library/3f8w183e%28v=VS.80%29.aspx */41 void *NUI_calloc(size_t num, size_t size)42 {43 return (void*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, num * size);44 }45 46 /* http://msdn.microsoft.com/en-US/library/we1whae7%28v=VS.80%29.aspx */47 void NUI_free(void *memblock)48 {49 if (memblock) {50 HeapFree(GetProcessHeap(), 0, memblock);51 }52 38 } 53 39 … … 87 73 return num; 88 74 } 75 76 77 #ifdef __cplusplus 78 79 #include <boost/utility.hpp> 80 81 class Handle { 82 HANDLE h; 83 84 public: 85 Handle(Handle& s) : h(NULL) { 86 DuplicateHandle(GetCurrentProcess(), 87 s.h, 88 GetCurrentProcess(), 89 &h, 90 0, 91 FALSE, 92 DUPLICATE_SAME_ACCESS); 93 } 94 95 Handle(HANDLE h_) : h(h_) { 96 } 97 98 Handle() : h(NULL) { 99 } 100 101 ~Handle() { 102 if (*this) { 103 CloseHandle(h); 104 } 105 } 106 107 operator HANDLE() { 108 return h; 109 } 110 111 operator bool() { 112 return h != INVALID_HANDLE_VALUE && h != NULL; 113 } 114 115 template <typename U> operator U() { 116 return static_cast<U>(h); 117 } 118 }; 119 120 template <typename T = char> 121 class Buffer { 122 T* b; 123 124 explicit Buffer(const Buffer&) { 125 } 126 127 Buffer& operator=(const Buffer&) { 128 b = NULL; 129 return *this; 130 } 131 132 public: 133 134 Buffer(size_t s) : b(NULL) { 135 setBytes(s * sizeof(T)); 136 } 137 138 Buffer(T* b_) : b(b_) { 139 } 140 141 Buffer& operator=(TCHAR* b_) { 142 b = b_; 143 return *this; 144 } 145 146 Buffer() : b(NULL) { 147 } 148 149 ~Buffer() { 150 free(b); 151 } 152 153 void setBytes(size_t bytes) { 154 b = (T*)calloc(bytes, 1); 155 } 156 157 operator T*() { 158 return b; 159 } 160 161 operator bool() { 162 return b != NULL; 163 } 164 165 template <typename U> operator U() { 166 return static_cast<U>(b); 167 } 168 }; 169 170 #endif 171 -
lang/c/NetworkUpdater/trunk/Build/UnCab.cpp
r38407 r38413 1 #ifndef _UNICODE 2 #error 3 #endif 4 5 #undef STRICT 6 #define STRICT 7 1 8 #include <stdio.h> 2 9 #include <windows.h> … … 20 27 FNSEEK(SeekProc); 21 28 22 BOOL StartFDI(char* lpszOutputDirectory, char* lpszFileName);23 24 29 int _tmain(int argc, TCHAR** argv) 25 30 { 26 BOOL bResult = FALSE;27 28 31 if (argc < 2) { 29 32 //printf("invalid argument count\n"); … … 31 34 } 32 35 36 ERF erf; 37 HFDI hfdi = FDICreate(AllocProc, FreeProc, OpenProc, ReadProc, WriteProc, CloseProc, SeekProc, cpu80386, &erf); 38 if (hfdi == NULL) { 39 //printf("FDICreate() failed erfOper=0x%x\n", erf.erfOper); 40 return FALSE; 41 } 42 33 43 char dir[] = ".\\"; 34 char* file = NUI_TCharToMultiByteDup(argv[1]); 44 Buffer<char> file = NUI_TCharToMultiByteDup(argv[1]); 45 46 if (!FDICopy(hfdi, file, dir, 0, NotifyProc, NULL, NULL)) { 47 //printf("FDICopy() failed erfOper=0x%x\n", erf.erfOper); 48 } 35 49 36 bResult = StartFDI(dir, file); 37 if (bResult) { 38 //printf("failed\n"); 39 } 40 return !bResult; 50 FDIDestroy(hfdi); 41 51 } 42 52 … … 54 64 } 55 65 56 BOOL StartFDI(char* lpszDirectoryName, char* lpszFileName)57 {58 ERF erf;59 BOOL bResult = FALSE;60 61 HFDI hfdi = FDICreate(AllocProc, FreeProc, OpenProc, ReadProc, WriteProc, CloseProc, SeekProc, cpu80386, &erf);62 if (hfdi == NULL) {63 //printf("FDICreate() failed erfOper=0x%x\n", erf.erfOper);64 return FALSE;65 }66 67 bResult = FDICopy(hfdi, lpszFileName, lpszDirectoryName, 0, NotifyProc, NULL, NULL);68 if (!bResult) {69 //printf("FDICopy() failed erfOper=0x%x\n", erf.erfOper);70 }71 72 FDIDestroy(hfdi);73 74 return bResult;75 }76 77 66 FNFDINOTIFY(NotifyProc) 78 67 { … … 80 69 81 70 case fdintCOPY_FILE: { 82 char szFileName[1024]; 83 lstrcpyA(szFileName, pfdin->psz1); 84 HANDLE hFile = CreateFileA(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 85 if (hFile == INVALID_HANDLE_VALUE) { 71 Buffer<char> path(lstrlenA(pfdin->psz1) + (1 /* null terminate */)); 72 if (!path) { 73 return -1; 74 } 75 lstrcpyA(path, pfdin->psz1); 76 HANDLE file = CreateFileA(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 77 if (file == INVALID_HANDLE_VALUE) { 86 78 //printf("CreateFileA() failed szFileName=%s\n", szFileName); 87 79 return -1; 88 80 } 89 90 return (int)hFile; 81 return (int)file; 91 82 } 92 83 93 84 case fdintCLOSE_FILE_INFO: { 94 char szFileName[1024];95 85 FILETIME fileTime; 96 86 FILETIME localFileTime; … … 102 92 CloseHandle((HANDLE)pfdin->hf); 103 93 104 lstrcpyA(szFileName, pfdin->psz1); 105 SetFileAttributesA(szFileName, pfdin->attribs); 94 Buffer<char> path(lstrlenA(pfdin->psz1) + (1 /* null terminate */)); 95 lstrcpyA(path, pfdin->psz1); 96 SetFileAttributesA(path, pfdin->attribs); 106 97 107 98 return TRUE; … … 128 119 FNOPEN(OpenProc) 129 120 { 130 HANDLE hFile = NULL;131 121 DWORD dwDesiredAccess = 0; 132 122 DWORD dwCreationDisposition = 0; … … 134 124 UNREFERENCED_PARAMETER(pmode); 135 125 136 if ( oflag & _O_RDWR ) 137 { 126 if (oflag & _O_RDWR) { 138 127 dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; 139 } 140 else if ( oflag & _O_WRONLY ) 141 { 128 } else if (oflag & _O_WRONLY) { 142 129 dwDesiredAccess = GENERIC_WRITE; 143 } 144 else 145 { 130 } else { 146 131 dwDesiredAccess = GENERIC_READ; 147 132 } 148 133 149 if ( oflag & _O_CREAT ) 150 { 134 if (oflag & _O_CREAT) { 151 135 dwCreationDisposition = CREATE_ALWAYS; 152 } 153 else 154 { 136 } else { 155 137 dwCreationDisposition = OPEN_EXISTING; 156 138 } 157 139 158 hFile = CreateFileA(pszFile,140 HANDLE hFile = CreateFileA(pszFile, 159 141 dwDesiredAccess, 160 142 FILE_SHARE_READ, … … 172 154 { 173 155 DWORD dwBytesRead = 0; 174 if (ReadFile((HANDLE)hf, pv, cb, &dwBytesRead, NULL) == FALSE) 175 { 156 if (ReadFile((HANDLE)hf, pv, cb, &dwBytesRead, NULL) == FALSE) { 176 157 dwBytesRead = (DWORD)-1L; 177 158 } … … 183 164 { 184 165 DWORD dwBytesWritten = 0; 185 if (WriteFile((HANDLE)hf, pv, cb, &dwBytesWritten, NULL) == FALSE) 186 { 166 if (WriteFile((HANDLE)hf, pv, cb, &dwBytesWritten, NULL) == FALSE) { 187 167 dwBytesWritten = (DWORD)-1; 188 168 } … … 192 172 FNCLOSE(CloseProc) 193 173 { 194 return ( CloseHandle((HANDLE)hf) == TRUE) ? 0 : -1;174 return (CloseHandle((HANDLE)hf) == TRUE) ? 0 : -1; 195 175 } 196 197 176 198 177 FNSEEK(SeekProc) … … 200 179 return SetFilePointer((HANDLE)hf, dist, 0, seektype); 201 180 } 202 203 204 205
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)