void logputs (enum log_options o, const char *s) { FILE *fp; FILE *warcfp; check_redirect_output (); if (o == LOG_PROGRESS) fp = get_progress_fp (); else fp = get_log_fp (); if (fp == NULL) return; warcfp = get_warc_log_fp (); CHECK_VERBOSE (o); FPUTS (s, fp); if (warcfp != NULL) FPUTS (s, warcfp); if (save_context_p) saved_append (s); if (flush_log_p) logflush (); else needs_flushing = true; }
void logputs (enum log_options o, const char *s) { FILE *fp; check_redirect_output (); if ((fp = get_log_fp ()) == NULL) return; CHECK_VERBOSE (o); FPUTS (s, fp); if (save_context_p) saved_append (s); if (flush_log_p) logflush (); else needs_flushing = true; }
static bool log_vprintf_internal (struct logvprintf_state *state, const char *fmt, va_list args) { char smallmsg[128]; char *write_ptr = smallmsg; int available_size = sizeof (smallmsg); int numwritten; FILE *fp = get_log_fp (); if (!save_context_p) { /* In the simple case just call vfprintf(), to avoid needless allocation and games with vsnprintf(). */ vfprintf (fp, fmt, args); goto flush; } if (state->allocated != 0) { write_ptr = state->bigmsg; available_size = state->allocated; } /* The GNU coding standards advise not to rely on the return value of sprintf(). However, vsnprintf() is a relatively new function missing from legacy systems. Therefore I consider it safe to assume that its return value is meaningful. On the systems where vsnprintf() is not available, we use the implementation from snprintf.c which does return the correct value. */ numwritten = vsnprintf (write_ptr, available_size, fmt, args); /* vsnprintf() will not step over the limit given by available_size. If it fails, it returns either -1 (older implementations) or the number of characters (not counting the terminating \0) that *would have* been written if there had been enough room (C99). In the former case, we double available_size and malloc to get a larger buffer, and try again. In the latter case, we use the returned information to build a buffer of the correct size. */ if (numwritten == -1) { /* Writing failed, and we don't know the needed size. Try again with doubled size. */ int newsize = available_size << 1; state->bigmsg = xrealloc (state->bigmsg, newsize); state->allocated = newsize; return false; } else if (numwritten >= available_size) { /* Writing failed, but we know exactly how much space we need. */ int newsize = numwritten + 1; state->bigmsg = xrealloc (state->bigmsg, newsize); state->allocated = newsize; return false; } /* Writing succeeded. */ saved_append (write_ptr); FPUTS (write_ptr, fp); if (state->bigmsg) xfree (state->bigmsg); flush: if (flush_log_p) logflush (); else needs_flushing = true; return true; }