From 3fe7a3ffa7720450f822de3602a21e56d55ca181 Mon Sep 17 00:00:00 2001 From: Calixte DENIZET Date: Thu, 26 Mar 2015 17:21:25 +0100 Subject: [PATCH] Bug 13721 fixed: Could not write in a file opened in r+ mode Change-Id: Ie89724f0d6e83019c504e561d425eb4a959e6d6b --- scilab/CHANGES_5.5.X | 2 ++ scilab/modules/fileio/sci_gateway/c/sci_mfprintf.c | 2 +- scilab/modules/fileio/src/c/mputl.c | 2 +- .../fileio/tests/nonreg_tests/bug_13721.dia.ref | 23 ++++++++++++++++++ .../fileio/tests/nonreg_tests/bug_13721.tst | 25 ++++++++++++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 scilab/modules/fileio/tests/nonreg_tests/bug_13721.dia.ref create mode 100644 scilab/modules/fileio/tests/nonreg_tests/bug_13721.tst diff --git a/scilab/CHANGES_5.5.X b/scilab/CHANGES_5.5.X index 7523540..7cce23e2 100644 --- a/scilab/CHANGES_5.5.X +++ b/scilab/CHANGES_5.5.X @@ -119,6 +119,8 @@ Scilab Bug Fixes * Bug #13712 fixed - Details added in strcat help page for strcat(strings, "", "r") case. +* Bug #13721 fixed - Writing in a file opened in r+ mode was not possible. + * Bug #13723 fixed - It was not possible to insert a single double in double[][]. * Bug #13725 fixed - Polyline was not correctly filled with big values. diff --git a/scilab/modules/fileio/sci_gateway/c/sci_mfprintf.c b/scilab/modules/fileio/sci_gateway/c/sci_mfprintf.c index f3095d8..2d17687 100644 --- a/scilab/modules/fileio/sci_gateway/c/sci_mfprintf.c +++ b/scilab/modules/fileio/sci_gateway/c/sci_mfprintf.c @@ -106,7 +106,7 @@ int sci_mfprintf(char *fname, unsigned long fname_len) /* checks file mode */ /* bug 3898 */ /* read only attrib 1xx*/ - if ( (fileMode >= 100) && (fileMode < 200) && !isSTD) + if ( (fileMode >= 100) && (fileMode < 200) && ((fileMode % 100) < 10) /* check that it is not r+ */ && !isSTD) { Scierror(999, _("%s: Wrong file mode: READ only.\n"), fname); return 0; diff --git a/scilab/modules/fileio/src/c/mputl.c b/scilab/modules/fileio/src/c/mputl.c index de9cb10..4044b0c 100644 --- a/scilab/modules/fileio/src/c/mputl.c +++ b/scilab/modules/fileio/src/c/mputl.c @@ -43,7 +43,7 @@ mputlError mputl(int fileDescriptor, char **pStrings, int sizeStrings) { int mode = GetFileModeOpenedInScilab(fileDescriptor); - if ( (mode >= 100) && (mode < 200) ) + if ( (mode >= 100) && (mode < 200) && ((mode % 100) < 10) /* not r+ */) { return MPUTL_NO_WRITE_RIGHT; } diff --git a/scilab/modules/fileio/tests/nonreg_tests/bug_13721.dia.ref b/scilab/modules/fileio/tests/nonreg_tests/bug_13721.dia.ref new file mode 100644 index 0000000..534c47c --- /dev/null +++ b/scilab/modules/fileio/tests/nonreg_tests/bug_13721.dia.ref @@ -0,0 +1,23 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2015 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 13721 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/13721 +// +// <-- Short Description --> +// +// Cannot write in a file opened in r+ mode +fd = mopen(TMPDIR + "/bug_13721.txt", "a"); +mfprintf(fd, "%s\n", "hello"); +mclose(fd); +fd = mopen(TMPDIR + "/bug_13721.txt", "r+"); +mfprintf(fd, "%s\n", "world"); +mclose(fd); diff --git a/scilab/modules/fileio/tests/nonreg_tests/bug_13721.tst b/scilab/modules/fileio/tests/nonreg_tests/bug_13721.tst new file mode 100644 index 0000000..316887d --- /dev/null +++ b/scilab/modules/fileio/tests/nonreg_tests/bug_13721.tst @@ -0,0 +1,25 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2015 - Scilab Enterprises - Calixte DENIZET +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= +// +// <-- CLI SHELL MODE --> +// +// <-- Non-regression test for bug 13721 --> +// +// <-- Bugzilla URL --> +// http://bugzilla.scilab.org/13721 +// +// <-- Short Description --> +// +// Could not write in a file opened in r+ mode + +fd = mopen(TMPDIR + "/bug_13721.txt", "a"); +mfprintf(fd, "%s\n", "hello"); +mclose(fd); +fd = mopen(TMPDIR + "/bug_13721.txt", "r+"); +mfprintf(fd, "%s\n", "world"); +mclose(fd); + -- 1.7.9.5