Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings on Windows and reimplement err and errx as functions #193

Merged
merged 3 commits into from
Oct 29, 2022

Conversation

1480c1
Copy link
Contributor

@1480c1 1480c1 commented Oct 28, 2022

See: #192

Fixes some warnings produced by mingw-w64 gcc regarding signed<->unsigned comparison and comparing against less than 0 for unsigned numbers, along with redefined macros.

Also reimplements the macros err and errx as functions based on the man page description, minus a few sections due to those conditions not being met in any of the calls.

Confirmed this to work on both linux with gcc (GCC) 12.2.0 and x86_64-w64-mingw32-gcc (GCC) 12.2.0 from archlinux and from cc.exe (Rev4, Built by MSYS2 project) 12.2.0 from ucrt64 from MSYS2.

To reproduce on a linux machine with mingw-w64 gcc and meson installed

cat > x86_64-w64-mingw32.txt <<'EOF'
[binaries]
c = 'x86_64-w64-mingw32-gcc'
cpp = 'x86_64-w64-mingw32-g++'
ar = 'x86_64-w64-mingw32-ar'
strip = 'x86_64-w64-mingw32-strip'
exe_wrapper = 'wine64'

[host_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'
EOF
meson setup --cross-file x86_64-w64-mingw32.txt build-mingw
meson compile -C build-mingw

mingw-w64's stdio.h header already defines fseeko

Signed-off-by: Christopher Degawa <ccom@randomderp.com>
gcc warns against comparing size_t against -1 or checking if it's
less than zero as the first may be due to incorrect assumptions and
the second will always return false.

Signed-off-by: Christopher Degawa <ccom@randomderp.com>
These functions are based on the manpage for err(3) and errx(3), minus
the condition for the fmt to be NULL on the consideration that none of
the calls to them contain NULL as the fmt.

Online man page that was consulted: https://docs.oracle.com/cd/E36784_01/html/E36874/errx-3c.html

Signed-off-by: Christopher Degawa <ccom@randomderp.com>
Comment on lines +50 to +51
#include <errno.h>
#include <stdarg.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If wanted, I can move these includes up to an else branch for the #if !defined(WIN32) && !defined(_AIX) condition. I've only included them here for no particular reaso

Comment on lines +78 to 81
#if defined(_WIN32) && !defined(fseeko)
# define fseeko fseek
# define ftello ftell
#endif
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A potentially more robust check would be to also add && !defined(ftello) and undef both before defining them, but I wasn't sure if adding more lines for these two macros would be desirable

@jpmens
Copy link
Owner

jpmens commented Oct 29, 2022

This looks good to me for Darwin, Debian 11, and MingW (gcc 9.2.0) on Windows10.
About to merge.

Thank you for your help and contribution!

@jpmens jpmens merged commit 93ce3c3 into jpmens:master Oct 29, 2022
@1480c1 1480c1 deleted the win32/warningserrx branch October 29, 2022 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants