Update contrib.
1 /************************************************************************
3 * system.cpp - definitions of testsuite helpers
5 * $Id: system.cpp 290012 2005-09-18 23:38:12Z sebor $
7 ************************************************************************
9 * Copyright (c) 1994-2005 Quovadx, Inc., acting through its Rogue Wave
10 * Software division. Licensed under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance with the
12 * License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0. Unless required by
14 * applicable law or agreed to in writing, software distributed under
15 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
16 * CONDITIONS OF ANY KIND, either express or implied. See the License
17 * for the specific language governing permissions and limitations under
20 **************************************************************************/
22 // expand _TEST_EXPORT macros
23 #define _RWSTD_TEST_SRC
30 #include <stdarg.h> // for va_copy, va_list, ...
31 #include <stdlib.h> // for system
33 #if !defined (_WIN32) && !defined (_WIN64)
35 # include <sys/wait.h> // for WIFEXITED(), WIFSIGNALED(), WTERMSIG()
42 /**************************************************************************/
45 rw_vasnprintf (char**, size_t*, const char*, va_list);
47 /**************************************************************************/
50 _rw_vsystem (const char *cmd, va_list va)
52 _RWSTD_ASSERT (0 != cmd);
57 size_t bufsize = sizeof buffer;
59 rw_vasnprintf (&buf, &bufsize, cmd, va);
61 rw_note (0, __FILE__, __LINE__,
62 "executing \"%s\"", buf);
64 const int ret = system (buf);
71 // system() failed, e.g., because fork() failed
72 rw_error (0, __FILE__, __LINE__,
73 "system (\"%s\") failed: errno = %{#m} (%{m})", buf);
75 else if (WIFSIGNALED (ret)) {
76 // command exited with a signal
77 const int signo = WTERMSIG (ret);
79 rw_error (0, __FILE__, __LINE__,
80 "the command \"%s\" exited with signal %d (%{K})",
84 // command exited with a non-zero status
85 const int status = WEXITSTATUS (ret);
87 rw_error (0, __FILE__, __LINE__,
88 "the command \"%s\" exited with status %d",
91 #else // if defined (_WIN32)
93 // FIXME: make this more descriptive
94 rw_error (0, __FILE__, __LINE__,
95 "the command \"%s\" failed with code %d",
108 /**************************************************************************/
111 rw_system (const char *cmd, ...)
116 const int ret = _rw_vsystem (cmd, va);