public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* scanf and m modifier
       [not found] <768145014.4380137.1467998182030.JavaMail.yahoo.ref@mail.yahoo.com>
@ 2016-07-08 17:16 ` Owen Leibman
  2016-07-08 17:22   ` Eliot Moss
  0 siblings, 1 reply; 4+ messages in thread
From: Owen Leibman @ 2016-07-08 17:16 UTC (permalink / raw)
  To: cygwin

The m modifier is handled just fine by the compiler, but
the results of using it are different on Cygwin than on several other systems
I've tried. Here is a sample program:
 
#include <stdio.h>
#include <stdlib.h>
#define NAMELEN 100
int main(void) {
  char *f =
"inputstring", title[NAMELEN], *buffer = 0;
  int scanrc;
  scanrc =
sscanf(f, "%ms", &buffer);
  if (scanrc <
1) {
    snprintf(title,
sizeof(title), "sscanf failed");
  } else {
    snprintf(title,
sizeof(title), "%s", buffer);
    free(buffer);
  }
  printf("title is %s.\n", title);
  return 0;
}
 
The expected result is "title is inputstring",
which is what I see on Ubuntu and RedHat systems.
 
What I see in Cygwin is "sscanf failed".
 
My compile command is:
gcc -Wall program.c
 
No warnings are issued. I have also tried adding various
flavors of -D_XOPEN_SOURCE and -D_POSIX_SOURCE, all without success. Is there
some compile option I need to add, or is my program wrong, or is there a

problem with the library code in Cygwin?

BTW, on a very old Solaris system with a very old version of gcc (3.3), I did receive the following message:
replscan3.c:7: warning: unknown conversion type character `m' in format
That is far from ideal, but it is better than the inconsistency between the compiler and the run-time which I'm seeing in Cygwin.

--
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] 4+ messages in thread

* Re: scanf and m modifier
  2016-07-08 17:16 ` scanf and m modifier Owen Leibman
@ 2016-07-08 17:22   ` Eliot Moss
  2016-07-08 17:42     ` Eric Blake
  0 siblings, 1 reply; 4+ messages in thread
From: Eliot Moss @ 2016-07-08 17:22 UTC (permalink / raw)
  To: cygwin

On 7/8/2016 1:16 PM, Owen Leibman wrote:
> The m modifier is handled just fine by the compiler, but
> the results of using it are different on Cygwin than on several other systems
> I've tried. Here is a sample program:

Dear Owen -- The first question I'd ask is: What versions of gcc
and C libraries are we talking about?  IIRC, the m feature is
relatively new (relative being, umm, relative), so which gcc you're
using, and the libraries, too, may matter.

Regards -- Eliot Moss

--
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] 4+ messages in thread

* Re: scanf and m modifier
  2016-07-08 17:22   ` Eliot Moss
@ 2016-07-08 17:42     ` Eric Blake
  2016-07-11  9:56       ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Blake @ 2016-07-08 17:42 UTC (permalink / raw)
  To: cygwin


[-- Attachment #1.1: Type: text/plain, Size: 789 bytes --]

On 07/08/2016 11:22 AM, Eliot Moss wrote:
> On 7/8/2016 1:16 PM, Owen Leibman wrote:
>> The m modifier is handled just fine by the compiler, but
>> the results of using it are different on Cygwin than on several other
>> systems
>> I've tried. Here is a sample program:
> 
> Dear Owen -- The first question I'd ask is: What versions of gcc
> and C libraries are we talking about?  IIRC, the m feature is
> relatively new (relative being, umm, relative), so which gcc you're
> using, and the libraries, too, may matter.

scanf("%ms") is a POSIX extension, not required by C99.  I suspect the
answer is that no one has implemented it in newlib yet; patches welcome.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

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

* Re: scanf and m modifier
  2016-07-08 17:42     ` Eric Blake
@ 2016-07-11  9:56       ` Corinna Vinschen
  0 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2016-07-11  9:56 UTC (permalink / raw)
  To: cygwin

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

On Jul  8 11:42, Eric Blake wrote:
> On 07/08/2016 11:22 AM, Eliot Moss wrote:
> > On 7/8/2016 1:16 PM, Owen Leibman wrote:
> >> The m modifier is handled just fine by the compiler, but
> >> the results of using it are different on Cygwin than on several other
> >> systems
> >> I've tried. Here is a sample program:
> > 
> > Dear Owen -- The first question I'd ask is: What versions of gcc
> > and C libraries are we talking about?  IIRC, the m feature is
> > relatively new (relative being, umm, relative), so which gcc you're
> > using, and the libraries, too, may matter.
> 
> scanf("%ms") is a POSIX extension, not required by C99.  I suspect the
> answer is that no one has implemented it in newlib yet; patches welcome.

Indeed, the 'm' modifier isn't implemented in newlib yet.  However, the
vfscanf code, while being a bot more convoluted than FreeBSD/NetBSD to
support small targets, is still based on FreeBSD and NetBSD.  It might
be possible to port the 'm' handling from one of them with moderate
effort.

Anybody here who'd like to do that?

Just send your patch to the newlib AT sourceware DOT org mailing list 
and we're looking it over for inclusion.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

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

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

end of thread, other threads:[~2016-07-11  9:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <768145014.4380137.1467998182030.JavaMail.yahoo.ref@mail.yahoo.com>
2016-07-08 17:16 ` scanf and m modifier Owen Leibman
2016-07-08 17:22   ` Eliot Moss
2016-07-08 17:42     ` Eric Blake
2016-07-11  9:56       ` 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).