1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 23:05:47 +02:00

Reformat to be Unix format. Check the program

with access() to see if executable.
This commit is contained in:
Alain Magloire 2002-10-17 15:52:57 +00:00
parent b968757017
commit cad297693f

View file

@ -17,17 +17,25 @@ char *pfind( const char *name )
{
char *tok;
char *sp;
char *path = getenv( "PATH" );
char FullPath[PATH_MAX+1];
char *path;
char fullpath[PATH_MAX+1];
if( name == NULL )
{
if (name == NULL) {
fprintf(stderr, "pfind(): Null argument.\n");
return NULL;
}
if( path == NULL || strlen( path ) <= 0 )
{
/* For absolute namer or name with a path, check if it is an executable. */
if (name[0] == '/' || name[0] == '.') {
if (access(name, X_OK | R_OK) == 0) {
return strdup(name);
}
return NULL;
}
/* Search in the PATH environment. */
path = getenv("PATH");
if (path == NULL || strlen(path) <= 0) {
fprintf(stderr, "Unable to get $PATH.\n");
return NULL;
}
@ -36,17 +44,12 @@ char *pfind( const char *name )
path = strdup(path);
tok = strtok_r(path, ":", &sp);
while( tok != NULL )
{
//strcpy( FullPath, tok );
//strcat( FullPath, "/" );
//strcat( FullPath, name );
snprintf(FullPath, sizeof(FullPath) - 1, "%s/%s", tok, name);
while (tok != NULL) {
snprintf(fullpath, sizeof(fullpath) - 1, "%s/%s", tok, name);
if( access( FullPath, X_OK | R_OK ) == 0 )
{
if (access(fullpath, X_OK | R_OK) == 0) {
free(path);
return strdup(FullPath);
return strdup(fullpath);
}
tok = strtok_r(NULL, ":", &sp);
@ -62,8 +65,7 @@ int main( int argc, char **argv )
int i;
char *fullpath;
for( i=1; i<argc; i++ )
{
for (i = 1; i<argc; i++) {
fullpath = pfind(argv[i]);
if (fullpath == NULL)
printf("Unable to find %s in $PATH.\n", argv[i]);