delorie.com/djgpp/doc/libc/libc_188.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

__dosexec_find_on_path

Syntax

 
#include <stdio.h>
#include <libc/dosexec.h>

char *__dosexec_find_on_path(const char *program,
                             char *envp[], char *buf);

Description

This function searches for a program using a given path. The program is searched for using a known set of executable extensions, e.g. `.exe'. These executable extensions are described for the spawn*() function (see section spawn*).

Pass the program name in program, the environment array in envp and the output buffer in buf. envp is an array of pointers to the environment variables; it must be terminated with a NULL pointer. buf must be large enough to hold at least `FILENAME_MAX' bytes.

envp controls where __dosexec_find_on_path looks for the program. If envp is NULL, then only the current directory is searched. If envp contains the `PATH' environment variable whose value lists several directories, then these directories are also searched. The global variable environ is usually passed for envp.

Return Value

If the function finds the program, with or without one of the known executable extensions, either in the current directory or along the `PATH' as recorded in envp, it puts the full pathname into buf and returns a pointer to buf. Otherwise, it returns NULL.

Portability

ANSI/ISO C No
POSIX No

Example

 
 char shellpath[FILENAME_MAX];
 extern char * __dosexec_find_on_path (const char *, char *[], char *);
 extern char **environ;

 /* See if we can find "/bin/sh.exe", "/bin/sh.com", etc.  */
 if (__dosexec_find_on_path ("/bin/sh", (char **)0, shellpath)
     /* If not found, look for "sh" along the PATH.  */
     || __dosexec_find_on_path ("sh", environ, shellpath))
   printf ("/bin/sh found as `%s'\n", shellpath);


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004