Xref: news-dnh.mv.net comp.os.msdos.djgpp:1753 Path: news-dnh.mv.net!mv!news.NH.Destek.Net!news2.net99.net!uunet!in2.uu.net!tank.news.pipex.net!pipex!sunsite.doc.ic.ac.uk!ulcc.ac.uk!pluto.ulcc.ac.uk!cziwkga From: cziwkga AT pluto DOT ulcc DOT ac DOT uk (Kevin Ashley) Newsgroups: comp.os.msdos.djgpp Subject: Re: mkdir and errno in V2 Date: 21 Aug 1995 10:47:12 GMT Organization: University of London Computer Centre Lines: 37 Distribution: world References: Reply-To: k DOT ashley AT ulcc DOT ac DOT uk Nntp-Posting-Host: pluto-e.ulcc.ac.uk To: elf AT netcom DOT com Dj-Gateway: from newsgroup comp.os.msdos.djgpp In article , Marc Singer writes: |>It appears that the mkdir call does not clear errno on success. |>...... |> |>Since it fails once, errno is ENOTDIR. The successful mkdir calls do |>not clear this value so errno on exit from my procedure is still |>ENOTDIR. I patch my procedure by clearing errno before each call to |>mkdir. mkdir is behaving correctly, although not in the way you and probably many other people would like. errno only has a defined value after a function call has failed and before you call any other function that might affect errno. Succesful function calls are NOT required to set errno to zero. The POSIX standard is quite explicit on this (and mentions two exceptions - isatty and ptrace - one of which isn't covered by POSIX anyway.) Most functions which can set errno have some way of indicating that they have returned with an error. errno is only valid if they have so returned. In the case if mkdir, if it returns -1, then errno is valid (i.e. contains a meaningful error code); if it returns 0, then it has succeeded and the value of errno is undefined. Your patch should be to test the return value of mkdir, then test errno if the return value is -1. A conforming version of mkdir COULD set errno to a non-zero value on success if it wished, and it's not too difficult to imagine how this might happen. Kevin Ashley. ---------------------------------------------------------------------------- Kevin Ashley K DOT Ashley AT Ulcc DOT ac DOT uk Systems Development Group Manager http://www.ulcc.ac.uk/staff/Kevin+Ashley University of London Computer Centre. ...ukc!ncdlab!K.Ashley This is not a signature