Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jun 16, 2024

Conversation

michaelortmann
Copy link
Member

@michaelortmann michaelortmann commented Jun 16, 2024

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 thommey merged commit 95f630e into eggheads:develop Jun 16, 2024
11 of 12 checks passed
@thommey
Copy link
Member

thommey commented Jun 16, 2024

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.

@michaelortmann michaelortmann deleted the fix.time.posix branch June 16, 2024 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants