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 sync_pipe_close(int fd[], const char *name) { int r = 0; if (fd[0] != -1) r = close(fd[0]); if (fd[1] != -1) r |= close(fd[1]); if (name != NULL) { generate_pipe_name(name); unlink(pipe_name); } return r; }
int sync_pipe_create(int fd[], const char *name) { int ret; if (name != NULL) { generate_pipe_name(name); ret = open(pipe_name, O_RDWR); if (ret != -1) { fd[0] = ret; fd[1] = open(pipe_name, O_RDWR); } else { ret = mkfifo(pipe_name, S_IRWXU); if (!ret) { fd[0] = open(pipe_name, O_RDWR); fd[1] = open(pipe_name, O_RDWR); } } return ret; } else return pipe(fd); }