From 5f9109be396bc2047878a22d40e01a2a17bdd351 Mon Sep 17 00:00:00 2001 From: matyalatte Date: Sat, 22 Jun 2024 17:02:27 +0900 Subject: [PATCH] remove compiler warnings on mac --- include/env_utils.h | 20 ++++++++++---------- meson.build | 12 +++++++++--- src/common.c | 6 +++--- src/env_utils_priv.h | 2 +- src/haiku.cpp | 2 +- src/unix.c | 38 +++++++++++++++++++------------------- src/windows.c | 14 +++++++------- 7 files changed, 50 insertions(+), 44 deletions(-) diff --git a/include/env_utils.h b/include/env_utils.h index 1b3ed1d..5bf1b06 100644 --- a/include/env_utils.h +++ b/include/env_utils.h @@ -27,7 +27,7 @@ extern "C" { * * @returns A string that represents the version. */ -_ENVU_EXTERN const char* envuGetVersion(); +_ENVU_EXTERN const char* envuGetVersion(void); /** * Gets the version of c-env-utils as an integer. @@ -36,7 +36,7 @@ _ENVU_EXTERN const char* envuGetVersion(); * * @returns An integer that represents the version. */ -_ENVU_EXTERN int envuGetVersionAsInt(); +_ENVU_EXTERN int envuGetVersionAsInt(void); /** * Frees the memory of a string allocated by c-env-utils. @@ -52,7 +52,7 @@ _ENVU_EXTERN void envuFree(void *p); * * @returns A string that represents the path to the executing binary. Or a null pointer if failed. */ -_ENVU_EXTERN char *envuGetExecutablePath(); +_ENVU_EXTERN char *envuGetExecutablePath(void); /** * Returns if the specified path is a regular file for not. @@ -111,7 +111,7 @@ _ENVU_EXTERN char *envuGetDirectory(const char *path); * * @returns A string that represents the directory of the executing binary. Or a null pointer if failed. */ -_ENVU_EXTERN char *envuGetExecutableDir(); +_ENVU_EXTERN char *envuGetExecutableDir(void); /** * Gets the current working directory. @@ -120,7 +120,7 @@ _ENVU_EXTERN char *envuGetExecutableDir(); * * @returns A string that represents the current working directory. Or a null pointer if failed. */ -_ENVU_EXTERN char *envuGetCwd(); +_ENVU_EXTERN char *envuGetCwd(void); /** * Sets the current working directory. @@ -158,7 +158,7 @@ _ENVU_EXTERN int envuSetEnv(const char *name, const char *value); * * @returns A string that represents user's home directory. Or a null pointer if failed. */ -_ENVU_EXTERN char *envuGetHome(); +_ENVU_EXTERN char *envuGetHome(void); /** * Gets user name. @@ -167,7 +167,7 @@ _ENVU_EXTERN char *envuGetHome(); * * @returns A string that represents user name. Or a null pointer if failed. */ -_ENVU_EXTERN char *envuGetUsername(); +_ENVU_EXTERN char *envuGetUsername(void); /** * Gets the name of running OS. @@ -179,7 +179,7 @@ _ENVU_EXTERN char *envuGetUsername(); * @returns A string that represents running OS. * Or a null pointer if failed. */ -_ENVU_EXTERN char *envuGetOS(); +_ENVU_EXTERN char *envuGetOS(void); /** * Gets the version of running OS. @@ -190,7 +190,7 @@ _ENVU_EXTERN char *envuGetOS(); * @returns A string that represents the version of running OS. * Or a null pointer if failed. */ -_ENVU_EXTERN char *envuGetOSVersion(); +_ENVU_EXTERN char *envuGetOSVersion(void); /** * Gets the product name and its version of running OS. @@ -206,7 +206,7 @@ _ENVU_EXTERN char *envuGetOSVersion(); * @returns A string that represents the product name and its version of running OS. * Or a null pointer if failed. */ -_ENVU_EXTERN char *envuGetOSProductName(); +_ENVU_EXTERN char *envuGetOSProductName(void); /** * Gets the environment paths from the PATH variable. diff --git a/meson.build b/meson.build index 3d92a5a..8ce3481 100644 --- a/meson.build +++ b/meson.build @@ -16,6 +16,7 @@ project('c-env-utils', ['c'], envu_link_args = [] envu_c_args = [] +envu_c_only_args = [] envu_OS = host_machine.system() envu_compiler = meson.get_compiler('c').get_id() envu_is_release = get_option('buildtype').startswith('release') or (get_option('buildtype').startswith('custom') and not get_option('debug')) @@ -49,7 +50,12 @@ endif if envu_OS == 'freebsd' # Ignore some warnings on FreeBSD - envu_c_args += ['-Wno-strict-prototypes', '-Wno-c11-extensions'] + envu_c_args += ['-Wno-c11-extensions'] +endif + +if envu_compiler != 'msvc' + # Show warnings for strict-prototypes + envu_c_only_args += ['-Wstrict-prototypes'] endif # set source files @@ -89,7 +95,7 @@ endif env_utils = library('env_utils', envu_sources, dependencies: envu_lib_deps, - c_args: envu_c_args, + c_args: envu_c_args + envu_c_only_args, cpp_args: envu_c_args, link_args: envu_link_args, install: true, @@ -111,7 +117,7 @@ if get_option('cli') executable('env_utils_cli', envu_sources + ['src/env_utils_cli.c'], dependencies: env_utils_dep, - c_args: envu_c_args, + c_args: envu_c_args + envu_c_only_args, cpp_args: envu_c_args, install : false) endif diff --git a/src/common.c b/src/common.c index db34512..f332316 100644 --- a/src/common.c +++ b/src/common.c @@ -8,15 +8,15 @@ #include "env_utils.h" #include "env_utils_priv.h" -const char* envuGetVersion() { +const char* envuGetVersion(void) { return ENVU_VERSION; } -int envuGetVersionAsInt() { +int envuGetVersionAsInt(void) { return ENVU_VERSION_INT; } -char *envuGetExecutableDir() { +char *envuGetExecutableDir(void) { char *exe_path = envuGetExecutablePath(); char *exe_dir = envuGetDirectory(exe_path); envuFree(exe_path); diff --git a/src/env_utils_priv.h b/src/env_utils_priv.h index 03b221f..159b41b 100644 --- a/src/env_utils_priv.h +++ b/src/env_utils_priv.h @@ -44,7 +44,7 @@ extern wchar_t *getOSInfoFromWMI(const wchar_t *key); #endif #ifdef __HAIKU__ -extern char *getOSVersionHaiku(); +extern char *getOSVersionHaiku(void); #endif #ifdef __cplusplus diff --git a/src/haiku.cpp b/src/haiku.cpp index 0e79ed9..f9cba6e 100644 --- a/src/haiku.cpp +++ b/src/haiku.cpp @@ -7,7 +7,7 @@ // Use a method from SysInfoView::_GetABIVersion // https://cgit.haiku-os.org/haiku/tree/src/apps/aboutsystem/AboutSystem.cpp -char *getOSVersionHaiku() { +char *getOSVersionHaiku(void) { BString abiVersion; // the version is stored in the BEOS:APP_VERSION attribute of libbe.so diff --git a/src/unix.c b/src/unix.c index d17b796..7c7c7b3 100644 --- a/src/unix.c +++ b/src/unix.c @@ -82,7 +82,7 @@ char *envuGetRealPath(const char *path) { #ifdef __APPLE__ // macOS requires _NSGetExecutablePath to get the executable path. -static inline char *getExecutablePathApple() { +static inline char *getExecutablePathApple(void) { char path[PATH_MAX + 1]; path[PATH_MAX] = '\0'; uint32_t bufsize = PATH_MAX; @@ -97,7 +97,7 @@ static inline char *getExecutablePathApple() { } #elif defined(__FreeBSD__) // FreeBSD requires sysctl to get the executable path. -static inline char *getExecutablePathFreeBSD() { +static inline char *getExecutablePathFreeBSD(void) { char path[PATH_MAX + 1]; path[PATH_MAX] = 0; @@ -114,7 +114,7 @@ static inline char *getExecutablePathFreeBSD() { #elif defined(__OpenBSD__) // OpenBSD has no api to get executable path. // So, we need to guess it from argv[0] -static char *getArgv0() { +static char *getArgv0(void) { char **argv; size_t len; int mib[4] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV }; @@ -132,7 +132,7 @@ static char *getArgv0() { return argv0; } -static inline char *getExecutablePathOpenBSD() { +static inline char *getExecutablePathOpenBSD(void) { // try readlink char path[PATH_MAX + 1]; path[PATH_MAX] = 0; @@ -185,7 +185,7 @@ static inline char *getExecutablePathOpenBSD() { } #elif defined(__HAIKU__) // Haiku OS requires get_next_image_info to get the executable path. -static inline char *getExecutablePathHaiku() { +static inline char *getExecutablePathHaiku(void) { int32_t cookie = 0; image_info info; while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) { @@ -205,7 +205,7 @@ static int tryReadlink(const char *link, char *path, int path_size) { return new_path_size; } -static inline char *getExecutablePathProcfs() { +static inline char *getExecutablePathProcfs(void) { // get an executable path with readlink() char path[PATH_MAX + 1]; path[PATH_MAX] = 0; @@ -239,7 +239,7 @@ static inline char *getExecutablePathProcfs() { } #endif -char *envuGetExecutablePath() { +char *envuGetExecutablePath(void) { #ifdef __APPLE__ return getExecutablePathApple(); #elif defined(__FreeBSD__) @@ -352,7 +352,7 @@ char *envuGetDirectory(const char *path) { return ret; } -char *envuGetCwd() { +char *envuGetCwd(void) { char cwd[PATH_MAX + 1]; cwd[PATH_MAX] = 0; char *ret = getcwd(cwd, PATH_MAX); @@ -409,7 +409,7 @@ static struct passwd *getpwuid_safe(char **buf) { return result; } -char *envuGetHome() { +char *envuGetHome(void) { char *buf; struct passwd *p = getpwuid_safe(&buf); @@ -428,7 +428,7 @@ char *envuGetHome() { return str; } -char *envuGetUsername() { +char *envuGetUsername(void) { char *buf; struct passwd *p = getpwuid_safe(&buf); @@ -450,7 +450,7 @@ char *envuGetUsername() { } // Darwin, Linux, FreeBSD, OpenBSD, NetBSD, Haiku, SunOS, etc. -char *envuGetOS() { +char *envuGetOS(void) { struct utsname buf = { 0 }; // Note: uname(&buf) can be positive on Solaris if (uname(&buf) == -1) { @@ -459,7 +459,7 @@ char *envuGetOS() { return envuAllocStrWithConst(buf.sysname); } -char *envuGetOSVersion() { +char *envuGetOSVersion(void) { struct utsname buf = { 0 }; // Note: uname(&buf) can be positive on Solaris if (uname(&buf) == -1) { @@ -484,8 +484,8 @@ char *envuGetOSVersion() { } #ifdef __APPLE__ -CFDictionaryRef _CFCopyServerVersionDictionary(); -CFDictionaryRef _CFCopySystemVersionDictionary(); +CFDictionaryRef _CFCopyServerVersionDictionary(void); +CFDictionaryRef _CFCopySystemVersionDictionary(void); static char *CFStoChar(CFStringRef cfstr) { // Note: The length of string should be smaller than 256. @@ -498,7 +498,7 @@ static char *CFStoChar(CFStringRef cfstr) { return NULL; } -static inline char *getOSProductNameApple() { +static inline char *getOSProductNameApple(void) { // Get ProductName and ProductVersion // from /System/Library/CoreServices/*Version.plist @@ -541,7 +541,7 @@ static inline char *getOSProductNameApple() { return cstr; } #elif defined(__linux__) -static inline char *getOSProductNameLinux() { +static inline char *getOSProductNameLinux(void) { // Get the value of "PRETTY_NAME" in /etc/os-release FILE *fptr; fptr = fopen("/etc/os-release", "r"); @@ -587,7 +587,7 @@ static inline char *getOSProductNameLinux() { return pretty_name; } #elif defined(__sun) -static inline char *getOSProductNameSolaris() { +static inline char *getOSProductNameSolaris(void) { // Get the first alphanumeric part in /etc/release FILE *fptr; fptr = fopen("/etc/release", "r"); @@ -626,7 +626,7 @@ static inline char *getOSProductNameSolaris() { return pretty_name; } #else -static inline char *getOSProductNameOthers() { +static inline char *getOSProductNameOthers(void) { // concat envuGetOS and envuGetOSVersion on other platforms. char *os = envuGetOS(); if (os == NULL) @@ -648,7 +648,7 @@ static inline char *getOSProductNameOthers() { } #endif -char *envuGetOSProductName() { +char *envuGetOSProductName(void) { #ifdef __APPLE__ return getOSProductNameApple(); #elif defined(__linux__) diff --git a/src/windows.c b/src/windows.c index 361b3f6..5de9831 100644 --- a/src/windows.c +++ b/src/windows.c @@ -105,7 +105,7 @@ char *envuUTF16toUTF8(const wchar_t* wstr) { return str; } -char *envuGetExecutablePath() { +char *envuGetExecutablePath(void) { wchar_t *wpath = NULL; int max_size = 256; int size; @@ -246,7 +246,7 @@ char *envuGetDirectory(const char *path) { return str; } -char *envuGetCwd() { +char *envuGetCwd(void) { wchar_t *cwd = _wgetcwd(NULL, 0); if (cwd == NULL) return NULL; @@ -300,7 +300,7 @@ int envuSetEnv(const char *name, const char *value) { return -(ret != 0); } -char *envuGetHome() { +char *envuGetHome(void) { // Check USERPROFILE char *userprof = envuGetEnv("USERPROFILE"); if (userprof != NULL) @@ -324,7 +324,7 @@ char *envuGetHome() { return str; } -char *envuGetUsername() { +char *envuGetUsername(void) { // Try GetUserNameW wchar_t wname[UNLEN + 1]; wname[UNLEN] = 0; @@ -342,16 +342,16 @@ char *envuGetUsername() { return NULL; } -char *envuGetOS() { +char *envuGetOS(void) { return envuAllocStrWithConst("Windows"); } -char *envuGetOSVersion() { +char *envuGetOSVersion(void) { wchar_t *wstr = getOSInfoFromWMI(L"Version"); return envuUTF16toUTF8(wstr); } -char *envuGetOSProductName() { +char *envuGetOSProductName(void) { wchar_t *wstr = getOSInfoFromWMI(L"Caption"); return envuUTF16toUTF8(wstr); }