int repl_log(FILE *fp, boolean_t stamptime, boolean_t flush, char *fmt, ...) { va_list printargs; char time_str[CTIME_BEFORE_NL + 2]; /* for GET_CUR_TIME macro */ char fmt_str[BUFSIZ]; int rc; assert(NULL != fp); if (stamptime) { GET_CUR_TIME(time_str); strcpy(fmt_str, time_str); fmt_str[CTIME_BEFORE_NL] = ' '; /* Overwrite \n */ fmt_str[CTIME_BEFORE_NL + 1] = ':'; fmt_str[CTIME_BEFORE_NL + 2] = ' '; strcpy(fmt_str + CTIME_BEFORE_NL + 3, fmt); fmt = &fmt_str[0]; } va_start(printargs, fmt); VFPRINTF(fp, fmt, printargs, rc); assert(0 <= rc); va_end(printargs); if (flush) FFLUSH(fp); return(SS_NORMAL); }
void fgWarning( const char *fmt, ... ) { va_list ap; if (fgState.WarningFunc) { va_start( ap, fmt ); /* call user set warning handler here */ fgState.WarningFunc(fmt, ap); va_end( ap ); } else { #ifdef FREEGLUT_PRINT_WARNINGS va_start( ap, fmt ); fprintf( stderr, "freeglut "); if( fgState.ProgramName ) fprintf( stderr, "(%s): ", fgState.ProgramName ); VFPRINTF( stderr, fmt, ap ); fprintf( stderr, "\n" ); va_end( ap ); #endif } }
/* * Error Messages. */ void fgError( const char *fmt, ... ) { va_list ap; if (fgState.ErrorFunc) { va_start( ap, fmt ); /* call user set error handler here */ fgState.ErrorFunc(fmt, ap); va_end( ap ); } else { #ifdef FREEGLUT_PRINT_ERRORS va_start( ap, fmt ); fprintf( stderr, "freeglut "); if( fgState.ProgramName ) fprintf( stderr, "(%s): ", fgState.ProgramName ); VFPRINTF( stderr, fmt, ap ); fprintf( stderr, "\n" ); va_end( ap ); #endif if ( fgState.Initialised ) fgDeinitialize (); exit( 1 ); } }
void CodeFile::listBegin(const char* sep, bool nl, const char* s, ...) { PRINT_INDENT(file_, ind_); VFPRINTF(file_, s); listSep_ = sep; listItemNum_ = 0; listNL_ = nl; }
static void log_v(int priority, const char *fullPath, int line, const char *message, va_list ap) { static int using_terminal = -1; if (using_terminal == -1) { #if defined HAVE_VSYSLOG #if defined HAVE_VFPRINTF && defined HAVE_ISATTY using_terminal = isatty(fileno(stderr)); #else using_terminal = 0; #endif #elif defined HAVE_VFPRINTF using_terminal = 1; #else using_terminal = 0; #endif } #define LOG_PREAMBLE "%s PJSON %s:%d :: " char *pathCopy = strdup(fullPath); char *path = strstr(pathCopy, "src/pjson_c"); if (!path) path = pathCopy; // TODO: memoize the program name string length size_t messageLen = strlen(message) + strlen(path) + 4 /* line number */ + 100 /* chars for message */; const char *programNameToPrint = getConsumerName_internal(); size_t formatLen = messageLen + sizeof(LOG_PREAMBLE) + (using_terminal ? 1 : 0) + strlen(programNameToPrint); char *format = alloca(formatLen); snprintf(format, formatLen, LOG_PREAMBLE "%s%s", programNameToPrint, path, line, message, using_terminal ? "\n" : ""); #if HAVE_VSYSLOG if (LIKELY(!using_terminal)) { vsyslog(priority, format, ap); } else { VFPRINTF(priority, stderr, format, ap); } #elif HAVE_VFPRINTF VFPRINTF(priority, stderr, format, ap); #else #error Logging mechanism not implemented #endif free(pathCopy); }
void CodeFile::listEnd(const char* s, ...) { if(listNL_) { fprintf(file_, "\n"); PRINT_INDENT(file_, ind_); } VFPRINTF(file_, s); fprintf(file_, "\n"); }
/** * fprintf-like helper function for logging debug * messages. */ void MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...) { va_list va; if ((daemon->options & MHD_USE_DEBUG) == 0) return; va_start (va, format); VFPRINTF (stderr, format, va); va_end (va); }
void CodeFile::listItem(const char* s, ...) { if(listItemNum_ > 0) fprintf(file_, "%s", listSep_.c_str()); listItemNum_++; if(listNL_) { fprintf(file_, "\n"); PRINT_INDENT(file_, (ind_+1)); } VFPRINTF(file_, s); }
/* Wrapper for fprintf() - implements signal blocking */ int gtm_fprintf(FILE *stream, const char *format, ...) { va_list printargs; int retval; sigset_t savemask; if (blocksig_initialized) sigprocmask(SIG_BLOCK, &block_sigsent, &savemask); va_start(printargs, format); VFPRINTF(stream, format, printargs, retval); va_end(printargs); if (blocksig_initialized) sigprocmask(SIG_SETMASK, &savemask, NULL); return retval; }
/* Wrapper for fprintf() - implements signal blocking */ int gtm_fprintf(FILE *stream, const char *format, ...) { va_list printargs; int retval; sigset_t savemask; /* Note: cannot use SIGPROCMASK below because this function is used by "gtmsecshr" and using SIGPROCMASK * pulls in a lot of stuff from libgtmshr.so (due to asserts) and we want minimal stuff in "gtmsecshr". */ if (blocksig_initialized) sigprocmask(SIG_BLOCK, &block_sigsent, &savemask); /* BYPASSOK(sigprocmask) */ va_start(printargs, format); VFPRINTF(stream, format, printargs, retval); va_end(printargs); if (blocksig_initialized) sigprocmask(SIG_SETMASK, &savemask, NULL); /* BYPASSOK(sigprocmask) */ return retval; }
/* This is a wrapper for the system "fprintf" and is needed to prevent signal interrupts from occurring in the middle * of fprintf since that is not signal-safe (i.e. not re-entrant). The reason why this is considered okay is that if * the code is anyways ready to do a fprintf(), it should not be in a performance-sensitive area so doing extra work * for signal blocking/unblocking should not be a big issue. */ int gtm_fprintf(FILE *stream, const char *format, ...) { va_list printargs; int retval; sigset_t savemask; /* blocksig_initialized could not be set at this point for a variety of cases such as the following. * 1) If the current image is "dbcertify" * 2) At startup of GTCM_SERVER or GTCM_GNP_SERVER * 3) At startup of GT.M (e.g. bad command line "mumps -bad") * Because of this, we dont have an assert(blocksig_initialized) that similar code in dollarh.c has. */ if (blocksig_initialized) /* In pro, dont take chances and handle case where it is not initialized */ sigprocmask(SIG_BLOCK, &block_sigsent, &savemask); va_start(printargs, format); retval = VFPRINTF(stream, format, printargs); va_end(printargs); if (blocksig_initialized) sigprocmask(SIG_SETMASK, &savemask, NULL); return retval; }
void CodeFile::output(const char* s, ...) { PRINT_INDENT(file_, ind_); VFPRINTF(file_, s); fprintf(file_, "\n"); }