static int GIT_FORMAT_PRINTF(2, 3) cl_setenv_printf(const char *name, const char *fmt, ...) { int ret; va_list args; git_buf buf = GIT_BUF_INIT; va_start(args, fmt); cl_git_pass(git_buf_vprintf(&buf, fmt, args)); va_end(args); ret = cl_setenv(name, git_buf_cstr(&buf)); git_buf_free(&buf); return ret; }
void giterr_set(int error_class, const char *string, ...) { git_buf buf = GIT_BUF_INIT; va_list arglist; #ifdef GIT_WIN32 DWORD win32_error_code = (error_class == GITERR_OS) ? GetLastError() : 0; #endif int error_code = (error_class == GITERR_OS) ? errno : 0; va_start(arglist, string); git_buf_vprintf(&buf, string, arglist); va_end(arglist); if (error_class == GITERR_OS) { #ifdef GIT_WIN32 if (win32_error_code) { char *lpMsgBuf; if (FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, win32_error_code, 0, (LPSTR)&lpMsgBuf, 0, NULL)) { git_buf_PUTS(&buf, ": "); git_buf_puts(&buf, lpMsgBuf); LocalFree(lpMsgBuf); } SetLastError(0); } else #endif if (error_code) { git_buf_PUTS(&buf, ": "); git_buf_puts(&buf, strerror(error_code)); } if (error_code) errno = 0; } if (!git_buf_oom(&buf)) set_error(error_class, git_buf_detach(&buf)); }
static int rebase_setupfile(git_rebase *rebase, const char *filename, int flags, const char *fmt, ...) { git_buf path = GIT_BUF_INIT, contents = GIT_BUF_INIT; va_list ap; int error; va_start(ap, fmt); git_buf_vprintf(&contents, fmt, ap); va_end(ap); if ((error = git_buf_joinpath(&path, rebase->state_path, filename)) == 0) error = git_futils_writebuffer(&contents, path.ptr, flags, REBASE_FILE_MODE); git_buf_free(&path); git_buf_free(&contents); return error; }
void git_error_set(int error_class, const char *string, ...) { va_list arglist; #ifdef GIT_WIN32 DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0; #endif int error_code = (error_class == GIT_ERROR_OS) ? errno : 0; git_buf *buf = &GIT_GLOBAL->error_buf; git_buf_clear(buf); if (string) { va_start(arglist, string); git_buf_vprintf(buf, string, arglist); va_end(arglist); if (error_class == GIT_ERROR_OS) git_buf_PUTS(buf, ": "); } if (error_class == GIT_ERROR_OS) { #ifdef GIT_WIN32 char * win32_error = git_win32_get_error_message(win32_error_code); if (win32_error) { git_buf_puts(buf, win32_error); git__free(win32_error); SetLastError(0); } else #endif if (error_code) git_buf_puts(buf, strerror(error_code)); if (error_code) errno = 0; } if (!git_buf_oom(buf)) set_error_from_buffer(error_class); }