Return-Path: william@bourbon.usc.edu Delivery-Date: Wed Nov 19 08:18:02 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id mAJGI2vP031001 for ; Wed, 19 Nov 2008 08:18:02 -0800 Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1]) by bourbon.usc.edu (8.14.2/8.14.1) with ESMTP id mAJGF5gQ004680 for ; Wed, 19 Nov 2008 08:15:05 -0800 Message-Id: <200811191615.mAJGF5gQ004680@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: CS551 Final2 - disk quota Date: Wed, 19 Nov 2008 08:15:05 -0800 From: Bill Cheng Someone wrote: > Do we have to check disk space for saving files in permanent space? > If so, what system call should we use? You generally cannot find out how much disk space is available to you. So, you must do the following. When you write to the file, you must check return code. When you close the file, you must check return code. If something failed, you must delete the file and tell the user that there is no space (so that the user can create space by removing files). You don't need to change your code much to get this done. If your original code (without error checking) is: while (writing_to_file) { fwrite(N bytes to file); } fclose(...); All you need is to change it to the following: boolean something_wrong=false; while (writing_to_file) { if (fwrite(N bytes to file) != N) { something_wrong = true; } } if (fclose() == EOF) { something_wrong = true; } if (something_wrong) { print error message to user unlink(the_file_you_were_writing_to); } -- Bill Cheng // bill.cheng@usc.edu