File:  [Research Unix] / researchv9 / libc / gen / openshares.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:22:00 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv9-SUN3_old, researchv9-SUN3, HEAD
researchv9-SUN3(old)

/*LINTLIBRARY*/

/*
**	Open ``shares'' file and optionally lock it.
*/ 

#include	<sys/types.h>
#include	<sys/lnode.h>
#include	<sys/filio.h>
#include	<shares.h>
#include	<errno.h>
#include	<libc.h>


int		ShareFd;
static char *	ShareFile	= SHAREFILE;
static int	ShareOpen;



int
openshares(lock)
	int	lock;	/* True if writing desired */
{
	if ( ShareOpen )
		return 1;

	if ( (ShareFd = open(ShareFile, 2)) == SYSERROR )
	{
		if ( !lock && (errno == EACCES) )
		{
			if ( (ShareFd = open(ShareFile, 0)) == SYSERROR )
				return 0;
		}
		else
			return 0;
	}

#	ifdef	FIOCLEX
	(void)ioctl(ShareFd, FIOCLEX, 0);	/* close on exec */
#	endif

	ShareOpen = 1;
	errno = 0;

	return 1;
}


void
closeshares()
{
	if ( !ShareOpen )
		return;

	(void)close(ShareFd);

	ShareOpen = 0;
}


void
sharesfile(file)
	char *	file;
{
	closeshares();
	ShareFile = file;
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.