Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Wed, 1 Dec 2004 00:48:41 -0800 From: Yitzchak Scott-Thoennes To: cygwin AT cygwin DOT com Subject: truncate() improperly returns EBADF Message-ID: <20041201084841.GA2356@efn.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Organization: bs"d X-IsSubscribed: yes When using truncate(), EBADF is sometimes improperly returned. susv3 doesn't list this as a possible errno value for this function. In particular, ENOENT should be returned when when path doesn't exist and EACCES when write permission is denied. truncate.c: #include #include #include #include int main(int argc, char **argv) { off_t size; char *endptr = argv[2]; if (argc != 3) { fprintf(stderr, "usage: truncate path size\n"); exit(1); } errno = 0; size = strtoull(argv[2], &endptr, 10); if (!endptr || endptr == argv[2] || *endptr || size < 0 || (size == 0 && errno)) { fprintf(stderr, "truncate: invalid size\n"); exit(1); } printf("truncating %s to %lld bytes\n", argv[1], size); if (truncate(argv[1], size)) { int saveerr = errno; perror("truncate"); fprintf(stderr, "errno was %d\n", saveerr); exit(1); } exit(0); } ====================================================================== $ rm foo $ ./truncate foo 0 truncating foo to 0 bytes truncate: Bad file descriptor errno was 9 $ touch foo $ chmod u-w foo $ ls -l foo -r--r--r-- 1 sthoenna None 0 Dec 1 00:06 foo $ ./truncate foo 0 truncating foo to 0 bytes truncate: Bad file descriptor errno was 9 -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/