char * find_cmd_type(Cmd k) { char *str=malloc(100),buffer[10]; char delims[] = ":"; struct stat st; int l; char *result = malloc(100); pPath=malloc(100); char *cmd=malloc(100),*cm=malloc(100); char env[100]; getenviron(); strcpy(cmd,"/"); strcpy(env,pPath); strcat(cmd,k->args[0]); result = strtok( env, delims ); while( result != NULL ) { strcpy(str,result); strcat(str,cmd); if(stat(str,&st)==0) { // printf(" /CMD is present= %s\n",str); return str; } result = strtok( NULL, delims ); } return NULL; }
char * find_cmd_type_where(char * k) { char *str=malloc(100),buffer[10]; char delims[] = ":"; struct stat st; int l; char *result = malloc(100); pPath=malloc(100); char *cmd=malloc(100),*cm=malloc(100); char env[100]; getenviron(); strcpy(cmd,"/"); strcpy(env,pPath); strcat(cmd,k); result = strtok( env, delims ); while( result != NULL ) { strcpy(str,result); strcat(str,cmd); if(stat(str,&st)==0) { return str; } result = strtok( NULL, delims ); } return NULL; }
void call_posix_spawnp() { char * const argv[] = { "cc", "-c", "posix_spawnp.c", 0 }; pid_t child; if (0 != posix_spawnp(&child, "cc", 0, 0, argv, getenviron())) { perror("posix_spawnp"); exit(EXIT_FAILURE); } wait_for(child); }