190792Sgshapiro/*
2261370Sgshapiro * Copyright (c) 1990, 1993
390792Sgshapiro *	The Regents of the University of California.  All rights reserved.
490792Sgshapiro *
590792Sgshapiro * This code is derived from software contributed to Berkeley by
690792Sgshapiro * Chris Torek.
790792Sgshapiro *
890792Sgshapiro * Redistribution and use in source and binary forms, with or without
990792Sgshapiro * modification, are permitted provided that the following conditions
1090792Sgshapiro * are met:
11266711Sgshapiro * 1. Redistributions of source code must retain the above copyright
1290792Sgshapiro *    notice, this list of conditions and the following disclaimer.
1390792Sgshapiro * 2. Redistributions in binary form must reproduce the above copyright
1490792Sgshapiro *    notice, this list of conditions and the following disclaimer in the
1590792Sgshapiro *    documentation and/or other materials provided with the distribution.
1690792Sgshapiro * 4. Neither the name of the University nor the names of its contributors
1790792Sgshapiro *    may be used to endorse or promote products derived from this software
1890792Sgshapiro *    without specific prior written permission.
1990792Sgshapiro *
2090792Sgshapiro * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2190792Sgshapiro * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2290792Sgshapiro * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2390792Sgshapiro * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2490792Sgshapiro * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2590792Sgshapiro * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2690792Sgshapiro * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2790792Sgshapiro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2890792Sgshapiro * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2990792Sgshapiro * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3090792Sgshapiro * SUCH DAMAGE.
3190792Sgshapiro */
3290792Sgshapiro
3390792Sgshapiro#if defined(LIBC_SCCS) && !defined(lint)
3490792Sgshapirostatic char sccsid[] = "@(#)ldiv.c	8.1 (Berkeley) 6/4/93";
3590792Sgshapiro#endif /* LIBC_SCCS and not lint */
3690792Sgshapiro#include <sys/cdefs.h>
3790792Sgshapiro__FBSDID("$FreeBSD$");
3890792Sgshapiro
3990792Sgshapiro#include <stdlib.h>		/* ldiv_t */
4090792Sgshapiro
4190792Sgshapiroldiv_t
4290792Sgshapiroldiv(num, denom)
4390792Sgshapiro	long num, denom;
4490792Sgshapiro{
4590792Sgshapiro	ldiv_t r;
4690792Sgshapiro
4790792Sgshapiro	/* see div.c for comments */
4890792Sgshapiro
4990792Sgshapiro	r.quot = num / denom;
5090792Sgshapiro	r.rem = num % denom;
5190792Sgshapiro	if (num >= 0 && r.rem < 0) {
5290792Sgshapiro		r.quot++;
5390792Sgshapiro		r.rem -= denom;
5490792Sgshapiro	}
5590792Sgshapiro	return (r);
5690792Sgshapiro}
5790792Sgshapiro