From: ori@eigenstate.org
To: 9front@9front.org
Subject: ape scanf: add missing conversion flags
Date: Sat, 9 May 2020 19:07:47 -0700 [thread overview]
Message-ID: <ACB9150D88B680D22D915253F32590A1@eigenstate.org> (raw)
Found when porting timezone database compiler.
We're missing type flags for:
hh: char
ll: vlong
z: size_t
t: ptrdiff_t
j: intmax_t
The lack of '%lld' was causing us to fail when parsing
timezone files.
Relevant spec:
http://port70.net/~nsz/c/c99/n1256.html#7.19.6.2p11
diff -r 706dd21f7559 sys/src/ape/lib/ap/gen/strtoll.c
--- a/sys/src/ape/lib/ap/gen/strtoll.c Sun May 10 02:44:37 2020 +0200
+++ b/sys/src/ape/lib/ap/gen/strtoll.c Sat May 09 19:04:21 2020 -0700
@@ -101,3 +101,9 @@
return -n;
return n;
}
+
+long long
+strtoimax(char *nptr, char **endptr, int base)
+{
+ return strtoll(nptr, endptr, base);
+}
diff -r 706dd21f7559 sys/src/ape/lib/ap/stdio/vfscanf.c
--- a/sys/src/ape/lib/ap/stdio/vfscanf.c Sun May 10 02:44:37 2020 +0200
+++ b/sys/src/ape/lib/ap/stdio/vfscanf.c Sat May 09 19:04:21 2020 -0700
@@ -96,7 +96,16 @@
}
else
width=-1;
- type=*fmtp=='h' || *fmtp=='l' || *fmtp=='L'?*fmtp++:'n';
+ type = 'n';
+ if(*fmtp=='h' || *fmtp=='l' || *fmtp=='L' || *fmtp=='j' || *fmtp=='z' || *fmtp=='t')
+ type = *fmtp++;
+ if(type == 'l' && *fmtp == 'l'){
+ type = 'V';
+ fmtp++;
+ }else if(type == 'h' && *fmtp == 'h'){
+ type = 'H';
+ fmtp++;
+ }
if(!icvt[*fmtp]) goto NonSpecial;
if(!(*icvt[*fmtp])(f, &args, store, width, type))
return ncvt?ncvt:EOF;
@@ -137,7 +146,7 @@
static int
icvt_fixed(FILE *f, va_list *args,
int store, int width, int type, int unsgned, int base){
- unsigned long int num=0;
+ unsigned long long num=0;
int sign=1, ndig=0, dig;
int c;
do
@@ -194,18 +203,28 @@
switch(unsgned){
case SIGNED:
switch(type){
- case 'h': *va_arg(*args, short *)=num*sign; break;
- case 'n': *va_arg(*args, int *)=num*sign; break;
+ case 'H': *va_arg(*args, char *)=num*sign; break;
+ case 'h': *va_arg(*args, short *)=num*sign; break;
+ case 'n': *va_arg(*args, int *)=num*sign; break;
case 'l':
- case 'L': *va_arg(*args, long *)=num*sign; break;
+ case 'L': *va_arg(*args, long *)=num*sign; break;
+ case 'j':
+ case 'V': *va_arg(*args, long long*)=num*sign; break;
+ case 'z': *va_arg(*args, ssize_t*)=num*sign; break;
+ case 't': *va_arg(*args, ptrdiff_t*)=num*sign; break;
}
break;
case UNSIGNED:
switch(type){
+ case 'H': *va_arg(*args, unsigned char *)=num*sign; break;
case 'h': *va_arg(*args, unsigned short *)=num*sign; break;
case 'n': *va_arg(*args, unsigned int *)=num*sign; break;
case 'l':
case 'L': *va_arg(*args, unsigned long *)=num*sign; break;
+ case 'j':
+ case 'V': *va_arg(*args, unsigned long long *)=num*sign; break;
+ case 'z': *va_arg(*args, size_t*)=num*sign; break;
+ case 't': *va_arg(*args, ptrdiff_t*)=num*sign; break;
}
break;
case POINTER:
reply other threads:[~2020-05-10 2:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ACB9150D88B680D22D915253F32590A1@eigenstate.org \
--to=ori@eigenstate.org \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).