/* fopen by file system codepage */ FILE * fsyscp_fopen (const char *filename, const char *mode) { FILE *f; wchar_t *fnamew, modew[4]; int i; #if defined (KPSE_COMPAT_API) kpathsea kpse; #endif assert(filename && mode); fnamew = get_wstring_from_fsyscp(filename, fnamew=NULL); for(i=0; (modew[i]=(wchar_t)mode[i]); i++) {} /* mode[i] must be ASCII */ f = _wfopen(fnamew, modew); #if defined (KPSE_COMPAT_API) if (f != NULL) { kpse = kpse_def; if (KPATHSEA_DEBUG_P (KPSE_DEBUG_FOPEN)) { DEBUGF_START (); fprintf (stderr, "fsyscp_fopen(%s [", filename); WriteConsoleW( GetStdHandle( STD_ERROR_HANDLE ), fnamew, wcslen( fnamew ), NULL, NULL ); #if defined(_WIN64) fprintf (stderr, "], %s) => 0x%I64x\n", mode, (unsigned __int64) f); #else fprintf (stderr, "], %s) => 0x%lx\n", mode, (unsigned long) f); #endif DEBUGF_END (); } } #endif free(fnamew); return f; }
/* xfopen by file system codepage */ FILE * kpathsea_fsyscp_xfopen (kpathsea kpse, const char *filename, const char *mode) { FILE *f; wchar_t *fnamew, modew[4]; int i; assert(filename && mode); fnamew = get_wstring_from_mbstring(kpse->File_system_codepage, filename, fnamew=NULL); for(i=0; (modew[i]=(wchar_t)mode[i]); i++) {} /* mode[i] must be ASCII */ f = _wfopen(fnamew, modew); if (f == NULL) FATAL_PERROR(filename); if (KPATHSEA_DEBUG_P (KPSE_DEBUG_FOPEN)) { DEBUGF_START (); fprintf (stderr, "fsyscp_xfopen(%s [", filename); WriteConsoleW( GetStdHandle( STD_ERROR_HANDLE ), fnamew, wcslen( fnamew ), NULL, NULL ); #if defined(_WIN64) fprintf (stderr, "], %s) => 0x%I64x\n", mode, (unsigned __int64) f); #else fprintf (stderr, "], %s) => 0x%lx\n", mode, (unsigned long) f); #endif DEBUGF_END (); } free(fnamew); return f; }
FILE * fsyscp_popen (const char *command, const char *mode) { FILE *f; wchar_t *commandw, modew[4]; int i; #if defined (KPSE_COMPAT_API) kpathsea kpse; #endif assert(command && mode); if (is_include_space (command)) { const char *p; char *command2, *q; command2 = xmalloc (strlen (command) + 3); p = command; q = command2; *q++ = '\"'; while (*p) *q++ = *p++; *q++ = '\"'; *q = '\0'; commandw = get_wstring_from_fsyscp(command2, commandw=NULL); free (command2); } else { commandw = get_wstring_from_fsyscp(command, commandw=NULL); } for(i=0; (modew[i]=(wchar_t)mode[i]); i++) {} /* mode[i] must be ASCII */ f = _wpopen(commandw, modew); #if defined (KPSE_COMPAT_API) if (f != NULL) { kpse = kpse_def; if (KPATHSEA_DEBUG_P (KPSE_DEBUG_FOPEN)) { DEBUGF_START (); fprintf (stderr, "fsyscp_popen(%s [", command); WriteConsoleW( GetStdHandle( STD_ERROR_HANDLE ), commandw, wcslen( commandw ), NULL, NULL ); #if defined(_WIN64) fprintf (stderr, "], %s) => 0x%I64x\n", mode, (unsigned __int64) f); #else fprintf (stderr, "], %s) => 0x%lx\n", mode, (unsigned long) f); #endif DEBUGF_END (); } } #endif free (commandw); /* We use always binary mode on Windows */ if(f) _setmode (fileno (f), _O_BINARY); return f; }