/* See the copyright notice (COPYRIGHT) in this directory. */

/*
 * NAME
 *	pg_strncpy()	- null terminated strncpy
 *
 * DESCRIPTION
 *	This file contains miscellaneous utilities. Once robust and
 *	usefulness validated, will likely end up in the main gdi.
 *
 * FILES
 *	pg_util.c (this file)
 *
 * SEE ALSO
 *	libgendb.h
 *	gdi_postgres.h
 *
 * AUTHOR
 *	J. T. Anderson
 */

#ifndef	lint
static char SccsId[] = "@(#)pg_util.c	16.1 8/3/93 Copyright (c) 1992-1993 Science Applications International Corporation";
#endif

#include "gdi_postgres.h"

/* pg_strncpy ()
 *
 * This does strncpy, guaranteeing null termination.
 *
 * Public
 */

char *
pg_strncpy (to, from, to_len, from_len)
char	*to;
char	*from;
int	to_len;
int     from_len;
{
        int copy_len;

	if(to == NULL)
	{	gdi_error_app(NULL, GDI_BADDATA,
			"pg_strncpy: destination string is NULL.");
		return ( (char *) NULL);
	}

	if( (from_len > 0) && (to_len > 0) )
        {	
		if(from_len >= to_len)
			copy_len = to_len;
		else
			copy_len = from_len;

                bcopy(from, to, copy_len);
                to[copy_len] = '\0';
        }
	return(to);
}
