Skip to content

Commit

Permalink
disable warnings on some compilers for unused asprintf() return values
Browse files Browse the repository at this point in the history
  • Loading branch information
ka9q committed Apr 20, 2024
1 parent 707842b commit 0c2be11
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions avahi.c
Expand Up @@ -25,19 +25,23 @@ int avahi_start(char const *service_name,char const *service_type,int const serv
#endif
// run "avahi-publish-service --no-fail --host=dns_name service_name service_type service_port description pid hostname" in subprocess
// No need to free the asprintf-allocated strings, we're calling exec anyway
char *port_string;
// Turn off warnings about unused return values from asprintf generated by some compilers
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
char *port_string = NULL;
asprintf(&port_string, "%d", service_port);

char *host_string;
char *host_string = NULL;
asprintf(&host_string, "--host=%s",dns_name);

char *pid_string;
char *pid_string = NULL;
asprintf(&pid_string, "pid=%d", pid);

char hostname[sysconf(_SC_HOST_NAME_MAX)];
gethostname(hostname,sizeof(hostname));
char *source_string;
char *source_string = NULL;
asprintf(&source_string, "source=%s", hostname);
#pragma GCC diagnostic pop

#if 0
fprintf(stdout,"%s %s %s %s %s %s %s %s %s %s\n",
Expand All @@ -49,8 +53,11 @@ int avahi_start(char const *service_name,char const *service_type,int const serv
}
if(fork() == 0){
// run "avahi-publish-address dns_name address"
char *ip_address_string; // No need to free, we're calling exec
char *ip_address_string = NULL; // No need to free, we're calling exec
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
asprintf(&ip_address_string,"%d.%d.%d.%d",(address >> 24) & 0xff, (address >> 16) & 0xff, (address >> 8) & 0xff, address & 0xff);
#pragma GCC diagnostic pop
#if 0
fprintf(stdout,"avahi start: ip address string = %s\n",ip_address_string);
fprintf(stdout,"avahi-publish-address child pid %d\n",getpid());
Expand Down

0 comments on commit 0c2be11

Please sign in to comment.