Return-Path: Delivered-To: apmail-stdcxx-commits-archive@www.apache.org Received: (qmail 77440 invoked from network); 28 May 2008 19:03:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 May 2008 19:03:03 -0000 Received: (qmail 79295 invoked by uid 500); 28 May 2008 19:03:05 -0000 Delivered-To: apmail-stdcxx-commits-archive@stdcxx.apache.org Received: (qmail 79267 invoked by uid 500); 28 May 2008 19:03:05 -0000 Mailing-List: contact commits-help@stdcxx.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@stdcxx.apache.org Delivered-To: mailing list commits@stdcxx.apache.org Received: (qmail 79258 invoked by uid 99); 28 May 2008 19:03:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 May 2008 12:03:05 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 May 2008 19:02:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 33ACD2388A0F; Wed, 28 May 2008 12:02:40 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r661050 - /stdcxx/branches/4.2.x/util/exec.cpp Date: Wed, 28 May 2008 19:02:40 -0000 To: commits@stdcxx.apache.org From: sebor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080528190240.33ACD2388A0F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sebor Date: Wed May 28 12:02:39 2008 New Revision: 661050 URL: http://svn.apache.org/viewvc?rev=661050&view=rev Log: 2008-05-28 Martin Sebor STDCXX-946 * util/exec.cpp (rw_charcasecmp): Folded into... (rw_strcasecmp): ...here. Rewrote a for loop as a do/while loop to silence HP aCC 6 remark #4315-D: for loop without body, did you insert an extra ';'? (get_signo): Corrected the interpretation of exit status of 126 and 127 used to indicate a "cannot execute" and "executable does not exist" errors, respectively. (exec_file): Exit with status of 126 on execv() failure. * util/exec.cpp (calculate_usage, exec_file): Cast literal to the correct type to silence HP aCC 6 warning #2068-D: integer conversion resulted in a change of sign. Modified: stdcxx/branches/4.2.x/util/exec.cpp Modified: stdcxx/branches/4.2.x/util/exec.cpp URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/util/exec.cpp?rev=661050&r1=661049&r2=661050&view=diff ============================================================================== --- stdcxx/branches/4.2.x/util/exec.cpp (original) +++ stdcxx/branches/4.2.x/util/exec.cpp Wed May 28 12:02:39 2008 @@ -329,22 +329,6 @@ }; /** - Compare two characters in a case-insensitive manner - - @param c1 first character to compare - @param c2 second character to compare - @return an integer less than, equal to, or greater than 0, coresponding - to whether c1 is less than, equal to, or greater than c2 when compared - in a case insensitive manner. -*/ -static int -rw_charcasecmp (char c1, char c2) -{ - typedef unsigned char UChar; - return tolower ((UChar)c1) - tolower ((UChar)c2); -} - -/** Reimplementation of the POSIX strcasecmp function. This is a simplistic (re)implementation of the strcasecmp function @@ -361,15 +345,19 @@ { int delta; + typedef unsigned char UChar; + assert (0 != s1); assert (0 != s2); - for (delta = rw_charcasecmp (*s1, *s2); - *s1 && *s2 && 0 == delta; - delta = rw_charcasecmp (*(++s1), *(++s2))); + do { + delta = tolower ((UChar)*s1) - tolower ((UChar)*s2); + } while (*s1++ && *s2++ && 0 == delta); + return delta; } + int get_signo (const char* signame) { @@ -529,12 +517,21 @@ if (child_pid == wait_pid) { if (WIFEXITED (status)) { result->exit = WEXITSTATUS (status); + + /* from POSIX, 2.8.2 Exit Status for Commands: + * + * If a command is not found, the exit status shall be 127. + * If the command name is found, but it is not an executable + * utility, the exit status shall be 126. Applications that + * invoke utilities without using the shell should use these + * exit status values to report similar errors. + */ switch (result->exit) { case 126: - result->status = ST_EXIST; + result->status = ST_EXECUTE; break; case 127: - result->status = ST_EXECUTE; + result->status = ST_EXIST; break; } break; /*we've got an exit state, so let's bail*/ @@ -791,7 +788,7 @@ c_clk = times (&c_tms); - if (-1 == c_clk) { + if ((clock_t)-1 == c_clk) { warn ("Failed to retrieve ending times: %s", strerror (errno)); return; } @@ -872,7 +869,8 @@ fprintf (error_file, "%s (%s): execv (\"%s\", ...) error: %s\n", exe_name, target_name, options->argv [0], strerror (errno)); - exit (1); + /* POSIX specifies status of 126 for exec failures */ + exit (126); } if (-1 == child_pid) { @@ -885,7 +883,7 @@ struct tms h_tms; clock_t h_clk = times (&h_tms); wait_for_child (child_pid, options->timeout, result); - if (-1 != h_clk) + if ((clock_t)-1 != h_clk) calculate_usage (result, h_clk, &h_tms); else warn ("Failed to retrieve start times: %s", strerror (errno));