From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from homiemail-a21.g.dreamhost.com (caiajhbdcbef.dreamhost.com [208.97.132.145]) by che.dreamhost.com (Postfix) with ESMTP id 83789FE98 for ; Tue, 22 Mar 2011 20:43:05 -0700 (PDT) Received: from homiemail-a21.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a21.g.dreamhost.com (Postfix) with ESMTP id 76BFE300072 for ; Tue, 22 Mar 2011 20:29:00 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=the-brannons.com; h=from:to :subject:date:message-id; q=dns; s=the-brannons.com; b=stLGY0SJB 5IIjrLyGfbGP5kA4r5vc6Li3XhQZUenmAA8BNiCx0VUJdntfPm4THHGEEgyUJq67 JoneYgq5TNou36N/L1CJORn2i/IrEXcjyZ4rDUPrifZQqVmhn/iqpcavJH5CwWhG yTRWZoBHuDmKRaRYhPkhFUi7DA+nP8SHjg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=the-brannons.com; h=from :to:subject:date:message-id; s=the-brannons.com; bh=QEU2q8Ywv858 V6SToNVsLWcBEEo=; b=TRwbU3YIFeq/G6FNv9qRQpUZ2urp0KCaYe1XWJ6C+nqT vsYK3zMVVcHYEPFhXgoC7fcVPQ3+lvSze3h4igo7kavFBXAlnOt6qjgRchg4todK W+p+McKZco0EO8Koac4DJeZPjfZvQvDuObhiLbGaMvlUOWoodK/gPEQ4B6/ZbG8= Received: from localhost (ip68-12-125-253.ok.ok.cox.net [68.12.125.253]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: chris@the-brannons.com) by homiemail-a21.g.dreamhost.com (Postfix) with ESMTPSA id 2FBA1300059 for ; Tue, 22 Mar 2011 20:29:00 -0700 (PDT) From: Christopher Brannon To: edbrowse-dev@lists.the-brannons.com Date: Wed, 23 Mar 2011 03:28:59 +0000 Message-Id: <1300850939-18162-1-git-send-email-chris@the-brannons.com> X-Mailer: git-send-email 1.7.3.4 Subject: [Edbrowse-dev] [PATCH] Use stdio when saving files. X-BeenThere: edbrowse-dev@lists.the-brannons.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Edbrowse Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Mar 2011 03:43:05 -0000 Tyler S tells me that writeFile is slow when writing to a file on a networked filesystem. Now, we write them using stdio, instead of Unix system calls. The buffering should improve performance. --- src/buffers.c | 33 +++++++++++++++++++++------------ 1 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/buffers.c b/src/buffers.c index 4a37d58..7710c2d 100644 --- a/src/buffers.c +++ b/src/buffers.c @@ -1327,7 +1327,10 @@ readFile(const char *filename, const char *post) static bool writeFile(const char *name, int mode) { - int i, fh; + int i; + FILE *fh; + char *modeString; + int modeString_l; if(memEqualCI(name, "file://", 7)) name += 7; @@ -1353,12 +1356,18 @@ writeFile(const char *name, int mode) } /* mode should be TRUNC or APPEND */ - mode |= O_WRONLY | O_CREAT; + modeString = initString(&modeString_l); + if(mode & O_APPEND) + stringAndChar(&modeString, &modeString_l, 'a'); + else + stringAndChar(&modeString, &modeString_l, 'w'); if(cw->binMode) - mode |= O_BINARY; + stringAndChar(&modeString, &modeString_l, 'b'); + + fh = fopen(name, modeString); + nzFree(modeString); - fh = open(name, mode, 0666); - if(fh < 0) { + if(fh == NULL) { setError(MSG_NoCreate2, name); return false; } @@ -1394,7 +1403,7 @@ writeFile(const char *name, int mode) free(p); alloc_p = true; p = (pst) tp; - if(write(fh, p, tlen) < tlen) + if(fwrite(p, 1, tlen, fh) < tlen) rc = false; goto endline; } @@ -1405,20 +1414,20 @@ writeFile(const char *name, int mode) free(p); alloc_p = true; p = (pst) tp; - if(write(fh, p, tlen) < tlen) + if(fwrite(p, 1, tlen, fh) < tlen) rc = false; goto endline; } } - if(write(fh, p, len) < len) + if(fwrite(p, 1, len, fh) < len) rc = false; goto endline; } /* must write this line with the suffix on the end */ --len; - if(write(fh, p, len) < len) { + if(fwrite(p, 1, len, fh) < len) { badwrite: rc = false; goto endline; @@ -1426,7 +1435,7 @@ writeFile(const char *name, int mode) fileSize += len; strcat(suf, "\n"); len = strlen(suf); - if(write(fh, suf, len) < len) + if(fwrite(suf, 1, len, fh) < len) goto badwrite; endline: @@ -1434,13 +1443,13 @@ writeFile(const char *name, int mode) free(p); if(!rc) { setError(MSG_NoWrite2, name); - close(fh); + fclose(fh); return false; } fileSize += len; } /* loop over lines */ - close(fh); + fclose(fh); /* This is not an undoable operation, nor does it change data. * In fact the data is "no longer modified" if we have written all of it. */ if(startRange == 1 && endRange == cw->dol) -- 1.7.3.4