From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 42058 invoked by alias); 24 Jul 2017 19:34:30 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 41101 invoked by uid 89); 24 Jul 2017 19:34:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-pf0-f196.google.com Received: from mail-pf0-f196.google.com (HELO mail-pf0-f196.google.com) (209.85.192.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Jul 2017 19:34:26 +0000 Received: by mail-pf0-f196.google.com with SMTP id k72so7832827pfj.0 for ; Mon, 24 Jul 2017 12:34:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=MJLkza0iwWM1pemm+tdYHqhTaT3AWs4HkR54CaWI6dA=; b=kMt1KOn50u8tRn7eDgqlLKx79mjFzMFWMctfnKVQ6jxnw/SDaV4n4an/caV83BKBbr gcmPjy67Gc1tyhFTl3GTpmR17BSR+QU2xAqfCI9tBMFXN0gAXF/1e57M+8SQjPWstnBd /HZRupH8zT2FaQLLOlLBMcNbYSqBw6BZt94XN4keM92mQ7QXQk7kESoQFcE+JPlE+JYb TrSykz7AfygAA/aZ+ahyoRG+a8EmPtiIrivAUMkmzxPjzTVFSSROUlIiMD6LUsGf4653 YefneCU4TU0IetKaQOQQIJuWiu23B7ONFhde8UC3sUmNMvXZscts7GcbX/kocF7XRiKq zZiQ== X-Gm-Message-State: AIVw111nfNkl8iOf+hlMbGwy184BtQNS7Q4GawuwiE4LcvWWOVYJMhrn HPKTaVTdtV4rkDOw X-Received: by 10.98.64.83 with SMTP id n80mr2535901pfa.225.1500924864719; Mon, 24 Jul 2017 12:34:24 -0700 (PDT) Received: from localhost.localdomain ([203.192.233.164]) by smtp.gmail.com with ESMTPSA id l78sm24215731pfb.59.2017.07.24.12.34.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jul 2017 12:34:24 -0700 (PDT) From: Aditya Upadhyay To: newlib@sourceware.org Cc: Aditya Upadhyay Subject: [PATCH 3/7] Importing imaxdiv inttypes methods from FreeBSD. Date: Mon, 24 Jul 2017 19:34:00 -0000 Message-Id: <20170724193415.16993-1-aadit0402@gmail.com> X-IsSubscribed: yes X-SW-Source: 2017/txt/msg00625.txt.bz2 --- newlib/libc/stdlib/Makefile.am | 1 + newlib/libc/stdlib/imaxdiv.c | 48 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 newlib/libc/stdlib/imaxdiv.c diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am index 117d7c495..76a1a67e4 100644 --- a/newlib/libc/stdlib/Makefile.am +++ b/newlib/libc/stdlib/Makefile.am @@ -34,6 +34,7 @@ GENERAL_SOURCES = \ getenv_r.c \ itoa.c \ imaxabs.c \ + imaxdiv.c \ labs.c \ ldiv.c \ ldtoa.c \ diff --git a/newlib/libc/stdlib/imaxdiv.c b/newlib/libc/stdlib/imaxdiv.c new file mode 100644 index 000000000..eb3e99ad6 --- /dev/null +++ b/newlib/libc/stdlib/imaxdiv.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2001 Mike Barcroft + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: head/lib/libc/stdlib/imaxdiv.c 301115 2016-06-01 10:14:25Z ache $"); + +#include +#include + +/* See comments in div.c for implementation details. */ +imaxdiv_t +imaxdiv(intmax_t numer, intmax_t denom) +{ + imaxdiv_t retval; + + retval.quot = numer / denom; + retval.rem = numer % denom; +#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) + if (numer >= 0 && retval.rem < 0) { + retval.quot++; + retval.rem -= denom; + } +#endif + return (retval); +} -- 2.13.0