From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8576 invoked from network); 23 Aug 2020 09:56:56 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 23 Aug 2020 09:56:56 -0000 Received: (qmail 17968 invoked by uid 550); 23 Aug 2020 09:56:50 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 17950 invoked from network); 23 Aug 2020 09:56:49 -0000 X-IronPort-AV: E=Sophos;i="5.76,344,1592863200"; d="c'?scan'208";a="464361098" Date: Sun, 23 Aug 2020 11:56:18 +0200 From: Jens Gustedt To: musl@lists.openwall.com Message-ID: <20200823115618.79dac5e1@inria.fr> In-Reply-To: References: <20200823102439.2bbaffb5@inria.fr> Organization: inria.fr X-Mailer: Claws Mail 3.17.5git22 (GTK+ 2.24.32; x86_64-pc-linux-gnu) X-Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAAXNSR0IArs4c6QAAACRQTFRFERslNjAsLTE9Ok9wUk9TaUs8iWhSrYZkj42Rz6aD3sGZ MIME-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/X3DZ5Nm=z6KZLp3UkkPRNH1"; protocol="application/pgp-signature"; micalg=pgp-sha1 Subject: Re: [musl] direct coding of asctime_r --Sig_/X3DZ5Nm=z6KZLp3UkkPRNH1 Content-Type: multipart/mixed; boundary="MP_/4hkF18d+jv6DSixC+.h+dCg" --MP_/4hkF18d+jv6DSixC+.h+dCg Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Alexander, for simplicity I attach what I have. on Sun, 23 Aug 2020 12:33:30 +0300 (MSK) you (Alexander Monakov ) 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 =E2=80=94 why would an application use asctime_r b= ut > then avoid use of stdio to do something useful with the result? Just dumping a time stamp to a file e.g. Jens --=20 :: 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 :: --MP_/4hkF18d+jv6DSixC+.h+dCg Content-Type: text/x-c++src Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=test-asctime.c #include #include #include static unsigned print_decimal(size_t places, char buf[places], unsigned val= ) { for (size_t pos =3D places; pos > 0; pos--) { buf[pos-1] =3D (val % 10) + '0'; val /=3D 10; } return val; } char *asctime_r(const struct tm *tm, char *buf) { static char const wday[7][3] =3D { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", }; static char const mon[12][3] =3D { "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 >=3D 7u) goto CLEANUP; memcpy(buf, wday[tm->tm_wday], 3); if (tm->tm_mon >=3D 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_ye= ar)) goto CLEANUP; CLEANUP: return buf; } int main(int argc, char* argv[argc+1]) { char buf[26]; struct tm T; time_t t =3D time(0); gmtime_r(&t, &T); if (argc =3D=3D 2) T.tm_mon =3D 13; if (argc =3D=3D 3) T.tm_mon =3D -6; asctime_r(&T, buf); puts(buf); //puts(asctime(&T)); } --MP_/4hkF18d+jv6DSixC+.h+dCg-- --Sig_/X3DZ5Nm=z6KZLp3UkkPRNH1 Content-Type: application/pgp-signature Content-Description: Digitale Signatur von OpenPGP -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQSN9stI2OFN1pLljN0P0+hp2tU34gUCX0I9QgAKCRAP0+hp2tU3 4n6VAJ95ul3GpXQ0kFSE2wBGpTZ/rENzOACeN1sK3C5P0yuIVGLiM0DzLbeU+uk= =jHVr -----END PGP SIGNATURE----- --Sig_/X3DZ5Nm=z6KZLp3UkkPRNH1--