Exemplo n.º 1
0
/*
 * Handle a preprocessor line. Extract and return filename if it is a linemarker line.
 */
static int handle_preprocessor_line(FILE *fp, char **filename)
{
    int c, line;

    if (fscanf(fp, "%d", &line) == 1) {
        /* Seems to be a line marker. Try to find a filename. */

        while ((c = fgetc(fp)) != EOF && c != '"' && c != '\n');

        if (c == '"') {
            Buffer buffer = { 0 };

            handle_string(fp, &buffer, '"');
            free(*filename);
            *filename = bufDetach(&buffer);

            bufReset(&buffer);
        }
    }

    /* Consume the rest of the line. */

    while (c != EOF && c != '\n') c = fgetc(fp);

    return 0;
}
Exemplo n.º 2
0
/*
 * Add a string defined by <fmt> and the subsequent arguments to log messages.
 */
void logWithString(Logger *logger, const char *fmt, ...)
{
    va_list ap;
    Buffer string = { 0 };

    pthread_mutex_lock(&logger->access);

    LOG_Prefix *prefix = log_add_prefix(logger, LOG_PT_STR);

    va_start(ap, fmt);
    bufSetV(&string, fmt, ap);
    va_end(ap);

    prefix->u.string = bufDetach(&string);

    pthread_mutex_unlock(&logger->access);
}