eggheads / eggdrop

The Eggdrop IRC Bot
GNU General Public License v2.0
494 stars 88 forks source link

Fix include sys/time.h and time.h. Both are POSIX 2001 #1619

Closed michaelortmann closed 2 weeks ago

michaelortmann commented 2 weeks ago

Found by: thommey Patch by: michaelortmann Fixes:

One-line summary: Fix include sys/time.h and time.h. Both are POSIX 2001

Additional description (if needed): Please run misc/runautotools when merging this PR

Test cases demonstrating functionality (if applicable): The following bug is fixed by this PR:

$ ./configure --disable-tls --disable-tdns
$ make config
$ make

Making core eggdrop files...

make[1]: Entering directory '/home/michael/projects/eggdrop/src'
gcc -g -O2 -pipe -Wall -I.. -I..  -DHAVE_CONFIG_H -I/usr/include -g3 -DDEBUG -DDEBUG_ASSERT -DDEBUG_MEM -DDEBUG_DNS  -c bg.c
In file included from main.h:88,
                 from bg.c:25:
tclhash.h:97:37: warning: ‘struct tm’ declared inside parameter list will not be visible outside of this definition or declaration
   97 | void check_tcl_time_and_cron(struct tm *);
      |                                     ^~
gcc -g -O2 -pipe -Wall -I.. -I..  -DHAVE_CONFIG_H -I/usr/include -g3 -DDEBUG -DDEBUG_ASSERT -DDEBUG_MEM -DDEBUG_DNS  -c botcmd.c
In file included from main.h:88,
                 from botcmd.c:25:
tclhash.h:97:37: warning: ‘struct tm’ declared inside parameter list will not be visible outside of this definition or declaration
   97 | void check_tcl_time_and_cron(struct tm *);
      |                                     ^~
gcc -g -O2 -pipe -Wall -I.. -I..  -DHAVE_CONFIG_H -I/usr/include -g3 -DDEBUG -DDEBUG_ASSERT -DDEBUG_MEM -DDEBUG_DNS  -c botmsg.c
In file included from main.h:88,
                 from botmsg.c:27:
tclhash.h:97:37: warning: ‘struct tm’ declared inside parameter list will not be visible outside of this definition or declaration
   97 | void check_tcl_time_and_cron(struct tm *);
      |                                     ^~
gcc -g -O2 -pipe -Wall -I.. -I..  -DHAVE_CONFIG_H -I/usr/include -g3 -DDEBUG -DDEBUG_ASSERT -DDEBUG_MEM -DDEBUG_DNS  -c botnet.c
In file included from main.h:88,
                 from botnet.c:29:
tclhash.h:97:37: warning: ‘struct tm’ declared inside parameter list will not be visible outside of this definition or declaration
   97 | void check_tcl_time_and_cron(struct tm *);
      |                                     ^~
gcc -g -O2 -pipe -Wall -I.. -I..  -DHAVE_CONFIG_H -I/usr/include -g3 -DDEBUG -DDEBUG_ASSERT -DDEBUG_MEM -DDEBUG_DNS  -c chanprog.c
In file included from main.h:88,
                 from chanprog.c:29:
tclhash.h:97:37: warning: ‘struct tm’ declared inside parameter list will not be visible outside of this definition or declaration
   97 | void check_tcl_time_and_cron(struct tm *);
      |                                     ^~
gcc -g -O2 -pipe -Wall -I.. -I..  -DHAVE_CONFIG_H -I/usr/include -g3 -DDEBUG -DDEBUG_ASSERT -DDEBUG_MEM -DDEBUG_DNS  -c cmds.c
In file included from main.h:88,
                 from cmds.c:26:
tclhash.h:97:37: warning: ‘struct tm’ declared inside parameter list will not be visible outside of this definition or declaration
   97 | void check_tcl_time_and_cron(struct tm *);
      |                                     ^~
cmds.c: In function ‘tell_who’:
cmds.c:165:7: error: implicit declaration of function ‘strftime’ [-Wimplicit-function-declaration]
  165 |       strftime(s, 14, "%d %b %H:%M", localtime(&dcc[i].timeval));
      |       ^~~~~~~~
cmds.c:29:1: note: include ‘<time.h>’ or provide a declaration of ‘strftime’
   28 | #include "modules.h"
  +++ |+#include <time.h>
   29 | #include <signal.h>
cmds.c:165:7: warning: incompatible implicit declaration of built-in function ‘strftime’ [-Wbuiltin-declaration-mismatch]
  165 |       strftime(s, 14, "%d %b %H:%M", localtime(&dcc[i].timeval));
      |       ^~~~~~~~
cmds.c:165:7: note: include ‘<time.h>’ or provide a declaration of ‘strftime’
cmds.c:165:38: error: implicit declaration of function ‘localtime’ [-Wimplicit-function-declaration]
  165 |       strftime(s, 14, "%d %b %H:%M", localtime(&dcc[i].timeval));
      |                                      ^~~~~~~~~
cmds.c:165:38: note: ‘localtime’ is defined in header ‘<time.h>’; this is probably fixable by adding ‘#include <time.h>’
cmds.c:165:38: error: passing argument 4 of ‘strftime’ makes pointer from integer without a cast [-Wint-conversion]
  165 |       strftime(s, 14, "%d %b %H:%M", localtime(&dcc[i].timeval));
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                      |
      |                                      int
cmds.c:165:38: note: expected ‘const void *’ but argument is of type ‘int’
make[1]: *** [Makefile:83: cmds.o] Error 1
make[1]: Leaving directory '/home/michael/projects/eggdrop/src'
make: *** [Makefile:251: debug] Error 2

Tested on GNU/Linux, FreeBSD 14.1 and NetBSD 9.3

thommey commented 2 weeks ago

What was broken was --disable-tls and --disable-tdns in combination. ssl.h includes time.h and tdns includes pthread.h which includes time.h so it was implicitely included, but we need to include it unconditionally for our stuff, too.