ftruncate.c revision 1.8
11.8Skleink/*	$NetBSD: ftruncate.c,v 1.8 1998/10/14 11:25:19 kleink Exp $	*/
21.3Scgd
31.2Scgd/*
41.2Scgd * Copyright (c) 1992, 1993
51.2Scgd *	The Regents of the University of California.  All rights reserved.
61.2Scgd *
71.2Scgd * Redistribution and use in source and binary forms, with or without
81.2Scgd * modification, are permitted provided that the following conditions
91.2Scgd * are met:
101.2Scgd * 1. Redistributions of source code must retain the above copyright
111.2Scgd *    notice, this list of conditions and the following disclaimer.
121.2Scgd * 2. Redistributions in binary form must reproduce the above copyright
131.2Scgd *    notice, this list of conditions and the following disclaimer in the
141.2Scgd *    documentation and/or other materials provided with the distribution.
151.2Scgd * 3. All advertising materials mentioning features or use of this software
161.2Scgd *    must display the following acknowledgement:
171.2Scgd *	This product includes software developed by the University of
181.2Scgd *	California, Berkeley and its contributors.
191.2Scgd * 4. Neither the name of the University nor the names of its contributors
201.2Scgd *    may be used to endorse or promote products derived from this software
211.2Scgd *    without specific prior written permission.
221.2Scgd *
231.2Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
241.2Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
251.2Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
261.2Scgd * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
271.2Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
281.2Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
291.2Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
301.2Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
311.2Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
321.2Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
331.2Scgd * SUCH DAMAGE.
341.2Scgd */
351.2Scgd
361.7Schristos#include <sys/cdefs.h>
371.2Scgd#if defined(LIBC_SCCS) && !defined(lint)
381.3Scgd#if 0
391.3Scgdstatic char sccsid[] = "@(#)ftruncate.c	8.1 (Berkeley) 6/17/93";
401.3Scgd#else
411.8Skleink__RCSID("$NetBSD: ftruncate.c,v 1.8 1998/10/14 11:25:19 kleink Exp $");
421.3Scgd#endif
431.2Scgd#endif /* LIBC_SCCS and not lint */
441.1Scgd
451.8Skleink#include "namespace.h"
461.1Scgd#include <sys/types.h>
471.1Scgd#include <sys/syscall.h>
481.4Scgd#include <unistd.h>
491.8Skleink
501.8Skleink#ifdef __weak_alias
511.8Skleink__weak_alias(ftruncate,_ftruncate);
521.8Skleink#endif
531.1Scgd
541.2Scgd/*
551.2Scgd * This function provides 64-bit offset padding that
561.2Scgd * is not supplied by GCC 1.X but is supplied by GCC 2.X.
571.2Scgd */
581.1Scgdint
591.2Scgdftruncate(fd, length)
601.2Scgd	int	fd;
611.2Scgd	off_t	length;
621.1Scgd{
631.6Scgd	quad_t q;
641.6Scgd	int rv;
651.1Scgd
661.6Scgd	q = __syscall((quad_t)SYS_ftruncate, fd, 0, length);
671.6Scgd	if (sizeof (quad_t) == sizeof (register_t) ||
681.6Scgd	    BYTE_ORDER == LITTLE_ENDIAN)
691.6Scgd		rv = (int)q;
701.6Scgd	else
711.6Scgd		rv = (int)(q >> 32);
721.6Scgd	return rv;
731.1Scgd}
74