int try_do_work(const wchar_t* pipe_name, DWORD* exit_code) { DWORD bytes_transferred = 0; RESULT_BLOCK_HEADER header; static wchar_t current_directory[MAX_PATH + 1]; HANDLE h_pipe = CreateFile( pipe_name, GENERIC_READ | GENERIC_WRITE, 0, // no sharing NULL, // default security attributes OPEN_EXISTING, // opens existing pipe 0, // default attributes NULL); // no template file if (h_pipe == INVALID_HANDLE_VALUE) { int last_error = GetLastError(); if (last_error != ERROR_PIPE_BUSY) fprintf(stderr,"Unexpected error during opening pipe. %d\n", GetLastError()); return 0; } if (!GetCurrentDirectory( sizeof(current_directory)/sizeof(current_directory[1]), current_directory)) { fprintf(stderr,"Failed get current directory. %d\n", GetLastError()); return 0; } if (!send_wstring(h_pipe, get_env_variable(L"PATH"))) return 0; if (!send_wstring(h_pipe, get_env_variable(L"INCLUDE"))) return 0; if (!send_wstring(h_pipe, current_directory)) return 0; if (!send_wstring(h_pipe, GetCommandLineW())) { fprintf(stderr, "Failed send command line\n"); return 0; } if (!ReadFile( h_pipe, &header, sizeof(header), &bytes_transferred, NULL)) { fprintf(stderr, "Unexpected error during reading from pipe %d.\n", GetLastError()); return 0; } *exit_code = header.exit_code; if (!transfer_to_std_handle(h_pipe, header.stdout_length, STD_OUTPUT_HANDLE)) return 0; if (!transfer_to_std_handle(h_pipe, header.stderr_length, STD_ERROR_HANDLE)) return 0; return 1; }
int debug::debug_level() { static int cached_debug_level = ([]() -> int { std::string lvl = get_env_variable("HL_DEBUG_CODEGEN"); return !lvl.empty() ? atoi(lvl.c_str()) : 0; })(); return cached_debug_level; }
int main(int argc, char* argv[]) { static wchar_t pipe_name[BUFFER_SIZE]; int i = 0; int exit_code = 0; const wchar_t* clcache_dir = NULL; clcache_dir = get_env_variable(L"CLCACHE_DIR"); if (clcache_dir[0] == 0) { fprintf(stderr, "Failed get CLCACHE_DIR environment variable.\n"); return 1; } if (!generate_pipe_name(pipe_name, clcache_dir)) { fprintf(stderr,"CLCACHE_DIR Too large.\n"); return 1; } while(1) { if (try_do_work(pipe_name, &exit_code)) { return exit_code; } if (!WaitNamedPipe(pipe_name, NMPWAIT_WAIT_FOREVER)) { fprintf(stderr,"Failed wait for named pipe. Error %d\n", GetLastError()); return -1; } } return 0; }
int handle_dollar(t_expander *exp) { char *s; s = exp->tmp + 1; if (!*s) return (append(exp)); else if (*s == '?') return (get_exit_status(exp)); else if (*s == '$') return (get_process_pid(exp)); else if (*s == '0') return (get_shell_name(exp)); else return (get_env_variable(exp, s)); }