🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #31497

Re: Three questions.

#31497
From: Daniel A. Glasser
Date: Fri, 25 Mar 1988 21:19
99 lines
4250 bytes
The documentation for these two routines was omitted from the first few
revisons of the MWC manual.  They were included in the manual (revison 4)
that was shipped with version 2.1.7.  With several products on the market
and several more in development, sometimes these things slip past overworked
tech writers...  (and those who review the manual drafts)

access -- unix standard library function (libc)
	Check to see if a file can be accessed in a given mode
	#include <access.h>
	int access(filename, mode) char *filename; int mode;

	access check whether a file can be accessed in the mode you wish.
	filename is the full path name of the file you wish to check.
	mode is the mode in which you wish to access file filename, as
	follows:
	      value	define		access
		1	AEXEC		execute	
		2	AWRITE		write/append
		4	AREAD		read
	The defined values are set up by the header, access.h.
	access returns zero if filename can be accessed in the requested mode,
	non-zero if not.

	<example omitted>


path -- Coherent library function (libc)
	find a file in directories specified in a path list
	#include <stdio.h>
	#include <path.h>
	char *path(pathlst, filename, mode) char *pathlst, *filename; int mode;

	path is a general function that finds a file along a path.
	pathlst points to a null terminated string containing the names
	of the directories to be searched for filename, in search order,
	separated by commas.  filename points to a null terminated string
	containing the name of the file (including extension) for the
	search, and mode is the mode of access desired, as used in the
	libc function access.  path searches each directory in pathlst
	until a file with name filename that can be accessed for the
	desired mode is found or the end of the list is reached.
	If the file is found, path returns a pointer to a static internal
	buffer that contains the pathname that the file can be opened as.
	This buffer is overwritten by subsequent calls to path.
	If the file is not found, path returns NULL.

	The header file path.h includes default paths for lookup of
	binary (programs) and library (programs, data, objects, etc.)
	files, defined as DEFPATH and DEFLIBPATH, respectively.
	(these correspond to the PATH and LIBPATH environment variables
	used in MSH.)

	example:

/*
 * Search along PATH (or a default) for each of the files on the command
 * line.  Prints out the first occurrence of each file to which you have
 * execute access that is found, or a message that says it is not found
 * if it can't find it.
 *
 * This is not the example for path() from the Mark Williams C manual,
 * similar, but not the same.
 */
#include <stdio.h>
#include <path.h>

extern char *path();
extern char *getenv();

main(argc, argv)
int argc;
char *argv[];
{
	char *fullpath, *pathspec;
	int i;

	/* We are going to look up our files along PATH, from the env. */
	if ((pathspec = getenv("PATH")) == NULL)
		pathspec = DEFPATH;	/* If none in the env, use default */

	/* Loop through all the files... */
	for (i = 1; i < argc; ++i)
		if ((fullpath = path(pathspec, argv[i], 1)) == NULL)
			printf("%s not found along path %s\n",
				argv[i], pathspec);
		else
			printf("%s found as %s\n", argv[i], fullpath);
	exit(0);
}


Note that the above example program was written out of my head.  I used
the MWC manual for the text, though I paraphrased a bit, but the example
is new and I have not tested this program.  I believe it should work.

-- 
		Daniel A. Glasser	dag@chinet.UUCP
    One of those things that goes "BUMP!!! (ouch!)" in the night.
 ...!att-ih!chinet!dag | ...!ihnp4!mwc!dag | ...!ihnp4!mwc!gorgon!dag
Technical Details
Message-ID: <4121@chinet.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!amdahl!pacbell!att-ih!chinet!dag
References: <1988Feb22.221218.13780@jarvis.csri.toronto.edu> <80@obie.UUCP> <374@brambo.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!amdahl!pacbell!att-ih!chinet!dag
From: dag@chinet.UUCP (Daniel A. Glasser)
Newsgroups: comp.sys.atari.st
Subject: Re: Three questions.
Message-ID: <4121@chinet.UUCP>
Date: 25 Mar 88 21:19:03 GMT
References: <1988Feb22.221218.13780@jarvis.csri.toronto.edu> <80@obie.UUCP> <374@brambo.UUCP>
Reply-To: dag@chinet.UUCP (Daniel A. Glasser)
Organization: Chinet - Public Access Unix
Lines: 98
Keywords: MWC system() malloc() free()
Summary: path() and access() documentation