Permalink
Browse files

better way to test only the cmd part of 'program'

Thanks to juster on ArchLinux forums.
  • Loading branch information...
1 parent d8f57a2 commit d75b2480f815ecd940ffd546eab65e35d7a5b160 @fukawi2 committed Feb 1, 2012
Showing with 11 additions and 7 deletions.
  1. +11 −7 amqpspawn.c
View
@@ -288,14 +288,18 @@ int main(int argc, char **argv) {
if (NULL != program) {
// check that the program is executable
- char *program_cmd = malloc( (strlen(program) + 1) * sizeof(char));
- strcpy(program_cmd,program);
- *strchr(program_cmd,' ') = '\0';
- if (0 != access(program_cmd, X_OK)) {
- fprintf(stderr, "Program doesn't have execute permission, aborting: %s\n", program_cmd);
- exit(-1);
+ char *wend;
+ wend = strchr(program, ' ');
+ if(wend){
+ *wend = '\0';
+ }
+ if (0 != access(program, X_OK)) {
+ fprintf(stderr, "Program doesn't have execute permission, aborting: %s\n", program);
+ exit(-1);
+ }
+ if(wend){
+ *wend = ' ';
}
- free(program_cmd);
}
if ((passive != 0) && (passive != 1)) {

0 comments on commit d75b248

Please sign in to comment.