@@ -425,6 +425,84 @@ vimLoadLib(char *name)
425425 return dll ;
426426}
427427
428+ #if defined(DYNAMIC_ICONV ) || defined(DYNAMIC_GETTEXT ) || defined(PROTO )
429+ /*
430+ * Get related information about 'funcname' which is imported by 'hInst'.
431+ * If 'info' is 0, return the function address.
432+ * If 'info' is 1, return the module name which the function is imported from.
433+ */
434+ static void *
435+ get_imported_func_info (HINSTANCE hInst , const char * funcname , int info )
436+ {
437+ PBYTE pImage = (PBYTE )hInst ;
438+ PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER )hInst ;
439+ PIMAGE_NT_HEADERS pPE ;
440+ PIMAGE_IMPORT_DESCRIPTOR pImpDesc ;
441+ PIMAGE_THUNK_DATA pIAT ; /* Import Address Table */
442+ PIMAGE_THUNK_DATA pINT ; /* Import Name Table */
443+ PIMAGE_IMPORT_BY_NAME pImpName ;
444+
445+ if (pDOS -> e_magic != IMAGE_DOS_SIGNATURE )
446+ return NULL ;
447+ pPE = (PIMAGE_NT_HEADERS )(pImage + pDOS -> e_lfanew );
448+ if (pPE -> Signature != IMAGE_NT_SIGNATURE )
449+ return NULL ;
450+ pImpDesc = (PIMAGE_IMPORT_DESCRIPTOR )(pImage
451+ + pPE -> OptionalHeader .DataDirectory [IMAGE_DIRECTORY_ENTRY_IMPORT ]
452+ .VirtualAddress );
453+ for (; pImpDesc -> FirstThunk ; ++ pImpDesc )
454+ {
455+ if (!pImpDesc -> OriginalFirstThunk )
456+ continue ;
457+ pIAT = (PIMAGE_THUNK_DATA )(pImage + pImpDesc -> FirstThunk );
458+ pINT = (PIMAGE_THUNK_DATA )(pImage + pImpDesc -> OriginalFirstThunk );
459+ for (; pIAT -> u1 .Function ; ++ pIAT , ++ pINT )
460+ {
461+ if (IMAGE_SNAP_BY_ORDINAL (pINT -> u1 .Ordinal ))
462+ continue ;
463+ pImpName = (PIMAGE_IMPORT_BY_NAME )(pImage
464+ + (UINT_PTR )(pINT -> u1 .AddressOfData ));
465+ if (strcmp ((char * )pImpName -> Name , funcname ) == 0 )
466+ {
467+ switch (info )
468+ {
469+ case 0 :
470+ return (void * )pIAT -> u1 .Function ;
471+ case 1 :
472+ return (void * )(pImage + pImpDesc -> Name );
473+ default :
474+ return NULL ;
475+ }
476+ }
477+ }
478+ }
479+ return NULL ;
480+ }
481+
482+ /*
483+ * Get the module handle which 'funcname' in 'hInst' is imported from.
484+ */
485+ HINSTANCE
486+ find_imported_module_by_funcname (HINSTANCE hInst , const char * funcname )
487+ {
488+ char * modulename ;
489+
490+ modulename = (char * )get_imported_func_info (hInst , funcname , 1 );
491+ if (modulename != NULL )
492+ return GetModuleHandleA (modulename );
493+ return NULL ;
494+ }
495+
496+ /*
497+ * Get the address of 'funcname' which is imported by 'hInst' DLL.
498+ */
499+ void *
500+ get_dll_import_func (HINSTANCE hInst , const char * funcname )
501+ {
502+ return get_imported_func_info (hInst , funcname , 0 );
503+ }
504+ #endif
505+
428506#if defined(DYNAMIC_GETTEXT ) || defined(PROTO )
429507# ifndef GETTEXT_DLL
430508# define GETTEXT_DLL "libintl.dll"
@@ -436,6 +514,7 @@ static char *null_libintl_ngettext(const char *, const char *, unsigned long n);
436514static char * null_libintl_textdomain (const char * );
437515static char * null_libintl_bindtextdomain (const char * , const char * );
438516static char * null_libintl_bind_textdomain_codeset (const char * , const char * );
517+ static int null_libintl_putenv (const char * );
439518
440519static HINSTANCE hLibintlDLL = NULL ;
441520char * (* dyn_libintl_gettext )(const char * ) = null_libintl_gettext ;
@@ -446,6 +525,7 @@ char *(*dyn_libintl_bindtextdomain)(const char *, const char *)
446525 = null_libintl_bindtextdomain ;
447526char * (* dyn_libintl_bind_textdomain_codeset )(const char * , const char * )
448527 = null_libintl_bind_textdomain_codeset ;
528+ int (* dyn_libintl_putenv )(const char * ) = null_libintl_putenv ;
449529
450530 int
451531dyn_libintl_init (void )
@@ -463,6 +543,7 @@ dyn_libintl_init(void)
463543 {"bindtextdomain" , (FARPROC * )& dyn_libintl_bindtextdomain },
464544 {NULL , NULL }
465545 };
546+ HINSTANCE hmsvcrt ;
466547
467548 /* No need to initialize twice. */
468549 if (hLibintlDLL )
@@ -507,6 +588,13 @@ dyn_libintl_init(void)
507588 dyn_libintl_bind_textdomain_codeset =
508589 null_libintl_bind_textdomain_codeset ;
509590
591+ /* _putenv() function for the libintl.dll is optional. */
592+ hmsvcrt = find_imported_module_by_funcname (hLibintlDLL , "getenv" );
593+ if (hmsvcrt != NULL )
594+ dyn_libintl_putenv = (void * )GetProcAddress (hmsvcrt , "_putenv" );
595+ if (dyn_libintl_putenv == NULL || dyn_libintl_putenv == putenv )
596+ dyn_libintl_putenv = null_libintl_putenv ;
597+
510598 return 1 ;
511599}
512600
@@ -521,6 +609,7 @@ dyn_libintl_end(void)
521609 dyn_libintl_textdomain = null_libintl_textdomain ;
522610 dyn_libintl_bindtextdomain = null_libintl_bindtextdomain ;
523611 dyn_libintl_bind_textdomain_codeset = null_libintl_bind_textdomain_codeset ;
612+ dyn_libintl_putenv = null_libintl_putenv ;
524613}
525614
526615/*ARGSUSED*/
@@ -562,6 +651,13 @@ null_libintl_textdomain(const char *domainname)
562651 return NULL ;
563652}
564653
654+ /*ARGSUSED*/
655+ int
656+ null_libintl_putenv (const char * envstring )
657+ {
658+ return 0 ;
659+ }
660+
565661#endif /* DYNAMIC_GETTEXT */
566662
567663/* This symbol is not defined in older versions of the SDK or Visual C++ */
@@ -4781,32 +4877,32 @@ mch_call_shell(
47814877#if defined(FEAT_JOB_CHANNEL ) || defined(PROTO )
47824878 static HANDLE
47834879job_io_file_open (
4784- char_u * fname ,
4785- DWORD dwDesiredAccess ,
4786- DWORD dwShareMode ,
4787- LPSECURITY_ATTRIBUTES lpSecurityAttributes ,
4788- DWORD dwCreationDisposition ,
4789- DWORD dwFlagsAndAttributes )
4880+ char_u * fname ,
4881+ DWORD dwDesiredAccess ,
4882+ DWORD dwShareMode ,
4883+ LPSECURITY_ATTRIBUTES lpSecurityAttributes ,
4884+ DWORD dwCreationDisposition ,
4885+ DWORD dwFlagsAndAttributes )
47904886{
47914887 HANDLE h ;
47924888# ifdef FEAT_MBYTE
47934889 WCHAR * wn = NULL ;
47944890 if (enc_codepage >= 0 && (int )GetACP () != enc_codepage )
47954891 {
4796- wn = enc_to_utf16 (fname , NULL );
4797- if (wn != NULL )
4798- {
4799- h = CreateFileW (wn , dwDesiredAccess , dwShareMode ,
4800- lpSecurityAttributes , dwCreationDisposition ,
4801- dwFlagsAndAttributes , NULL );
4802- vim_free (wn );
4803- }
4892+ wn = enc_to_utf16 (fname , NULL );
4893+ if (wn != NULL )
4894+ {
4895+ h = CreateFileW (wn , dwDesiredAccess , dwShareMode ,
4896+ lpSecurityAttributes , dwCreationDisposition ,
4897+ dwFlagsAndAttributes , NULL );
4898+ vim_free (wn );
4899+ }
48044900 }
48054901 if (wn == NULL )
48064902# endif
4807- h = CreateFile ((LPCSTR )fname , dwDesiredAccess , dwShareMode ,
4808- lpSecurityAttributes , dwCreationDisposition ,
4809- dwFlagsAndAttributes , NULL );
4903+ h = CreateFile ((LPCSTR )fname , dwDesiredAccess , dwShareMode ,
4904+ lpSecurityAttributes , dwCreationDisposition ,
4905+ dwFlagsAndAttributes , NULL );
48104906 return h ;
48114907}
48124908
0 commit comments