use c17 std, fix warnings / errors

This commit is contained in:
Stefan Bühler 2021-09-15 18:52:43 +02:00
parent 7e9fbaf5d2
commit 187ec1a68e
10 changed files with 29 additions and 22 deletions

View File

@ -28,9 +28,9 @@ executable(
'src/network.c', 'src/network.c',
'src/sound.c', 'src/sound.c',
'src/utils.c', 'src/utils.c',
# override_options: [ override_options: [
# 'c_std=c11', 'c_std=c17',
# ], ],
install: true, install: true,
dependencies: [ dependencies: [
avahi_client_dep, avahi_client_dep,

View File

@ -38,7 +38,7 @@ gamelistentry gamelistentries[10];
int gamelistsize = 0; int gamelistsize = 0;
static void myerror(AvahiClient *c, const char *s) { static void myerror(AvahiClient *c, const char *s) {
fprintf(stderr, "Error in: %s\n (%s)", s, avahi_strerror(avahi_client_errno(client))); fprintf(stderr, "Error in: %s\n (%s)", s, avahi_strerror(avahi_client_errno(c)));
} }
static void create_services(AvahiClient *c); static void create_services(AvahiClient *c);
@ -119,6 +119,8 @@ fail:
} }
static void client_callback(AvahiClient *c, AvahiClientState state, void * userdata) { static void client_callback(AvahiClient *c, AvahiClientState state, void * userdata) {
(void)userdata;
client = c; client = c;
switch (state) { switch (state) {
case AVAHI_CLIENT_S_RUNNING: case AVAHI_CLIENT_S_RUNNING:
@ -183,6 +185,10 @@ static void resolve_callback(AvahiServiceResolver *r, AvahiIfIndex interface, Av
uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void* userdata) { uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void* userdata) {
int i; int i;
uint32_t want_version; uint32_t want_version;
(void)interface;
(void)host_name;
(void)flags;
(void)userdata;
assert(r); assert(r);
if (protocol != AVAHI_PROTO_INET) goto done; /* ignore non IPv4 for now */ if (protocol != AVAHI_PROTO_INET) goto done; /* ignore non IPv4 for now */
@ -229,6 +235,7 @@ done:
static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event,
const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void* userdata) { const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void* userdata) {
(void)flags;
assert(b); assert(b);

View File

@ -20,16 +20,16 @@
#include "game.h" #include "game.h"
#include "draw.h" #include "draw.h"
int main(int argc,char **argv) { int main(void) {
char *p; char *p;
strcpy(playername,"ANONYMOUS"); strcpy(playername,"ANONYMOUS");
p=getenv("USER"); p=getenv("USER");
if(p) strncpy(playername,p,sizeof(playername)); if(p) strncpy(playername,p,sizeof(playername)-1);
create_seed_unique(); create_seed_unique();
opengfx(argc, argv); opengfx();
getsocket(); getsocket();
if (!initannouncer()) exit(1); if (!initannouncer()) exit(1);

View File

@ -587,7 +587,7 @@ static void drawstats(void) {
player *pl; player *pl;
int p = 0; int p = 0;
const char *n; const char *n;
char buf[16]; char buf[17];
solidcopy(&background, 0, 0, IXSIZE, arraystarty); solidcopy(&background, 0, 0, IXSIZE, arraystarty);
list_for_each_entry(pl, &allplayers, list_all_players) { list_for_each_entry(pl, &allplayers, list_all_players) {

View File

@ -407,7 +407,7 @@ void copyupxysize(int x,int y,int xsize,int ysize)
// themap[color].b=blue; // themap[color].b=blue;
// } // }
void opengfx(int argc, char **argv) { void opengfx(void) {
unsigned long videoflags; unsigned long videoflags;
themap[0].r=0; themap[0].r=0;

View File

@ -19,7 +19,7 @@ extern int mxpos,mypos;
extern int pressedcodes[KEYMAX],downcodes[KEYMAX],numpressed,numdown; extern int pressedcodes[KEYMAX],downcodes[KEYMAX],numpressed,numdown;
void opengfx(int argc, char **argv); void opengfx(void);
void gfxlock(void); void gfxlock(void);
void gfxunlock(void); void gfxunlock(void);
void pollinput(void); void pollinput(void);

View File

@ -81,7 +81,7 @@ void things_list_clear(listhead *head) {
genericlistitem *entry; genericlistitem *entry;
while (head->next != head) { while (head->next != head) {
entry = container_of(head->next, typeof(*entry), list); entry = container_of(head->next, __typeof__(*entry), list);
list_del(head->next); list_del(head->next);
freeentry(entry); freeentry(entry);
} }

View File

@ -1,11 +1,10 @@
#ifndef LIST_H #ifndef LIST_H
#define LIST_H #define LIST_H
/* from linux kernel */ /* from linux kernel (with some changes for "iso" c) */
#define container_of(ptr, type, member) ({ \ #define container_of(ptr, type, member) \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \ ((type *)( (char *)(__typeof__( ((type *)0)->member ) *)(ptr) - offsetof(type,member)))
(type *)( (char *)__mptr - offsetof(type,member) );})
/** /**
* list_entry - get the struct for this entry * list_entry - get the struct for this entry
@ -38,10 +37,10 @@ void things_list_clear(listhead *head); /* listhead member must be the first mem
* @member: the name of the list_struct within the struct. * @member: the name of the list_struct within the struct.
*/ */
#define list_for_each_entry(pos, head, member) \ #define list_for_each_entry(pos, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member); \ for (pos = list_entry((head)->next, __typeof__(*pos), member); \
/* prefetch(pos->member.next), */ \ /* prefetch(pos->member.next), */ \
&pos->member != (head); \ &pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member)) pos = list_entry(pos->member.next, __typeof__(*pos), member))
/** /**
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
@ -51,10 +50,10 @@ void things_list_clear(listhead *head); /* listhead member must be the first mem
* @member:>the name of the list_struct within the struct. * @member:>the name of the list_struct within the struct.
*/ */
#define list_for_each_entry_safe(pos, n, head, member) \ #define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member), \ for (pos = list_entry((head)->next, __typeof__(*pos), member), \
n = list_entry(pos->member.next, typeof(*pos), member); \ n = list_entry(pos->member.next, __typeof__(*pos), member); \
&pos->member != (head); \ &pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member)) pos = n, n = list_entry(n->member.next, __typeof__(*n), member))
#define list_empty(head) ((head) == (head)->next) #define list_empty(head) ((head) == (head)->next)

View File

@ -473,7 +473,7 @@ static void send_reject(struct sockaddr_in *toname, Uint32 network_join_unique,
memcpy(mesg+1, &network_join_unique, sizeof(network_join_unique)); memcpy(mesg+1, &network_join_unique, sizeof(network_join_unique));
write_version(mesg+5); write_version(mesg+5);
mesg[9] = reason; mesg[9] = reason;
putmsg(&sender,mesg,10); putmsg(toname,mesg,10);
} }
static void send_accept(Uint32 network_join_unique) { static void send_accept(Uint32 network_join_unique) {
@ -526,7 +526,7 @@ int handle_joins() {
int size; int size;
int i, j; int i, j;
unsigned char temp[64]; unsigned char temp[64];
Uint32 network_join_unique; Uint32 network_join_unique = 0;
size=getmsg(40); size=getmsg(40);
switch (*mesg) { switch (*mesg) {

View File

@ -58,6 +58,7 @@ static void fillaudio(void *udata,Uint8 *buffer,int len)
char com,*p; char com,*p;
int i,j,*ip; int i,j,*ip;
int which; int which;
(void)udata;
while(soundtake!=soundput) while(soundtake!=soundput)
{ {