Skip to content

Commit

Permalink
remove compiler warnings on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
matyalatte committed Jun 22, 2024
1 parent 1324f26 commit 5f9109b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 44 deletions.
20 changes: 10 additions & 10 deletions include/env_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
12 changes: 9 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/env_utils_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/haiku.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions src/unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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 };
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -239,7 +239,7 @@ static inline char *getExecutablePathProcfs() {
}
#endif

char *envuGetExecutablePath() {
char *envuGetExecutablePath(void) {
#ifdef __APPLE__
return getExecutablePathApple();
#elif defined(__FreeBSD__)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -428,7 +428,7 @@ char *envuGetHome() {
return str;
}

char *envuGetUsername() {
char *envuGetUsername(void) {
char *buf;
struct passwd *p = getpwuid_safe(&buf);

Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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.
Expand All @@ -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

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand All @@ -648,7 +648,7 @@ static inline char *getOSProductNameOthers() {
}
#endif

char *envuGetOSProductName() {
char *envuGetOSProductName(void) {
#ifdef __APPLE__
return getOSProductNameApple();
#elif defined(__linux__)
Expand Down
14 changes: 7 additions & 7 deletions src/windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -324,7 +324,7 @@ char *envuGetHome() {
return str;
}

char *envuGetUsername() {
char *envuGetUsername(void) {
// Try GetUserNameW
wchar_t wname[UNLEN + 1];
wname[UNLEN] = 0;
Expand All @@ -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);
}

0 comments on commit 5f9109b

Please sign in to comment.