/*
 *   Copyright (C) 1988-2006 Lucent Technologies Inc. and others.
 *   All Rights Reserved.
 */

/* vpaccess - view path version of the access system call */

#ifdef __BORLANDC__
#include <io.h>
#include <stdio.h>
#endif

#include "vp.h"
#ifdef CCS
#include <sys/types.h>
#include "ccstypes.h"
#else
typedef unsigned mode_t;
#endif
 
vpaccess(path, amode)
char	*path;
mode_t	amode;
{
	char	buf[MAXPATH + 1];
	int	returncode;
	int	i;

#if defined(__BORLANDC__) || defined(FOR_WIN32)
	if ((returncode = access(compath(path), amode)) == -1 && (path[0] != '/' && path[0] != '\\')) {
#else
	if ((returncode = access(path, amode)) == -1 && path[0] != '/') {
#endif
		vpinit((char *) 0);
		for (i = 1; i < vpndirs; i++) {
			(void) sprintf(buf, "%s/%s", vpdirs[i], path);
			if ((returncode = access(compath(buf), amode)) != -1) {
				break;
			}
		}
	}
	return(returncode);
}
