delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/01/12/18:10:02

X-Spam-Check-By: sourceware.org
X-T2-Posting-ID: dCnToGxhL58ot4EWY8b+QGwMembwLoz1X2yB7MdtIiA=
X-Cloudmark-Score: 0.000000 []
Date: Fri, 13 Jan 2006 00:09:39 +0100
From: Samuel Thibault <samuel DOT thibault AT ens-lyon DOT org>
To: cygwin AT cygwin DOT com, Dave Korn <dave DOT korn AT artimi DOT com>,
"Yaakov S (Cygwin Ports)" <yselkowitz AT users DOT sourceforge DOT net>
Subject: Re: Define _POSIX_SOURCE in cygwin's features.h?
Message-ID: <20060112230938.GH5574@bouh.residence.ens-lyon.fr>
Mail-Followup-To: cygwin AT cygwin DOT com, Dave Korn <dave DOT korn AT artimi DOT com>, "Yaakov S (Cygwin Ports)" <yselkowitz AT users DOT sourceforge DOT net>
References: <20060112181339 DOT GC30108 AT trixie DOT casa DOT cgf DOT cx> <SERRANOHaZVrDs9aAOP000000c7 AT SERRANO DOT CAM DOT ARTIMI DOT COM> <20060112185350 DOT GG30108 AT trixie DOT casa DOT cgf DOT cx> <20060112185934 DOT GH30108 AT trixie DOT casa DOT cgf DOT cx> <20060112181339 DOT GC30108 AT trixie DOT casa DOT cgf DOT cx> <SERRANOHaZVrDs9aAOP000000c7 AT SERRANO DOT CAM DOT ARTIMI DOT COM> <20060112185350 DOT GG30108 AT trixie DOT casa DOT cgf DOT cx> <20060112175908 DOT GB30108 AT trixie DOT casa DOT cgf DOT cx> <SERRANO1aNEVJpjc0D5000000c4 AT SERRANO DOT CAM DOT ARTIMI DOT COM> <20060112184710 DOT GF30108 AT trixie DOT casa DOT cgf DOT cx>
Mime-Version: 1.0
In-Reply-To: <20060112204835.GC2887@trixie.casa.cgf.cx> <43C6BBA5.9000809@users.sourceforge.net> <20060112192423.GI30108@trixie.casa.cgf.cx> <SERRANObC8wSA1XvpFV000000cb@SERRANO.CAM.ARTIMI.COM> <20060112185934.GH30108@trixie.casa.cgf.cx> <20060112185350.GG30108@trixie.casa.cgf.cx> <20060112184710.GF30108@trixie.casa.cgf.cx>
User-Agent: Mutt/1.5.9i-nntp
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Hi,

Christopher Faylor, le Thu 12 Jan 2006 13:47:10 -0500, a écrit :
> Just to add even more clarification, this wasn't some guy writing a
> program for his class assignment.  It was someone trying to port a
> standard linux/unix application.

If he doesn't define _POSIX_SOURCE for getting function definitions, his
application isn't a standard unix one.

> The program had a test for _POSIX_SOURCE which would have worked
> correctly under Cygwin.  Again, I'm not really interested in hearing
> what someone should have done or should have known to do.

Christopher Faylor, le Thu 12 Jan 2006 14:24:23 -0500, a écrit :
> This particular application was ircd.  It was testing _POSIX_SOURCE (and
> a few other defines) to determine whether it should use setsid or a
> two-argument version of setpgrp, e.g.:
> 
> #ifdef _POSIX_SOURCE
>     setsid ();
> #else
>     setpgrp(..., ...);
> #endif

Testing for _POSIX_SOURCE _doesn't_ make sense. Read a posix book. One
of the first things it would tell you is that you must define
_POSIX_SOURCE yourself for pulling posix function definitions & such.

If a programmer wants to determine whether setsid or setpgr can be used,
he can just use an autoconf rule for that. I repeat: read posix, testing
for _POSIX_SOURCE does _not_ make sense in a program.

Christopher Faylor, le Thu 12 Jan 2006 13:53:50 -0500, a écrit :
> >I don't see why we should try and fix this in cygwin.
> >
> >Consider how many times people come here and say "My app works fine on
> >Linux, how come it just dies with a SEGV on cygwin" and someone points
> >out the trivially obvious buffer overrun and we have to explain how it
> >only ever worked on Linux by luck because of differences in the
> >environment and the way the stack is set up.
> 
> If I could easily make cygwin behave exactly the same way so that a
> buffer overrun that worked on linux went undetected on cygwin, too, I'd
> do that.  If there was some linker option to ensure that, I'd use it.

This is /weird/. Reproducing bugs is just silly ! 8!

> It turns out that _POSIX_SOURCE *is* turned on by default on in glibc
> regardless of whether you define _GNU_SOURCE or not.  So that would
> explain why this application built.
> 
> Apparently _POSIX_SOURCE is turned on by this segment of features.h:
> 
>   #if ((!defined __STRICT_ANSI__ || (_XOPEN_SOURCE - 0) >= 500) && \
>        !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE)
>   # define _POSIX_SOURCE  1
>   # if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 500
>   #  define _POSIX_C_SOURCE       2
>   # else
>   #  define _POSIX_C_SOURCE       199506L
>   # endif
>   #endif

Ok, now _this_ makes sense. This is a lazyness of GNU people: gcc
is _not_ an ansi compiler, only gcc -ansi is ; and in that case
__STRICT_ANSI__ is defined for headers to avoid defining things like
_POSIX_C_SOURCE themselves.

Since cygwin uses the gcc compiler, these few lines should _indeed_ be
added to features.h. But not more !

(BTW, that means that ircd can only be compiled with a gcc compiler, not
an ansi compiler).

> I was wondering if anyone had specific examples where defining
> _POSIX_SOURCE would help or hurt existing applications.

It can hurt:

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
static const char *confstr(num)
	unsigned int num;
{
	static const char *strs[] = { "foo", "bar", "baz" };
	if (num >= sizeof(strs)/sizeof(*strs))
		return "unknown";
	return strs[num];
}
int main(argc, argv)
	int argc;
	char *argv[];
{
	char *conf;
	argv++;
	while ((conf = *(argv++)))
		puts(confstr(atoi(conf)));
	return 0;
}

This program is a perfectly valid ansi C program:
$ gcc test.c -o test -ansi -Wall -pedantic
It compiles fine with ansi C compilers.

But it is not a valid posix C program:
$ gcc test.c -o test
test.c:5: error: conflicting types for 'confstr'
/usr/include/unistd.h:544: error: previous declaration of 'confstr' was here

So, does cygwin want gcc to be by default an ansi compiler or a posix
compiler?

Regards,
Samuel

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019