Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:3738 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49931 invoked from network); 5 Aug 2003 20:48:11 -0000 Received: from unknown (HELO bgbest.net) (212.91.188.18) by pb1.pair.com with SMTP; 5 Aug 2003 20:48:11 -0000 Received: (qmail 5292 invoked from network); 5 Aug 2003 20:48:07 -0000 Received: from unknown (HELO damagegqsaogpp) (212.91.188.166) by dns.bgbest.net with SMTP; 5 Aug 2003 20:48:07 -0000 To: "PHP-DEV" Date: Tue, 5 Aug 2003 23:47:53 +0300 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Subject: Patch for command-line version of PHP From: vma1@abv.bg ("Vesselin Atanasov") Hello. Here is a patch for the command-line version of PHP which makes it chdir() to the script directory just like the web version of PHP does. It also implements the -C option which has been a NOOP up to now. diff -ruN php5-200308051930.orig/sapi/cli/php_cli.c php5-200308051930/sapi/cli/php_cli.c --- php5-200308051930.orig/sapi/cli/php_cli.c 2003-08-01 17:08:26.000000000 +0000 +++ php5-200308051930/sapi/cli/php_cli.c 2003-08-05 23:39:38.000000000 +0000 @@ -360,6 +360,7 @@ " %s [options] -- [args...]\n" "\n" " -a Run interactively\n" + " -C Don't chdir to the script directory\n" " -c | Look for php.ini file in this directory\n" " -n No php.ini file will be used\n" " -d foo[=bar] Define INI entry foo with value 'bar'\n" @@ -527,6 +528,8 @@ const char *param_error=NULL; int scan_input = 0; int hide_argv = 0; + int no_chdir=0; + char *new_cwd; /* end of temporary locals */ #ifdef ZTS zend_compiler_globals *compiler_globals; @@ -685,7 +688,7 @@ break; case 'C': /* don't chdir to the script directory */ - /* This is default so NOP */ + no_chdir = 1; break; case 'd': /* define ini entries on command line */ define_command_line_ini_entry(optarg); @@ -902,6 +905,12 @@ zend_llist_destroy(&global_vars); PG(during_request_startup) = 0; + if (!no_chdir && strcmp(file_handle.filename, "-")) { + new_cwd = strdup(file_handle.filename); + php_dirname(new_cwd, strlen(new_cwd)); + chdir(new_cwd); + free(new_cwd); + } switch (behavior) { case PHP_MODE_STANDARD: if (strcmp(file_handle.filename, "-")) {