From: Martin Stromberg Message-Id: <200302261504.QAA11492@lws256.lu.erisoft.se> Subject: Re: fchmod, revision 3 [PATCH] To: djgpp-workers AT delorie DOT com Date: Wed, 26 Feb 2003 16:04:25 +0100 (MET) In-Reply-To: from "Richard Dawe" at Feb 26, 2003 12:24:59 PM X-Mailer: ELM [version 2.5 PL3] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk Richard said: > *** /dev/null Wed Feb 26 12:22:27 2003 > --- tests/libc/posix/sys/stat/t-fchmod.c Thu Feb 20 14:17:52 2003 ... > + /* Re-open the file and change the permissions to read-only. > + * Try writing to the file before and after. */ > + fd = open(TEST_FILE, O_BINARY|O_RDWR); > + if (fd < 0) > + die(argv[0]); > + > + /* Try writing to the file. */ > + { > + char wibble[] = "wibble-read-write"; > + > + if (write(fd, wibble, strlen(wibble)) < 0) > + { > + printf("Unable to write to read-write file %s\n", TEST_FILE); > + perror(argv[0]); > + ok = 0; > + } > + } > + > + if (fchmod(fd, S_IRUSR) < 0) > + die(argv[0]); > + > + /* Check the permissions are read-only. */ > + if (!check_read_only(TEST_FILE)) > + ok = 0; > + > + /* Try writing to the file. */ > + { > + char wibble[] = "wibble-read-only"; > + > + if (write(fd, wibble, strlen(wibble)) < 0) > + { > + printf("Unable to write to read-only file %s\n", TEST_FILE); > + perror(argv[0]); > + ok = 0; > + } > + } > + > + close(fd); Shouldn't you check that that close() is successful? In case of buffering or whatever you might not see any error until you close the file. (There might be other close()s you need to check as well.) Right, MartinS