Skip to content

Commit 1b80601

Browse files
committed
add clang-format
1 parent f3d0a33 commit 1b80601

File tree

3 files changed

+65
-55
lines changed

3 files changed

+65
-55
lines changed

.clang-format

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BasedOnStyle: WebKit
2+
PointerAlignment: Right

tlog.c

+37-36
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <dirent.h>
1111
#include <errno.h>
1212
#include <fcntl.h>
13+
#include <libgen.h>
1314
#include <limits.h>
1415
#include <pthread.h>
1516
#include <stdarg.h>
@@ -21,7 +22,6 @@
2122
#include <sys/time.h>
2223
#include <sys/types.h>
2324
#include <sys/wait.h>
24-
#include <libgen.h>
2525
#include <unistd.h>
2626

2727
#ifndef likely
@@ -103,13 +103,13 @@ struct tlog_segment_log_head {
103103
struct tlog_loginfo info;
104104
unsigned short len;
105105
char data[0];
106-
} __attribute__((packed));
106+
} __attribute__((packed));
107107

108108
struct tlog_segment_head {
109109
unsigned int magic;
110110
unsigned short len;
111111
char data[0];
112-
} __attribute__((packed));
112+
} __attribute__((packed));
113113

114114
struct oldest_log {
115115
char name[TLOG_LOG_NAME_LEN];
@@ -172,8 +172,8 @@ static int _tlog_mkdir(const char *path)
172172
if (access(path, F_OK) == 0) {
173173
return 0;
174174
}
175-
176-
while(*path == ' ' && *path != '\0') {
175+
176+
while (*path == ' ' && *path != '\0') {
177177
path++;
178178
}
179179

@@ -297,10 +297,10 @@ void tlog_set_maxline_size(struct tlog_log *log, int size)
297297

298298
if (size < TLOG_MIN_LINE_SIZE_SET) {
299299
size = TLOG_MIN_LINE_SIZE_SET;
300-
} else if ( size > TLOG_MAX_LINE_SIZE_SET) {
300+
} else if (size > TLOG_MAX_LINE_SIZE_SET) {
301301
size = TLOG_MAX_LINE_SIZE_SET;
302-
}
303-
302+
}
303+
304304
log->max_line_size = size;
305305
}
306306

@@ -309,7 +309,8 @@ int tlog_localtime(struct tlog_time *tm)
309309
return _tlog_gettime(tm);
310310
}
311311

