/*	Willows Software, Inc. - Jun 1996	*/
/*	"@(#)MWftruncate.c	1.2 :/users/sccs/src/win/library/mac/s.MWftruncate.c 4/21/97 12:58:51" */

#include <errno.h>
#include <unistd.h>
#include <Files.h>

int ftruncate(int, long);

/*
 *	int ftruncate(int fildes, long length)
 *	
 *		truncate a file (fildes is the MacOS refnum).
 */
int ftruncate(int fildes, long length)
{
	IOParam			pb;
	OSErr			err;

	if (fildes >= 0 && fildes <= 2) return -1;

	pb.ioRefNum = fildes;
	pb.ioMisc = (Ptr)length;

	err = PBSetEOFSync((ParmBlkPtr) &pb);


	if (err != noErr)
		errno = err;
	return (err == noErr ? 0 : -1);
}
