_GNU_SOURCE doesn't enable cuserid() declaration

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

_GNU_SOURCE doesn't enable cuserid() declaration

Tony Cook
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

Reply | Threaded
Open this post in threaded view
|

Re: _GNU_SOURCE doesn't enable cuserid() declaration

Corinna Vinschen-2
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

signature.asc (849 bytes) Download Attachment