Skip to content

Commit e275840

Browse files
committed
Fix compiler warnings
1 parent 60aa054 commit e275840

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

tlog.c

+24-11
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct tlog {
9494
};
9595

9696
struct tlog_segment_log_head {
97-
struct tlog_info info;
97+
struct tlog_loginfo info;
9898
unsigned short len;
9999
char data[0];
100100
} __attribute__((packed));
@@ -117,7 +117,7 @@ struct count_log {
117117
};
118118

119119
struct tlog_info_inter {
120-
struct tlog_info info;
120+
struct tlog_loginfo info;
121121
void *userptr;
122122
};
123123

@@ -203,8 +203,8 @@ static int _tlog_mkdir(const char *path)
203203

204204
static struct tm *_tlog_localtime(time_t *timep, struct tm *tm)
205205
{
206-
static time_t last_time = {0};
207-
static struct tm last_tm = {0};
206+
static time_t last_time;
207+
static struct tm last_tm;
208208

209209
/* localtime_r has a global timezone lock, it's about 8 times slower than gmtime
210210
* this code is used to speed up localtime_r call.
@@ -297,11 +297,14 @@ void *tlog_get_private(tlog_log *log)
297297
return log->private_data;
298298
}
299299

300-
static int _tlog_format(char *buff, int maxlen, struct tlog_info *info, void *userptr, const char *format, va_list ap)
300+
static int _tlog_format(char *buff, int maxlen, struct tlog_loginfo *info, void *userptr, const char *format, va_list ap)
301301
{
302302
int len = 0;
303303
int total_len = 0;
304304
struct tlog_time *tm = &info->time;
305+
void* unused __attribute__ ((unused));
306+
307+
unused = userptr;
305308

306309
if (tlog.root->multi_log) {
307310
/* format prefix */
@@ -388,6 +391,9 @@ static int _tlog_print_buffer(char *buff, int maxlen, void *userptr, const char
388391
{
389392
int len;
390393
int total_len = 0;
394+
void* unused __attribute__ ((unused));
395+
396+
unused = userptr;
391397

392398
/* format log message */
393399
len = vsnprintf(buff, maxlen, format, ap);
@@ -550,8 +556,9 @@ int tlog_printf(struct tlog_log *log, const char *format, ...)
550556
static int _tlog_early_print(const char *format, va_list ap)
551557
{
552558
char log_buf[TLOG_MAX_LINE_LEN];
553-
int len = 0;
554-
int out_len = 0;
559+
size_t len = 0;
560+
size_t out_len = 0;
561+
int unused __attribute__ ((unused));
555562

556563
if (tlog_disable_early_print) {
557564
return 0;
@@ -565,9 +572,9 @@ static int _tlog_early_print(const char *format, va_list ap)
565572
out_len = sizeof(log_buf);
566573
}
567574

568-
write(STDOUT_FILENO, log_buf, out_len);
575+
unused = write(STDOUT_FILENO, log_buf, out_len);
569576
if (log_buf[out_len - 1] != '\n') {
570-
write(STDOUT_FILENO, "\n", 1);
577+
unused = write(STDOUT_FILENO, "\n", 1);
571578
}
572579

573580
return len;
@@ -650,6 +657,7 @@ static int _tlog_list_dir(const char *path, list_callback callback, void *userpt
650657
DIR *dir = NULL;
651658
struct dirent *ent;
652659
int ret = 0;
660+
const char* unused __attribute__ ((unused)) = path;
653661

654662
dir = opendir(path);
655663
if (dir == NULL) {
@@ -682,6 +690,7 @@ static int _tlog_count_log_callback(const char *path, struct dirent *entry, void
682690
struct count_log *count_log = (struct count_log *)userptr;
683691
struct tlog_log *log = count_log->log;
684692
char logname[TLOG_LOG_NAME_LEN * 2];
693+
const char* unused __attribute__ ((unused)) = path;
685694

686695
if (strstr(entry->d_name, log->suffix) == NULL) {
687696
return 0;
@@ -1008,14 +1017,15 @@ static int _tlog_archive_log(struct tlog_log *log)
10081017
static int _tlog_write(struct tlog_log *log, const char *buff, int bufflen)
10091018
{
10101019
int len;
1020+
int unused __attribute__ ((unused));
10111021

10121022
if (bufflen <= 0) {
10131023
return 0;
10141024
}
10151025

10161026
/* output log to screen */
10171027
if (log->logscreen) {
1018-
write(STDOUT_FILENO, buff, bufflen);
1028+
unused = write(STDOUT_FILENO, buff, bufflen);
10191029
}
10201030

10211031
/* if log file size exceeds threshold, start to compress */
@@ -1027,7 +1037,7 @@ static int _tlog_write(struct tlog_log *log, const char *buff, int bufflen)
10271037
if (log->filesize < lseek(log->fd, 0, SEEK_END) && log->multi_log == 0) {
10281038
const char *msg = "[Auto enable multi-process write mode, log may be lost, please enable multi-process write mode manually]\n";
10291039
log->multi_log = 1;
1030-
write(log->fd, msg, strlen(msg));
1040+
unused = write(log->fd, msg, strlen(msg));
10311041
}
10321042
close(log->fd);
10331043
log->fd = -1;
@@ -1326,7 +1336,10 @@ static void *_tlog_work(void *arg)
13261336
int log_dropped = 0;
13271337
struct tlog_log *log = NULL;
13281338
struct tlog_log *loop_log = NULL;
1339+
void* unused __attribute__ ((unused));
13291340

1341+
unused = arg;
1342+
13301343
while (1) {
13311344
log_len = 0;
13321345
log_extlen = 0;

tlog.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct tlog_time {
6060
/* enable log to screen */
6161
#define TLOG_SCREEN (1 << 4)
6262

63-
struct tlog_info {
63+
struct tlog_loginfo {
6464
tlog_level level;
6565
const char *file;
6666
const char *func;
@@ -121,13 +121,13 @@ customize log output format
121121
122122
read _tlog_format for example.
123123
*/
124-
typedef int (*tlog_format_func)(char *buff, int maxlen, struct tlog_info *info, void *userptr, const char *format, va_list ap);
124+
typedef int (*tlog_format_func)(char *buff, int maxlen, struct tlog_loginfo *info, void *userptr, const char *format, va_list ap);
125125
extern int tlog_reg_format_func(tlog_format_func func);
126126

127127
/* register log output callback
128128
Note: info is invalid when flag TLOG_SEGMENT is not set.
129129
*/
130-
typedef int (*tlog_log_output_func)(struct tlog_info *info, const char *buff, int bufflen, void *private_data);
130+
typedef int (*tlog_log_output_func)(struct tlog_loginfo *info, const char *buff, int bufflen, void *private_data);
131131
extern int tlog_reg_log_output_func(tlog_log_output_func output, void *private_data);
132132

133133
struct tlog_log;
@@ -140,7 +140,7 @@ maxlogcount: Number of archived logs.
140140
buffsize: Buffer size, zero for default (128K)
141141
flag: read tlog flags
142142
return: log stream handler.
143-
*/
143+
*/
144144
extern tlog_log *tlog_open(const char *logfile, int maxlogsize, int maxlogcount, int buffsize, unsigned int flag);
145145

146146
/* write buff to log file */

0 commit comments

Comments
 (0)