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

Implicit declaration of getenv_s() #61

Closed
pwpiwi opened this issue Jan 29, 2021 · 4 comments
Closed

Implicit declaration of getenv_s() #61

pwpiwi opened this issue Jan 29, 2021 · 4 comments
Assignees
Labels

Comments

@pwpiwi
Copy link
Contributor

pwpiwi commented Jan 29, 2021

cliparser/argtable3.c: In function 'getopt_internal':
cliparser/argtable3.c:1710:3: warning: implicit declaration of function 'getenv_s'; did you mean 'getenv'? [-Wimplicit-function-declaration]
 1710 |   getenv_s(&requiredSize, NULL, 0, "POSIXLY_CORRECT");
      |   ^~~~~~~~
      |   getenv

This is on mingw. I propose to add the usual checks for the availability of this C11 extension:

	if (posixly_correct == -1 || optreset) {
#ifdef _WIN32 && ((defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) || (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)))

		size_t requiredSize;
		getenv_s(&requiredSize, NULL, 0, "POSIXLY_CORRECT");
		posixly_correct = requiredSize != 0;
#else
		posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
#endif
	}
@tomghuang tomghuang self-assigned this Jan 29, 2021
@tomghuang tomghuang added the bug label Jan 29, 2021
@tomghuang
Copy link
Contributor

Hi @pwpiwi , when I tried to fix this issue in the msys2/mingw64 environment, I kept seeing the following error:

D:/Projects/argtable3/build_mingw64/src/version.rc:33:10: fatal error: verrsrc.h: No such file or directory
   33 | #include <verrsrc.h>
      |          ^~~~~~~~~~~
compilation terminated.

Do you have the same issue? If yes, how did you fix it? Thanks.

@pwpiwi
Copy link
Contributor Author

pwpiwi commented Jan 30, 2021

Don't know. I never tried to build it. I am using the "amalgamation" argtable3.c instead.
.
I googled for this file and it seems to be part of Visual Studio. Therefore not available on msys2/mingw

@pwpiwi
Copy link
Contributor Author

pwpiwi commented Jan 30, 2021

Re getenv_s(): Why using it at all? In your case you just want to check if the environment variable is availabe. Isn't this always safe?

@tomghuang
Copy link
Contributor

It might be an issue of msys2/mingw64, because msys2/mingw32 doesn't have this issue.

getenv_s() is used to make Visual Studio compiler happy, because VC++ wants us to use more secure functions. Otherwise, it will show tons of warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants