sl@0: /************************************************************************ sl@0: * sl@0: * system.cpp - definitions of testsuite helpers sl@0: * sl@0: * $Id: system.cpp 290012 2005-09-18 23:38:12Z sebor $ sl@0: * sl@0: ************************************************************************ sl@0: * sl@0: * Copyright (c) 1994-2005 Quovadx, Inc., acting through its Rogue Wave sl@0: * Software division. Licensed under the Apache License, Version 2.0 (the sl@0: * "License"); you may not use this file except in compliance with the sl@0: * License. You may obtain a copy of the License at sl@0: * http://www.apache.org/licenses/LICENSE-2.0. Unless required by sl@0: * applicable law or agreed to in writing, software distributed under sl@0: * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR sl@0: * CONDITIONS OF ANY KIND, either express or implied. See the License sl@0: * for the specific language governing permissions and limitations under sl@0: * the License. sl@0: * sl@0: **************************************************************************/ sl@0: sl@0: // expand _TEST_EXPORT macros sl@0: #define _RWSTD_TEST_SRC sl@0: sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include // for va_copy, va_list, ... sl@0: #include // for system sl@0: sl@0: #if !defined (_WIN32) && !defined (_WIN64) sl@0: # include sl@0: # include // for WIFEXITED(), WIFSIGNALED(), WTERMSIG() sl@0: #endif sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: #include sl@0: #endif sl@0: sl@0: /**************************************************************************/ sl@0: sl@0: _TEST_EXPORT int sl@0: rw_vasnprintf (char**, size_t*, const char*, va_list); sl@0: sl@0: /**************************************************************************/ sl@0: sl@0: static int sl@0: _rw_vsystem (const char *cmd, va_list va) sl@0: { sl@0: _RWSTD_ASSERT (0 != cmd); sl@0: sl@0: char buffer [256]; sl@0: char *buf = buffer; sl@0: sl@0: size_t bufsize = sizeof buffer; sl@0: sl@0: rw_vasnprintf (&buf, &bufsize, cmd, va); sl@0: sl@0: rw_note (0, __FILE__, __LINE__, sl@0: "executing \"%s\"", buf); sl@0: sl@0: const int ret = system (buf); sl@0: sl@0: if (ret) { sl@0: sl@0: #if !defined (_WIN32) sl@0: sl@0: if (-1 == ret) { sl@0: // system() failed, e.g., because fork() failed sl@0: rw_error (0, __FILE__, __LINE__, sl@0: "system (\"%s\") failed: errno = %{#m} (%{m})", buf); sl@0: } sl@0: else if (WIFSIGNALED (ret)) { sl@0: // command exited with a signal sl@0: const int signo = WTERMSIG (ret); sl@0: sl@0: rw_error (0, __FILE__, __LINE__, sl@0: "the command \"%s\" exited with signal %d (%{K})", sl@0: buf, signo, signo); sl@0: } sl@0: else { sl@0: // command exited with a non-zero status sl@0: const int status = WEXITSTATUS (ret); sl@0: sl@0: rw_error (0, __FILE__, __LINE__, sl@0: "the command \"%s\" exited with status %d", sl@0: buf, status); sl@0: } sl@0: #else // if defined (_WIN32) sl@0: sl@0: // FIXME: make this more descriptive sl@0: rw_error (0, __FILE__, __LINE__, sl@0: "the command \"%s\" failed with code %d", sl@0: buf, ret); sl@0: sl@0: #endif // _WIN32 sl@0: sl@0: } sl@0: sl@0: if (buf != buffer) sl@0: free (buf); sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: /**************************************************************************/ sl@0: sl@0: _TEST_EXPORT int sl@0: rw_system (const char *cmd, ...) sl@0: { sl@0: va_list va; sl@0: va_start (va, cmd); sl@0: sl@0: const int ret = _rw_vsystem (cmd, va); sl@0: sl@0: va_end (va); sl@0: return ret; sl@0: }