Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!aplcen!haven!adm!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.unix.internals Subject: Re: checking return values of close(2) Message-ID: <24382:Oct1822:37:1290@kramden.acf.nyu.edu> Date: 18 Oct 90 22:37:12 GMT References: <1990Oct18.121818.9956@athena.mit.edu> <19547:Oct1818:25:2690@kramden.acf.nyu.edu> <1990Oct18.194707.12313@decuac.dec.com> Organization: IR Lines: 36 In article <1990Oct18.194707.12313@decuac.dec.com> mjr@hussar.dco.dec.com (Marcus J. Ranum) writes: > Is anyone seriously considering an fwaste() > system call ? I can imagine the results of that ("gee, better make sure I > have a spare megabyte for this one in case I need space next week - this > disk is getting awfully tight because of all the software that uses fwaste() > to grab a spare 256K) At worst the application will ftruncate() before closing the file. fwaste()ing too much is just as dumb as write()ing too much. Periodically there are requests for functions to do the same thing. Most applications know how much disk they need, and it's a lot better to allocate the space beforehand than to wait for disaster to strike. What do you think the news package's ``spacefor'' does? fwaste() is also very useful for asynchronous I/O. > What's the big deal, anyhow ? So you check your close() calls > if it's important to you that your files close properly. And do what if it returns EDQUOT? It is simply wrong for write() to succeed if there's no space for the data. The application might erase what it wrote; how do you expect it to recover if it doesn't find out until later? Well? What excuse do you have for forcing applications to buffer all their data until close()? There's no efficiency loss in making write() return accurate errors. > I'm sure everyone > makes sure that fprintf() and printf() don't return EOF, too. But those are meant to use internal buffers, and if you want better error checking you can and should be using descriptors directly. There's no level to escape to below descriptors if they don't do the job. ---Dan