From d00fbf37ee62dc095c3d8d37d07cb0ddd8314c77 Mon Sep 17 00:00:00 2001 From: schmidt Date: Mon, 17 Mar 1997 18:32:04 +0000 Subject: foo --- examples/Mem_Map/IO-tests/IO_Test.cpp | 10 +++--- examples/Mem_Map/IO-tests/test_io.cpp | 66 ++++++++++++++++------------------- 2 files changed, 35 insertions(+), 41 deletions(-) (limited to 'examples/Mem_Map') diff --git a/examples/Mem_Map/IO-tests/IO_Test.cpp b/examples/Mem_Map/IO-tests/IO_Test.cpp index aef0b12c597..ceef5e8e39d 100644 --- a/examples/Mem_Map/IO-tests/IO_Test.cpp +++ b/examples/Mem_Map/IO-tests/IO_Test.cpp @@ -83,7 +83,7 @@ Block_Read_Write_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp while (--iterations >= 0) { char buf[BUFSIZ]; - int n; + ssize_t n; while ((n = ACE_OS::read (ifd, buf, sizeof buf)) > 0) ::write (ofd, buf, n); @@ -109,7 +109,7 @@ Block_Fread_Fwrite_Test::run_test (int iterations, FILE *input_fp, FILE *output_ while (--iterations >= 0) { char buf[BUFSIZ]; - int n; + ssize_t n; while ((n = ACE_OS::fread (buf, 1, sizeof buf, input_fp)) != 0) ::fwrite (buf, n, 1, output_fp); @@ -134,7 +134,7 @@ Mmap1_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp) void *src = 0; if (map_input (src) == -1) - return -1; + ACE_ERROR_RETURN ((ACE_ERROR, "%s", this->name ()), -1); else { this->tm_.start (); @@ -142,7 +142,7 @@ Mmap1_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp) while (--iterations >= 0) { if (ACE_OS::write (fileno (output_fp), src, map_input.size ()) == -1) - return -1; + ACE_ERROR_RETURN ((ACE_ERROR, "%s", this->name ()), -1); ACE_OS::lseek (fileno (output_fp), 0, SEEK_SET); } @@ -150,7 +150,7 @@ Mmap1_Test::run_test (int iterations, FILE *input_fp, FILE *output_fp) } if (map_input.unmap () == -1) - return -1; + ACE_ERROR_RETURN ((ACE_ERROR, "%s", this->name ()), -1); else return 0; } diff --git a/examples/Mem_Map/IO-tests/test_io.cpp b/examples/Mem_Map/IO-tests/test_io.cpp index 0b155fb0631..5e3ad676928 100644 --- a/examples/Mem_Map/IO-tests/test_io.cpp +++ b/examples/Mem_Map/IO-tests/test_io.cpp @@ -47,17 +47,6 @@ cleanup (int = 0) ACE_OS::exit (0); } -// Set up the program name used in error messages. - -static void -set_program_name (char name[]) -{ - if ((name = strrchr (name, '/')) == 0) - program_name = name; - else - program_name = name + 1; -} - // Parse the command-line arguments and set options. static void @@ -86,33 +75,37 @@ parse_args (int argc, char *argv[]) } } -// Vector of pointers to derived classes that inherit from IO_Test base class. +// Vector of pointers to derived classes that inherit from IO_Test +// base class. static IO_Test *test_vector[100]; static void run_tests (int iterations, FILE *input_fp, FILE *output_fp) { - // If HP/UX didn't suck so badly we could initialize in the global scope... - test_vector[0] = new Stdio_Test ("Stdio_Test", tm); - test_vector[1] = new Block_Fread_Fwrite_Test ("Block_Fread_Fwrite_Test", tm); - test_vector[2] = new Block_Read_Write_Test ("Block_Read_Write_Test", tm); - test_vector[3] = new Mmap1_Test ("Mmap1_Test", tm); - test_vector[4] = new Mmap2_Test ("Mmap2_Test", tm); - // test_vector[5] = new Slow_Read_Write_Test ("Slow"Read_Write_Test", tm) - test_vector[5] = (IO_Test *) 0; - - for (int i = 0; test_vector[i] != 0; i++) + // If HP/UX didn't suck so badly we could initialize in the global + // scope... + int i = 0; + + ACE_NEW (test_vector[i++], Stdio_Test ("Stdio_Test", tm)); + ACE_NEW (test_vector[i++], Block_Fread_Fwrite_Test ("Block_Fread_Fwrite_Test", tm)); + ACE_NEW (test_vector[i++], Block_Read_Write_Test ("Block_Read_Write_Test", tm)); + ACE_NEW (test_vector[i++], Mmap1_Test ("Mmap1_Test", tm)); + ACE_NEW (test_vector[i++], Mmap2_Test ("Mmap2_Test", tm)); + ACE_NEW (test_vector[i++], Slow_Read_Write_Test ("Slow_Read_Write_Test", tm)); + + test_vector[i] = (IO_Test *) 0; + + for (i = 0; test_vector[i] != 0; i++) { if (ACE_OS::ftruncate (fileno (output_fp), 0) == -1) - ::perror ("ftruncate"); + ACE_ERROR_RETURN ((ACE_ERROR, "%s\n", "ftruncate")); cerr << "--------------------\n" << "starting " << test_vector[i]->name () << " for " << iterations << " iteration(s):\n"; - if (test_vector[i]->run_test (iterations, input_fp, output_fp) == -1) - ::perror (test_vector[i]->name ()); + test_vector[i]->run_test (iterations, input_fp, output_fp); ACE_Profile_Timer::ACE_Elapsed_Time et; tm.elapsed_time (et); @@ -130,27 +123,28 @@ run_tests (int iterations, FILE *input_fp, FILE *output_fp) int main (int argc, char *argv[]) { - FILE *input_fp; - FILE *output_fp; - - set_program_name (argv[0]); + program_name = ACE::basename (argv[0]); parse_args (argc, argv); ACE_Sig_Action sa ((ACE_SignalHandler) cleanup, SIGINT); ACE_UNUSED_ARG (sa); - if ((input_fp = ACE_OS::fopen (input_filename, "r")) == 0) - ACE_OS::perror (input_filename), ACE_OS::exit (1); + FILE *input_fp = ACE_OS::fopen (input_filename, "r"); + FILE *output_fp = ACE_OS::fopen (output_filename, "w+"); - ACE_OS::unlink (output_filename); + if (input_fp == 0) + ACE_ERROR_RETURN ((ACE_ERROR, "%s\n", "input_filename"), -1); + + if (output_fp == 0) + ACE_ERROR_RETURN ((ACE_ERROR, "%s\n", "output_filename"), -1); - if ((output_fp = ACE_OS::fopen (output_filename, "w+")) == 0) - ACE_OS::perror (output_filename), ACE_OS::exit (1); + ACE_OS::unlink (output_filename); run_tests (iteration_count, input_fp, output_fp); - if (ACE_OS::fclose (input_fp) == -1 || ACE_OS::fclose (output_fp) == -1) - ACE_OS::perror ("fclose"), ACE_OS::exit (1); + if (ACE_OS::fclose (input_fp) == -1 + || ACE_OS::fclose (output_fp) == -1) + ACE_ERROR_RETURN ((ACE_ERROR, "%s\n", "fclose"), -1); cleanup (); return 0; -- cgit v1.2.1