static wchar_t* fix_path_type(void* arg, bool islist, cygwin_conv_path_t convtyp) { const char* cygpath = NULL; wchar_t* result = NULL; size_t szcount = 0, szresult = 0; ssize_t(*conversion_func)(cygwin_conv_path_t, const void*, void*, size_t); // We'll use cygwin to allocate the buffer for the original value. if(!(cygpath = (const char*)cygwin_create_path(convtyp, (const void*)arg))) { FreeLibrary(*phCygwin); *phCygwin = NULL; return NULL; } // Figure out which function to use. if(islist) { conversion_func = cygwin_conv_path_list; } else { conversion_func = cygwin_conv_path; } // Since cygwin allocated our buffer, we can assume it's big enough to hold the output. // For now, though, we'll just use MAX_ENV+1 if(conversion_func(convtyp, (const void*)arg, (void*)cygpath, (MAX_ENV+1) * sizeof(char)) == -1) { cygwin_free((void*)cygpath); FreeLibrary(*phCygwin); *phCygwin = NULL; return NULL; } // Finally, allocate our result buffer. szcount = lstrlenA(cygpath) + 1; szresult = szcount * sizeof(wchar_t); if(!szresult || !(result = (wchar_t*)malloc(szresult))) { cygwin_free((void*)cygpath); FreeLibrary(*phCygwin); *phCygwin = NULL; return NULL; } // Zero out the allocated data. memset((void*)result, 0, szresult); // And convert the char string to our resulting wchar string. mbstowcs(result, cygpath, szcount); // At this point, we can free up the buffer cygwin created. cygwin_free((void*)cygpath); if(!verbose_flag) return result; verbose(L"Converted file path/path list:"); verbose_step(L"fix_path_type(x)"); if(*(((char*)arg) + 1) != '\0') { printf("# [%d] x -> %s\n", verbose_stepi++, arg); } else { verbose_step(L" x -> %s", arg); } verbose_step(L" r <- %s", result); return result; }
static void save_config(void) { #if CYGWIN_VERSION_API_MINOR >= 222 char *filename = cygwin_create_path(CCP_WIN_W_TO_POSIX, rc_filename); FILE *file = fopen(filename, "w"); free(filename); #else FILE *file = fopen(rc_filename, "w"); #endif if (!file) return; for (uint j = 0; j < option_order_len; j++) { uint i = option_order[j]; fprintf(file, "%s=", options[i].name); uint offset = options[i].offset; switch (options[i].type) { when OPT_BOOL: fprintf(file, "%i\n", atoffset(bool, &cfg, offset)); when OPT_INT: fprintf(file, "%i\n", atoffset(int, &cfg, offset)); when OPT_STRING: fprintf(file, "%s\n", &atoffset(char, &cfg, offset)); when OPT_COLOUR: { colour c = atoffset(colour, &cfg, offset); fprintf(file, "%u,%u,%u\n", red(c), green(c), blue(c)); } } } fclose(file); return; }
void printer_finish_job(void) { if (printer) { close(pd); char * wf = (char *)cygwin_create_path(CCP_POSIX_TO_WIN_A, pf); char * pn = cs__wcstoutf(printer); strcpy(strchr(pf, '\0') - 4, ".cmd"); int cmdd = open(pf, O_CREAT | O_TRUNC | O_BINARY | O_WRONLY, 0700); char * cmdformat = "@chcp 65001\r\n@start /min notepad /w /pt \"%s\" \"%s\""; char * cmd = malloc(strlen(cmdformat) - 4 + strlen(wf) + strlen(pn) + 1); sprintf(cmd, cmdformat, wf, pn); write(cmdd, cmd, strlen(cmd)); close(cmdd); system(pf); free(cmd); free(wf); free(pn); free(pf); printer = 0; } }
static char *canonicalize_file_name( const char *fileName ) { auto r = (char*)cygwin_create_path(CCP_WIN_A_TO_POSIX, fileName); if(0==r) { errFatal("can't canonicalize path %s", fileName); } return r; }
void load_config(char *filename) { option_order_len = 0; free(rc_filename); #if CYGWIN_VERSION_API_MINOR >= 222 rc_filename = cygwin_create_path(CCP_POSIX_TO_WIN_W, filename); #else rc_filename = strdup(filename); #endif FILE *file = fopen(filename, "r"); if (file) { char line[256]; while (fgets(line, sizeof line, file)) { line[strcspn(line, "\r\n")] = 0; /* trim newline */ int i = parse_option(line); if (i >= 0 && !memchr(option_order, i, option_order_len)) option_order[option_order_len++] = i; } fclose(file); } }
static void ATTRIBUTE_NORETURN __report_error (const char *msg, ...) { #ifdef __CYGWIN__ /* This function is used to print short error messages * to stderr, which may occur during DLL initialization * while fixing up 'pseudo' relocations. This early, we * may not be able to use cygwin stdio functions, so we * use the win32 WriteFile api. This should work with both * normal win32 console IO handles, redirected ones, and * cygwin ptys. */ char buf[SHORT_MSG_BUF_SZ]; wchar_t module[MAX_PATH]; char * posix_module = NULL; static const char UNKNOWN_MODULE[] = "<unknown module>: "; static const size_t UNKNOWN_MODULE_LEN = sizeof (UNKNOWN_MODULE) - 1; static const char CYGWIN_FAILURE_MSG[] = "Cygwin runtime failure: "; static const size_t CYGWIN_FAILURE_MSG_LEN = sizeof (CYGWIN_FAILURE_MSG) - 1; DWORD len; DWORD done; va_list args; HANDLE errh = GetStdHandle (STD_ERROR_HANDLE); ssize_t modulelen = GetModuleFileNameW (NULL, module, sizeof (module)); if (errh == INVALID_HANDLE_VALUE) cygwin_internal (CW_EXIT_PROCESS, STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION, 1); if (modulelen > 0) posix_module = cygwin_create_path (CCP_WIN_W_TO_POSIX, module); va_start (args, msg); len = (DWORD) vsnprintf (buf, SHORT_MSG_BUF_SZ, msg, args); va_end (args); buf[SHORT_MSG_BUF_SZ-1] = '\0'; /* paranoia */ if (posix_module) { WriteFile (errh, (PCVOID)CYGWIN_FAILURE_MSG, CYGWIN_FAILURE_MSG_LEN, &done, NULL); WriteFile (errh, (PCVOID)posix_module, strlen(posix_module), &done, NULL); WriteFile (errh, (PCVOID)": ", 2, &done, NULL); WriteFile (errh, (PCVOID)buf, len, &done, NULL); free (posix_module); } else { WriteFile (errh, (PCVOID)CYGWIN_FAILURE_MSG, CYGWIN_FAILURE_MSG_LEN, &done, NULL); WriteFile (errh, (PCVOID)UNKNOWN_MODULE, UNKNOWN_MODULE_LEN, &done, NULL); WriteFile (errh, (PCVOID)buf, len, &done, NULL); } WriteFile (errh, (PCVOID)"\n", 1, &done, NULL); cygwin_internal (CW_EXIT_PROCESS, STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION, 1); /* not reached, but silences noreturn warning */ abort (); #else va_list argp; va_start (argp, msg); # ifdef __MINGW64_VERSION_MAJOR fprintf (stderr, "Mingw-w64 runtime failure:\n"); # else fprintf (stderr, "Mingw runtime failure:\n"); # endif vfprintf (stderr, msg, argp); va_end (argp); abort (); #endif }