Mail Archives: djgpp-workers/2003/02/26/10:04:30
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
- Raw text -