mailing list of musl libc
 help / color / mirror / code / Atom feed
* Trouble with sscanf
@ 2012-11-16 15:28 Paul Schutte
  2012-11-16 15:39 ` Szabolcs Nagy
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Schutte @ 2012-11-16 15:28 UTC (permalink / raw)
  To: musl


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

Hi Guys,

I am trying to compile procps-3.2.8. I keep getting floating point
exceptions when trying to run the tools.

I narrowed the problem to what seems to be an issue with sscanf.

glibc output:
3720798 10228 2410878 64601718 356554 1658 33774 0

musl output:
100 0 0 0 0 0 0 0

I hacked sample code together out of their code to illustrate the problem,
which I attach.
I tried to keep it very close to the original.

Regards
Paul

[-- Attachment #1.2: Type: text/html, Size: 625 bytes --]

[-- Attachment #2: scanftest.c --]
[-- Type: text/x-csrc, Size: 1192 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>

#define BUFFSIZE (128*1024)
typedef unsigned long long jiff;

int main() {
static char buff[BUFFSIZE]; /* used in the procedures */
static int fd;
jiff cuse;
jiff cice;
jiff csys;
jiff cide;
jiff ciow;
jiff cxxx;
jiff cyyy;
jiff czzz;
unsigned intr;
const char* b=NULL;

buff[BUFFSIZE-1] = 0;  /* ensure null termination in buffer */

if (fd) {
	lseek(fd, 0L, SEEK_SET);
	}else{
	fd = open("/proc/stat", O_RDONLY, 0);
	if(fd == -1) perror("/proc/stat");
}

  read(fd,buff,BUFFSIZE-1);

	intr = 0;
  ciow = 0;  /* not separated out until the 2.5.41 kernel */
  cxxx = 0;  /* not separated out until the 2.6.0-test4 kernel */
  cyyy = 0;  /* not separated out until the 2.6.0-test4 kernel */
  czzz = 0;  /* not separated out until the 2.6.11 kernel */

  b = strstr(buff, "cpu ");
  if (b) { 
	sscanf(b,  "cpu  %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", &cuse, &cice, &csys, &cide, &ciow, &cxxx, &cyyy, &czzz);
	printf("%llu %llu %llu %llu %llu %llu %llu %llu\n",cuse,cice,csys,cide,ciow,cxxx,cyyy,czzz);
	return 0;
	} else {
	printf("strstr failed\n");
	}
}

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

end of thread, other threads:[~2012-11-16 15:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-16 15:28 Trouble with sscanf Paul Schutte
2012-11-16 15:39 ` Szabolcs Nagy
2012-11-16 15:46   ` Paul Schutte
2012-11-16 15:53     ` John Spencer
2012-11-16 15:49   ` Szabolcs Nagy

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).