From: Jens Gustedt <jens.gustedt@inria.fr>
To: musl@lists.openwall.com
Subject: Re: [musl] direct coding of asctime_r
Date: Sun, 23 Aug 2020 11:56:18 +0200 [thread overview]
Message-ID: <20200823115618.79dac5e1@inria.fr> (raw)
In-Reply-To: <alpine.LNX.2.20.13.2008231227350.12553@monopod.intra.ispras.ru>
[-- Attachment #1.1: Type: text/plain, Size: 841 bytes --]
Alexander,
for simplicity I attach what I have.
on Sun, 23 Aug 2020 12:33:30 +0300 (MSK) you (Alexander Monakov
<amonakov@ispras.ru>) wrote:
> Do I understand correctly that this 10k figure is for an "application"
> that does not use stdio at all otherwise?
It just uses unformatted IO, namely `puts`.
> If so, I believe that is a
> quite unrealistic test — why would an application use asctime_r but
> then avoid use of stdio to do something useful with the result?
Just dumping a time stamp to a file e.g.
Jens
--
:: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536 ::
:: :::::::::::::::::::::: gsm France : +33 651400183 ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: test-asctime.c --]
[-- Type: text/x-c++src, Size: 2114 bytes --]
#include <time.h>
#include <string.h>
#include <stdio.h>
static unsigned print_decimal(size_t places, char buf[places], unsigned val) {
for (size_t pos = places; pos > 0; pos--) {
buf[pos-1] = (val % 10) + '0';
val /= 10;
}
return val;
}
char *asctime_r(const struct tm *tm, char *buf) {
static char const wday[7][3] = {
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
};
static char const mon[12][3] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
};
memcpy(buf, "\0\0\0 \0\0\0 \0 \0\0:\0\0:\0\0 \0\0\0\0\n", 26);
if (tm->tm_wday >= 7u) goto CLEANUP;
memcpy(buf, wday[tm->tm_wday], 3);
if (tm->tm_mon >= 12u) goto CLEANUP;
memcpy(buf+4, mon[tm->tm_mon], 3);
if (tm->tm_mday < 10u) {
if (print_decimal(1, buf+9, tm->tm_mday)) goto CLEANUP;
} else {
if (print_decimal(2, buf+8, tm->tm_mday)) goto CLEANUP;
}
if (print_decimal(2, buf+11, tm->tm_hour)) goto CLEANUP;
if (print_decimal(2, buf+14, tm->tm_min)) goto CLEANUP;
if (print_decimal(2, buf+17, tm->tm_sec)) goto CLEANUP;
if (1900u+tm->tm_year < 1000u || print_decimal(4, buf+20, 1900u+tm->tm_year)) goto CLEANUP;
CLEANUP:
return buf;
}
int main(int argc, char* argv[argc+1]) {
char buf[26];
struct tm T;
time_t t = time(0);
gmtime_r(&t, &T);
if (argc == 2) T.tm_mon = 13;
if (argc == 3) T.tm_mon = -6;
asctime_r(&T, buf);
puts(buf);
//puts(asctime(&T));
}
[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
next prev parent reply other threads:[~2020-08-23 9:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-23 8:24 Jens Gustedt
2020-08-23 9:33 ` Alexander Monakov
2020-08-23 9:56 ` Jens Gustedt [this message]
2020-08-23 11:08 ` Alexander Monakov
2020-08-24 16:14 ` Rich Felker
2020-08-27 9:27 ` Jens Gustedt
2020-08-27 14:03 ` Rich Felker
2020-08-27 14:24 ` Jens Gustedt
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=20200823115618.79dac5e1@inria.fr \
--to=jens.gustedt@inria.fr \
--cc=musl@lists.openwall.com \
/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.
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).