/* * newvstrallocf - free existing string and then vstrallocf a new one. */ char * debug_newvstrallocf( const char *file, int line, char * oldstr, const char *fmt, ...) { size_t size; char * result; va_list argp; result = debug_alloc(file, line, MIN_ALLOC); if (result != NULL) { arglist_start(argp, fmt); size = g_vsnprintf(result, MIN_ALLOC, fmt, argp); arglist_end(argp); if (size >= MIN_ALLOC) { amfree(result); result = debug_alloc(file, line, size + 1); arglist_start(argp, fmt); (void)g_vsnprintf(result, size + 1, fmt, argp); arglist_end(argp); } } amfree(oldstr); return result; }
int dgram_cat(dgram_t *dgram, const char *fmt, ...) { ssize_t bufsize; va_list argp; int len; assert(dgram != NULL); assert(fmt != NULL); assert(dgram->len == (size_t)(dgram->cur - dgram->data)); assert(dgram->len < sizeof(dgram->data)); bufsize = (ssize_t)(sizeof(dgram->data) - dgram->len); if (bufsize <= 0) return -1; arglist_start(argp, fmt); len = g_vsnprintf(dgram->cur, (size_t)bufsize, fmt, argp); arglist_end(argp); if(len < 0) { return -1; } else if((ssize_t)len > bufsize) { dgram->len = sizeof(dgram->data); dgram->cur = dgram->data + dgram->len; return -1; } else { dgram->len += len; dgram->cur = dgram->data + dgram->len; } return 0; }
printf_arglist_function1(void log_add, logtype_t, typ, char *, format) { va_list argp; char *leader = NULL; char *xlated_fmt = gettext(format); char linebuf[STR_SIZE]; size_t n; static gboolean in_log_add = 0; /* avoid recursion */ if (in_log_add) return; /* format error message */ if((int)typ <= (int)L_BOGUS || (int)typ > (int)L_MARKER) typ = L_BOGUS; if(multiline > 0) { leader = stralloc(" "); /* continuation line */ } else { leader = vstralloc(logtype_str[(int)typ], " ", get_pname(), " ", NULL); } arglist_start(argp, format); /* use sizeof(linebuf)-2 to save space for a trailing newline */ g_vsnprintf(linebuf, SIZEOF(linebuf)-2, xlated_fmt, argp); /* -1 to allow for '\n' */ arglist_end(argp); /* avoid recursive call from error() */ in_log_add = 1; /* append message to the log file */ if(multiline == -1) open_log(); if (full_write(logfd, leader, strlen(leader)) < strlen(leader)) { error(_("log file write error: %s"), strerror(errno)); /*NOTREACHED*/ } amfree(leader); /* add a newline if necessary */ n = strlen(linebuf); if(n == 0 || linebuf[n-1] != '\n') linebuf[n++] = '\n'; linebuf[n] = '\0'; if (full_write(logfd, linebuf, n) < n) { error(_("log file write error: %s"), strerror(errno)); /*NOTREACHED*/ } if(multiline != -1) multiline++; else close_log(); in_log_add = 0; }
void log_add_full(logtype_t typ, char *pname, char *format, ...) { va_list argp; arglist_start(argp, format); log_add_full_v(typ, pname, format, argp); arglist_end(argp); }
printf_arglist_function1(void putresult, cmd_t, result, const char *, format) { va_list argp; arglist_start(argp, format); dbprintf(_("putresult: %d %s\n"), result, cmdstr[result]); g_printf("%s ", cmdstr[result]); g_vprintf(format, argp); fflush(stdout); arglist_end(argp); }
static void _xsr_dbg(const char *fmt, ...) { va_list argp; char msg[1024]; arglist_start(argp, fmt); g_vsnprintf(msg, sizeof(msg), fmt, argp); arglist_end(argp); g_debug("XSR: %s", msg); }
static void _xdh_dbg(const char *fmt, ...) { va_list argp; gchar *msg; arglist_start(argp, fmt); msg = g_strdup_vprintf(fmt, argp); arglist_end(argp); g_debug("XDH: %s", msg); g_free(msg); }
void security_stream_seterror(security_stream_t *stream, const char *fmt, ...) { char *buf; va_list argp; arglist_start(argp, fmt); buf = g_strdup_vprintf(fmt, argp); arglist_end(argp); g_free(stream->error); stream->error = buf; g_debug("security_stream_seterr(%p, %s)", stream, stream->error); }
/* * this used to be a function in it's own write but became a wrapper around * pipespawnv to eliminate redundancy... */ pid_t pipespawn( char * prog, int pipedef, int need_root, int * stdinfd, int * stdoutfd, int * stderrfd, ...) { va_list ap; int argc = 0, i; pid_t pid; char **argv; /* count args */ arglist_start(ap, stderrfd); while(arglist_val(ap, char *) != NULL) { argc++; } arglist_end(ap); /* * Create the argument vector. */ arglist_start(ap, stderrfd); argv = (char **)g_malloc((argc + 1) * sizeof(*argv)); i = 0; while((argv[i] = arglist_val(ap, char *)) != NULL) { if (argv[i] != skip_argument) { i++; } } arglist_end(ap); pid = pipespawnv_passwd(prog, pipedef, need_root, stdinfd, stdoutfd, stderrfd, argv); amfree(argv); return pid; }
void putresult(cmd_t result, const char *format, ...) { va_list argp; char *msg; arglist_start(argp, format); msg = g_strdup_vprintf(format, argp); arglist_end(argp); g_debug("putresult: %d %s %s", result, cmdstr[result], msg); g_printf("%s %s", cmdstr[result], msg); fflush(stdout); g_free(msg); }
/* * vstralloc - copies multiple strings into newly allocated memory. */ char * debug_vstralloc( const char *file, int line, const char *str, ...) { va_list argp; char *result; arglist_start(argp, str); result = internal_vstralloc(file, line, str, argp); arglist_end(argp); return result; }
void security_seterror(security_handle_t *handle, const char *fmt, ...) { char *buf; va_list argp; assert(handle->error != NULL); arglist_start(argp, fmt); buf = g_strdup_vprintf(fmt, argp); arglist_end(argp); g_free(handle->error); handle->error = buf; g_debug("security_seterror(handle=%p, driver=%p (%s) error=%s)", handle, handle->driver, handle->driver->name, handle->error); }
/* * newvstralloc - free existing string and then vstralloc a new one. */ char * debug_newvstralloc( const char *file, int line, char * oldstr, const char *newstr, ...) { va_list argp; char *result; arglist_start(argp, newstr); result = internal_vstralloc(file, line, newstr, argp); arglist_end(argp); amfree(oldstr); return result; }
int fdprintf( int fd, char *format, ...) { va_list argp; char *s; int r; arglist_start(argp, format); s = g_strdup_vprintf(format, argp); arglist_end(argp); r = full_write(fd, s, strlen(s)); amfree(s); return r; }
/* vstrextend -- Extends the existing string by appending the other * arguments. */ char * debug_vstrextend( const char *file, int line, char ** oldstr, ...) { char *keep = *oldstr; va_list ap; arglist_start(ap, oldstr); if (*oldstr == NULL) *oldstr = ""; *oldstr = internal_vstralloc(file, line, *oldstr, ap); amfree(keep); arglist_end(ap); return *oldstr; }
printf_arglist_function2(char *log_genstring, logtype_t, typ, char *, pname, char *, format) { va_list argp; char *leader = NULL; char linebuf[STR_SIZE]; char *xlated_fmt = dgettext("C", format); /* format error message */ if((int)typ <= (int)L_BOGUS || (int)typ > (int)L_MARKER) typ = L_BOGUS; if(multiline > 0) { leader = stralloc(" "); /* continuation line */ } else { leader = vstralloc(logtype_str[(int)typ], " ", pname, " ", NULL); } arglist_start(argp, format); g_vsnprintf(linebuf, SIZEOF(linebuf)-1, xlated_fmt, argp); /* -1 to allow for '\n' */ arglist_end(argp); return(vstralloc(leader, linebuf, "\n", NULL)); }