Skip to contentSkip to conversation

Mercury/psos: Solve compiler warning when including psos.h

PATCH Applied Ronny Meeus 2 participants 2 messages Nov 29, 2016 – Dec 9, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Mercury/psos: Solve compiler warning when including psos.h

In boilerplate function 'get_program_name', basename is used.

When libgen.h is incuded in your program, the basename gets the POSIX version (no const char*, see 'man basename'):
char *basename(char *path);

This results in the following compiler warning:
boilerplate/setup.h: In function 'const char* get_program_name()':
boilerplate/setup.h:107: error: invalid conversion from 'const char*' to 'char*'
boilerplate/setup.h:107: error: initializing argument 1 of 'char* __xpg_basename(char*)'

Test application:

#include <libgen.h>
#include <psos/psos.h>
int main(int argc, char * const argv[])
{
return 0;
}

When the libgen.h is not included, the warning is not seen.

This patch solve the above issue by moving the implementation to setup.c instead of using an inline function.

include/boilerplate/setup.h +1 -4
@@ -102,10 +102,7 @@ extern int __config_done;
 
 extern struct base_setup_data __base_setup_data;
 
-static inline const char *get_program_name(void)
-{
-	return basename(__base_setup_data.arg0 ?: "program");
-}
+const char *get_program_name(void);
 
 void __trace_me(const char *fmt, ...);
 
lib/boilerplate/setup.c +5 -0
@@ -644,3 +644,8 @@ void __register_setup_call(struct setup_
 	}
 	pvlist_prepend(&p->__reserved.next, &setup_list);
 }
+
+const char *get_program_name(void)
+{
+	return basename(__base_setup_data.arg0 ?: "program");
+}
#1 lore raw
Quoted 20 lines · Ronny Meeus

In boilerplate function 'get_program_name', basename is used.

When libgen.h is incuded in your program, the basename gets the POSIX version (no const char*, see 'man basename'):
char *basename(char *path);

This results in the following compiler warning:
boilerplate/setup.h: In function 'const char* get_program_name()':
boilerplate/setup.h:107: error: invalid conversion from 'const char*' to 'char*'
boilerplate/setup.h:107: error: initializing argument 1 of 'char* __xpg_basename(char*)'

Test application:

#include <libgen.h>
#include <psos/psos.h>
int main(int argc, char * const argv[])
{
return 0;
}

Quoted 4 lines

When the libgen.h is not included, the warning is not seen.

This patch solve the above issue by moving the implementation to setup.c instead of using an inline function.

Merged, thanks.

Signature · 1 line
Philippe.