public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* _GNU_SOURCE doesn't enable cuserid() declaration
@ 2018-11-29  2:22 Tony Cook
  2018-11-29 10:28 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Tony Cook @ 2018-11-29  2:22 UTC (permalink / raw)
  To: cygwin

Linux stdio.h exposes the declaration of cuserid() both with standard
version macros and with _GNU_SOURCE:

tony@mars:~/play$ cat testcuserid.c
#define _GNU_SOURCE
#include <stdio.h>

int main() {
  puts(cuserid(NULL));
  return 0;
}
tony@mars:~/play$ gcc -otestcuserid -Werror=all testcuserid.c
tony@mars:~/play$ ./testcuserid
tony
tony@mars:~/play$ uname -a
Linux mars 4.9.0-8-amd64 #1 SMP Debian 4.9.110-3+deb9u4 (2018-08-21) x86_64 GNU/Linux

while on Cygwin _GNU_SOURCE doesn't expose cuserid():

tony@phobos /cygdrive/n/play
$ gcc -otestcuserid.exe -Werror=all testcuserid.c
testcuserid.c: In function ‘main’:
testcuserid.c:5:8: error: implicit declaration of function ‘cuserid’; did you mean ‘L_cuserid’? [-Werror=implicit-function-declaration]
   puts(cuserid(NULL));
        ^~~~~~~
        L_cuserid
testcuserid.c:5:8: warning: passing argument 1 of ‘puts’ makes pointer from integer without a cast [-Wint-conversion]
In file included from testcuserid.c:2:0:
/usr/include/stdio.h:221:5: note: expected ‘const char *’ but argument is of type ‘int’
 int puts (const char *);
     ^~~~
cc1: some warnings being treated as errors

tony@phobos /cygdrive/n/play
$ uname -a
CYGWIN_NT-6.1 phobos 2.11.2(0.329/5/3) 2018-11-08 14:34 x86_64 Cygwin

This seems unintentional, since L_cuserid is exposed with _GNU_SOURCE
on Cygwin:

tony@phobos /cygdrive/n/play
$ cat testlcuserid.c
#define _GNU_SOURCE
#include <stdio.h>

int main() {
  printf("%d\n", (int)L_cuserid);
  return 0;
}

tony@phobos /cygdrive/n/play
$ gcc -otestlcuserid.exe -Werror=all testlcuserid.c

and on Linux:

tony@mars:~/play$ gcc -otestlcuserid -Werror=all testlcuserid.c

(neither produces a diagnostic)

Tony

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: _GNU_SOURCE doesn't enable cuserid() declaration
  2018-11-29  2:22 _GNU_SOURCE doesn't enable cuserid() declaration Tony Cook
@ 2018-11-29 10:28 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2018-11-29 10:28 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 889 bytes --]

On Nov 29 13:22, Tony Cook wrote:
> Linux stdio.h exposes the declaration of cuserid() both with standard
> version macros and with _GNU_SOURCE:
> 
> tony@mars:~/play$ cat testcuserid.c
> #define _GNU_SOURCE
> #include <stdio.h>
> 
> int main() {
>   puts(cuserid(NULL));
>   return 0;
> }
> tony@mars:~/play$ gcc -otestcuserid -Werror=all testcuserid.c
> tony@mars:~/play$ ./testcuserid
> tony
> tony@mars:~/play$ uname -a
> Linux mars 4.9.0-8-amd64 #1 SMP Debian 4.9.110-3+deb9u4 (2018-08-21) x86_64 GNU/Linux
> 
> while on Cygwin _GNU_SOURCE doesn't expose cuserid():

Thanks, I pushed a patch.

https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=09870c6e958c

Of course, that doesn't make cuserid more portable.  The rule given in
the Linux man page still applies:  "Do not use cuserid()."


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-11-29 10:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-29  2:22 _GNU_SOURCE doesn't enable cuserid() declaration Tony Cook
2018-11-29 10:28 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).