Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <unistd.h>
#include "mx_log.h"
#include "mx_util.h"
#ifndef mx_free_null
#include <stdlib.h>
#define mx_free_null(a) do { free((a)); (a) = NULL; } while(0)
#endif
static int timetag(char *buf, size_t size)
{
time_t t;
struct tm *ltime;
size_t len;
if(!size)
return -(errno=EINVAL);
*buf = 0;
t = time(NULL);
if (t == ((time_t) -1))
return -errno;
ltime = localtime(&t);
if (ltime == NULL)
return -(errno=EINVAL);
len = strftime(buf, size, "%F %T %z", ltime);
if (!len)
*buf = 0;
return len;
}
int mx_log_print(char *msg, size_t len)
{
char timebuf[1024];
if (!msg) {
return 0;
}
if (!len)
return 0;
timetag(timebuf, sizeof(timebuf));
fprintf(stderr, "%s %s[%d]: %s\n", timebuf, program_invocation_short_name, getpid(), msg);
fflush(stderr);
mx_free_null(msg);
return 1;
}