diff: io__remove_file bug fix

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Jan 22 13:19:37 AEDT 1998


library/io.m:
	Fix a bug in io__remove_file_2 that was spotted by
	Thomas By <T.By at dcs.shef.ac.uk>: a call to strcpy()
	in the pragma c_code had the wrong argument, causing
	it to do the wrong thing in the case where io__remove_file
	returned an error.

tests/hard_coded/Mmakefile:
tests/hard_coded/remove_file.m:
tests/hard_coded/remove_file.exp:
	Regression test.

cvs diff  library/io.m tests/hard_coded/Mmakefile tests/hard_coded/remove_file.exp tests/hard_coded/remove_file.m
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.146
diff -u -r1.146 io.m
--- io.m	1998/01/13 09:59:25	1.146
+++ io.m	1998/01/22 01:51:15
@@ -2748,7 +2748,7 @@
 		buf = strerror(errno);
 		incr_hp_atomic(tmp,(strlen(buf)+sizeof(Word)) / sizeof(Word));
 		RetStr = (char *)tmp;
-		strcpy(RetStr, (char *)tmp);
+		strcpy(RetStr, buf);
 	} else {
 		RetStr = NULL;
 	}
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.8
diff -u -r1.8 Mmakefile
--- Mmakefile	1998/01/21 06:11:17	1.8
+++ Mmakefile	1998/01/22 02:06:28
@@ -53,6 +53,7 @@
 	qual_adv_test \
 	qual_basic_test \
 	qual_is_test \
+	remove_file \
 	reorder_di \
 	reverse_arith \
 	string_alignment \
Index: tests/hard_coded/remove_file.exp
===================================================================
RCS file: remove_file.exp
diff -N remove_file.exp
--- /dev/null	Thu Jan 22 13:03:24 1998
+++ remove_file.exp	Thu Jan 22 13:07:43 1998
@@ -0,0 +1,2 @@
+Test passed
+Second remove failed, as expected: No such file or directory
Index: tests/hard_coded/remove_file.m
===================================================================
RCS file: remove_file.m
diff -N remove_file.m
--- /dev/null	Thu Jan 22 13:03:24 1998
+++ remove_file.m	Thu Jan 22 13:10:48 1998
@@ -0,0 +1,50 @@
+:- module remove_file.
+:- interface.
+:- use_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+main -->
+	io__tmpnam(Name),
+%%%%%%%	io__print("Temp file name = "), io__print(Name), io__nl,
+	io__tell(Name, TellResult),
+	( { TellResult = io__ok },
+		io__print("Just testing"), io__nl,
+		io__told,
+		io__remove_file(Name, RemoveResult),
+		( { RemoveResult = io__ok },
+			io__see(Name, SeeResult),
+			( { SeeResult = io__ok } ->
+				io__print("Remove didn't remove file\n"),
+				io__set_exit_status(1)
+			;
+				io__print("Test passed\n")
+			)
+		; { RemoveResult = io__error(RemoveError) },
+			io__print("Remove failed: "),
+			{ io__error_message(RemoveError, RemoveErrorMsg) },
+			io__print(RemoveErrorMsg),
+			io__nl,
+			io__set_exit_status(1)
+		),
+		io__remove_file(Name, RemoveAgainResult),
+		( { RemoveAgainResult = io__ok },
+			io__print("Second remove didn't report failure\n"),
+			io__set_exit_status(1)
+		; { RemoveAgainResult = io__error(RemoveAgainError) },
+			io__print("Second remove failed, as expected: "),
+			{ io__error_message(RemoveAgainError,
+				RemoveAgainErrorMsg) },
+			io__print(RemoveAgainErrorMsg),
+			io__nl
+		)
+	; { TellResult = io__error(TellError) },
+		io__print("Tell failed: "),
+		{ io__error_message(TellError, TellErrorMsg) },
+		io__print(TellErrorMsg),
+		io__nl,
+		io__set_exit_status(1)
+	).
+

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list