1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

formating "fixes".

This commit is contained in:
Alain Magloire 2002-09-26 19:52:44 +00:00
parent b4b7151cf3
commit adcc89e794

View file

@ -13,62 +13,57 @@
#endif #endif
char *pfind( const char *name ) char *pfind(const char *name)
{ {
char *tok; char *tok;
char *sp; char *sp;
char *path = getenv( "PATH" ); char *path = getenv("PATH" );
char FullPath[PATH_MAX+1]; char FullPath[PATH_MAX+1];
if( name == NULL ) if (name == NULL) {
{ fprintf(stderr, "pfind(): Null argument.\n");
fprintf( stderr, "pfind(): Null argument.\n" ); return NULL;
return NULL; }
}
if( path == NULL || strlen( path ) <= 0 ) if (path == NULL || strlen( path ) <= 0) {
{ fprintf(stderr, "Unable to get $PATH.\n");
fprintf( stderr, "Unable to get $PATH.\n" ); return NULL;
return NULL; }
}
// The value return by getenv() is readonly */ // The value return by getenv() is readonly */
path = strdup( path ); path = strdup(path);
tok = strtok_r( path, ":", &sp ); tok = strtok_r(path, ":", &sp);
while( tok != NULL ) while (tok != NULL) {
{ //strcpy(FullPath, tok);
//strcpy( FullPath, tok ); //strcat(FullPath, "/");
//strcat( FullPath, "/" ); //strcat(FullPath, name);
//strcat( FullPath, name );
snprintf(FullPath, sizeof(FullPath) - 1, "%s/%s", tok, name); 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);
free( path ); return strdup(FullPath);
return strdup(FullPath); }
}
tok = strtok_r( NULL, ":", &sp ); tok = strtok_r( NULL, ":", &sp );
} }
free( path ); free(path);
return NULL; return NULL;
} }
#ifdef BUILD_WITH_MAIN #ifdef BUILD_WITH_MAIN
int main( int argc, char **argv ) int main(int argc, char **argv)
{ {
int i; int i;
char *fullpath; char *fullpath;
for( i=1; i<argc; i++ ) for (i=1; i<argc; i++) {
{ fullpath = pfind(argv[i]);
fullpath = pfind( argv[i] ); if (fullpath == NULL)
if( fullpath == NULL ) printf("Unable to find %s in $PATH.\n", argv[i]);
printf( "Unable to find %s in $PATH.\n", argv[i] );
else else
printf( "Found %s @ %s.\n", argv[i], fullpath ); printf("Found %s @ %s.\n", argv[i], fullpath);
} }
} }
#endif #endif