You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2008/05/28 21:02:40 UTC

svn commit: r661050 - /stdcxx/branches/4.2.x/util/exec.cpp

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  <se...@roguewave.com>

	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));