test: fix compilation warnings when building with Clang

warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement]

PR-URL: https://github.com/libuv/libuv/pull/67
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
Saúl Ibarra Corretgé 2014-12-13 18:22:10 +01:00
parent 5a8f7931b7
commit 9c8e971443
3 changed files with 16 additions and 14 deletions

View File

@ -68,6 +68,7 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) {
const char* arg;
char* args[16];
int n;
pid_t pid;
stdout_file = tmpfile();
if (!stdout_file) {
@ -78,7 +79,7 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) {
p->terminated = 0;
p->status = 0;
pid_t pid = fork();
pid = fork();
if (pid < 0) {
perror("fork");
@ -167,8 +168,14 @@ static void* dowait(void* data) {
/* Return 0 if all processes are terminated, -1 on error, -2 on timeout. */
int process_wait(process_info_t* vec, int n, int timeout) {
int i;
int r;
int retval;
process_info_t* p;
dowait_args args;
pthread_t tid;
struct timeval tv;
fd_set fds;
args.vec = vec;
args.n = n;
args.pipe[0] = -1;
@ -186,10 +193,7 @@ int process_wait(process_info_t* vec, int n, int timeout) {
* we'd need to lock vec.
*/
pthread_t tid;
int retval;
int r = pipe((int*)&(args.pipe));
r = pipe((int*)&(args.pipe));
if (r) {
perror("pipe()");
return -1;
@ -202,11 +206,9 @@ int process_wait(process_info_t* vec, int n, int timeout) {
goto terminate;
}
struct timeval tv;
tv.tv_sec = timeout / 1000;
tv.tv_usec = 0;
fd_set fds;
FD_ZERO(&fds);
FD_SET(args.pipe[0], &fds);
@ -259,15 +261,16 @@ long int process_output_size(process_info_t *p) {
/* Copy the contents of the stdio output buffer to `fd`. */
int process_copy_output(process_info_t *p, int fd) {
int r = fseek(p->stdout_file, 0, SEEK_SET);
ssize_t nwritten;
char buf[1024];
int r;
r = fseek(p->stdout_file, 0, SEEK_SET);
if (r < 0) {
perror("fseek");
return -1;
}
ssize_t nwritten;
char buf[1024];
/* TODO: what if the line is longer than buf */
while (fgets(buf, sizeof(buf), p->stdout_file) != NULL) {
/* TODO: what if write doesn't write the whole buffer... */

View File

@ -53,6 +53,7 @@ TEST_IMPL(pipe_close_stdout_read_stdin) {
int pid;
int fd[2];
int status;
uv_pipe_t stdin_pipe;
r = pipe(fd);
ASSERT(r == 0);
@ -68,8 +69,6 @@ TEST_IMPL(pipe_close_stdout_read_stdin) {
ASSERT(r != -1);
/* Create a stream that reads from the pipe. */
uv_pipe_t stdin_pipe;
r = uv_pipe_init(uv_default_loop(), (uv_pipe_t *)&stdin_pipe, 0);
ASSERT(r == 0);

View File

@ -1032,6 +1032,7 @@ TEST_IMPL(spawn_with_an_odd_path) {
#ifndef _WIN32
TEST_IMPL(spawn_setuid_setgid) {
int r;
struct passwd* pw;
/* if not root, then this will fail. */
uv_uid_t uid = getuid();
@ -1043,7 +1044,6 @@ TEST_IMPL(spawn_setuid_setgid) {
init_process_options("spawn_helper1", exit_cb);
/* become the "nobody" user. */
struct passwd* pw;
pw = getpwnam("nobody");
ASSERT(pw != NULL);
options.uid = pw->pw_uid;