2 #include <stdio.h> /* for FILE etc */
3 #include <stdlib.h> /* for malloc */
4 #include <string.h> /* for making ftw.h happy */
5 #include <unistd.h> /* for fork exec */
7 #include "pnd_utility.h"
9 // a generalized variable-substitution routine might be nice; for now we need a quick tilde one,
10 // so here goes. Brute force ftw!
11 char *pnd_expand_tilde ( char *freeable_buffer ) {
13 char *s = freeable_buffer;
14 char *home = getenv ( "HOME" );
17 return ( s ); // can't succeed
20 while ( ( p = strchr ( s, '~' ) ) ) {
21 char *temp = malloc ( strlen ( s ) + strlen ( home ) + 1 );
22 memset ( temp, '\0', strlen ( s ) + strlen ( home ) + 1 );
23 // copy in stuff prior to ~
24 strncpy ( temp, s, p - s );
26 strcat ( temp, home );
27 // copy stuff after tilde in
28 strcat ( temp, p + 1 );
32 } // while finding matches
37 void pnd_exec_no_wait_1 ( char *fullpath, char *arg1 ) {
40 if ( ( i = fork() ) < 0 ) {
41 printf ( "ERROR: Couldn't fork()\n" );
46 return; // parent process, don't care
49 // child process, do something
51 execl ( fullpath, fullpath, arg1, (char*) NULL );
53 execl ( fullpath, fullpath, (char*) NULL );
56 // getting here is an error
57 //printf ( "Error attempting to run %s\n", fullpath );