312-
tlog_log *tlog_get_root() {
312+
tlog_log *tlog_get_root()
313+
{
313314
return tlog.root;
314315
}
315316

@@ -336,19 +337,19 @@ static int _tlog_format(char *buff, int maxlen, struct tlog_loginfo *info, void
336337
int len = 0;
337338
int total_len = 0;
338339
struct tlog_time *tm = &info->time;
339-
void* unused __attribute__ ((unused));
340+
void *unused __attribute__((unused));
340341

341342
unused = userptr;
342343

343344
if (tlog.root->multi_log) {
344345
/* format prefix */
345-
len = snprintf(buff, maxlen, "[%.4d-%.2d-%.2d %.2d:%.2d:%.2d,%.3d][%5d][%4s][%17s:%-4d] ",
346-
tm->year, tm->mon, tm->mday, tm->hour, tm->min, tm->sec, tm->usec / 1000, getpid(),
346+
len = snprintf(buff, maxlen, "[%.4d-%.2d-%.2d %.2d:%.2d:%.2d,%.3d][%5d][%4s][%17s:%-4d] ",
347+
tm->year, tm->mon, tm->mday, tm->hour, tm->min, tm->sec, tm->usec / 1000, getpid(),
347348
tlog_get_level_string(info->level), info->file, info->line);
348349
} else {
349350
/* format prefix */
350-
len = snprintf(buff, maxlen, "[%.4d-%.2d-%.2d %.2d:%.2d:%.2d,%.3d][%5s][%17s:%-4d] ",
351-
tm->year, tm->mon, tm->mday, tm->hour, tm->min, tm->sec, tm->usec / 1000,
351+
len = snprintf(buff, maxlen, "[%.4d-%.2d-%.2d %.2d:%.2d:%.2d,%.3d][%5s][%17s:%-4d] ",
352+
tm->year, tm->mon, tm->mday, tm->hour, tm->min, tm->sec, tm->usec / 1000,
352353
tlog_get_level_string(info->level), info->file, info->line);
353354
}
354355

@@ -384,7 +385,7 @@ static int _tlog_root_log_buffer(char *buff, int maxlen, void *userptr, const ch
384385
}
385386

386387
if (tlog.root->segment_log) {
387-
log_head = (struct tlog_segment_log_head *) buff;
388+
log_head = (struct tlog_segment_log_head *)buff;
388389
len += sizeof(*log_head);
389390
memcpy(&log_head->info, &info_inter->info, sizeof(log_head->info));
390391
}
@@ -425,7 +426,7 @@ static int _tlog_print_buffer(char *buff, int maxlen, void *userptr, const char
425426
{
426427
int len;
427428
int total_len = 0;
428-
void* unused __attribute__ ((unused));
429+
void *unused __attribute__((unused));
429430

430431
unused = userptr;
431432

@@ -527,7 +528,7 @@ static int _tlog_vprintf(struct tlog_log *log, vprint_callback print_callback, v
527528
pthread_mutex_unlock(&tlog.lock);
528529
return -1;
529530
}
530-
531+
531532
pthread_mutex_unlock(&tlog.lock);
532533
pthread_mutex_lock(&log->lock);
533534
log->waiters++;
@@ -587,12 +588,12 @@ int tlog_printf(struct tlog_log *log, const char *format, ...)
587588
return len;
588589
}
589590

590-
static int _tlog_early_print(const char *format, va_list ap)
591+
static int _tlog_early_print(const char *format, va_list ap)
591592
{
592593
char log_buf[TLOG_MAX_LINE_LEN];
593594
size_t len = 0;
594595
size_t out_len = 0;
595-
int unused __attribute__ ((unused));
596+
int unused __attribute__((unused));
596597

597598
if (tlog_disable_early_print) {
598599
return 0;
@@ -668,13 +669,13 @@ static int _tlog_rename_logfile(struct tlog_log *log, const char *log_file)
668669
return -1;
669670
}
670671

671-
snprintf(archive_file, sizeof(archive_file), "%s/%s-%.4d%.2d%.2d-%.2d%.2d%.2d%s",
672+
snprintf(archive_file, sizeof(archive_file), "%s/%s-%.4d%.2d%.2d-%.2d%.2d%.2d%s",
672673
log->logdir, log->logname, logtime.year, logtime.mon, logtime.mday,
673674
logtime.hour, logtime.min, logtime.sec, log->suffix);
674675

675676
while (access(archive_file, F_OK) == 0) {
676677
i++;
677-
snprintf(archive_file, sizeof(archive_file), "%s/%s-%.4d%.2d%.2d-%.2d%.2d%.2d-%d%s",
678+
snprintf(archive_file, sizeof(archive_file), "%s/%s-%.4d%.2d%.2d-%.2d%.2d%.2d-%d%s",
678679
log->logdir, log->logname, logtime.year, logtime.mon,
679680
logtime.mday, logtime.hour, logtime.min, logtime.sec, i, log->suffix);
680681
}
@@ -691,7 +692,7 @@ static int _tlog_list_dir(const char *path, list_callback callback, void *userpt
691692
DIR *dir = NULL;
692693
struct dirent *ent;
693694
int ret = 0;
694-
const char* unused __attribute__ ((unused)) = path;
695+
const char *unused __attribute__((unused)) = path;
695696

696697
dir = opendir(path);
697698
if (dir == NULL) {
@@ -724,7 +725,7 @@ static int _tlog_count_log_callback(const char *path, struct dirent *entry, void
724725
struct count_log *count_log = (struct count_log *)userptr;
725726
struct tlog_log *log = count_log->log;
726727
char logname[TLOG_LOG_NAME_LEN * 2];
727-
const char* unused __attribute__ ((unused)) = path;
728+
const char *unused __attribute__((unused)) = path;
728729

729730
if (strstr(entry->d_name, log->suffix) == NULL) {
730731
return 0;
@@ -1064,14 +1065,14 @@ void _tlog_get_log_name_dir(struct tlog_log *log)
10641065
strncpy(log_file, log->pending_logfile, PATH_MAX);
10651066
log_file[sizeof(log_file) - 1] = '\0';
10661067
strncpy(log->logname, basename(log_file), sizeof(log->logname));
1067-
log->logname[sizeof(log->logname) - 1] = '\0';
1068+
log->logname[sizeof(log->logname) - 1] = '\0';
10681069
pthread_mutex_unlock(&tlog.lock);
10691070
}
10701071

10711072
static int _tlog_write(struct tlog_log *log, const char *buff, int bufflen)
10721073
{
10731074
int len;
1074-
int unused __attribute__ ((unused));
1075+
int unused __attribute__((unused));
10751076

10761077
if (bufflen <= 0 || log->fail) {
10771078
return 0;
@@ -1082,7 +1083,7 @@ static int _tlog_write(struct tlog_log *log, const char *buff, int bufflen)
10821083
log->rename_pending = 0;
10831084
}
10841085

1085-
/* output log to screen */
1086+
/* output log to screen */
10861087
if (log->logscreen) {
10871088
unused = write(STDOUT_FILENO, buff, bufflen);
10881089
}
@@ -1181,7 +1182,6 @@ static int _tlog_any_has_data_locked(void)
11811182
return 0;
11821183
}
11831184

1184-
11851185
static int _tlog_any_has_data(void)
11861186
{
11871187
int ret = 0;
@@ -1212,7 +1212,7 @@ static int _tlog_wait_pids(void)
12121212
continue;
12131213
}
12141214

1215-
last_log = next;
1215+
last_log = next;
12161216
next->last_waitpid = now;
12171217
pthread_mutex_unlock(&tlog.lock);
12181218
_tlog_wait_pid(next, 0);
@@ -1313,7 +1313,6 @@ static void _tlog_wakeup_waiters(struct tlog_log *log)
13131313
pthread_mutex_unlock(&log->lock);
13141314
}
13151315

1316-
13171316
static void _tlog_write_one_segment_log(struct tlog_log *log, char *buff, int bufflen)
13181317
{
13191318
struct tlog_segment_head *segment_head = NULL;
@@ -1395,10 +1394,10 @@ static void *_tlog_work(void *arg)
13951394
int log_dropped = 0;
13961395
struct tlog_log *log = NULL;
13971396
struct tlog_log *loop_log = NULL;
1398-
void* unused __attribute__ ((unused));
1397+
void *unused __attribute__((unused));
13991398

14001399
unused = arg;
1401-
1400+
14021401
while (1) {
14031402
log_len = 0;
14041403
log_extlen = 0;
@@ -1480,7 +1479,7 @@ static void *_tlog_work(void *arg)
14801479

14811480
void tlog_set_early_printf(int enable)
14821481
{
1483-
tlog_disable_early_print = (enable == 0) ? 1 : 0;
1482+
tlog_disable_early_print = (enable == 0) ? 1 : 0;
14841483
}
14851484

14861485
const char *tlog_get_level_string(tlog_level level)
@@ -1662,23 +1661,26 @@ void tlog_rename_logfile(struct tlog_log *log, const char *logfile)
16621661
log->rename_pending = 1;
16631662
}
16641663

1665-
static void tlog_fork_prepare() {
1664+
static void tlog_fork_prepare()
1665+
{
16661666
if (tlog.root == NULL) {
16671667
return;
16681668
}
16691669

16701670
pthread_mutex_lock(&tlog.lock);
16711671
}
16721672

1673-
static void tlog_fork_parent() {
1673+
static void tlog_fork_parent()
1674+
{
16741675
if (tlog.root == NULL) {
16751676
return;
16761677
}
16771678

16781679
pthread_mutex_unlock(&tlog.lock);
16791680
}
16801681

1681-
static void tlog_fork_child() {
1682+
static void tlog_fork_child()
1683+
{
16821684
pthread_attr_t attr;
16831685
tlog_log *next;
16841686
if (tlog.root == NULL) {
@@ -1701,7 +1703,6 @@ static void tlog_fork_child() {
17011703
}
17021704
out:
17031705
pthread_mutex_unlock(&tlog.lock);
1704-
17051706
}
17061707

17071708
int tlog_init(const char *logfile, int maxlogsize, int maxlogcount, int buffsize, unsigned int flag)

0 commit comments

Comments
 (0)