Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 33000 invoked from network); 2 Sep 2009 16:59:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 Sep 2009 16:59:51 -0000 Received: (qmail 18443 invoked by uid 500); 2 Sep 2009 16:59:51 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 18358 invoked by uid 500); 2 Sep 2009 16:59:51 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 18349 invoked by uid 99); 2 Sep 2009 16:59:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Sep 2009 16:59:51 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Sep 2009 16:59:48 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7DA6323888D2; Wed, 2 Sep 2009 16:59:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r810609 - /commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c Date: Wed, 02 Sep 2009 16:59:27 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090902165927.7DA6323888D2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Wed Sep 2 16:59:27 2009 New Revision: 810609 URL: http://svn.apache.org/viewvc?rev=810609&view=rev Log: Save errno when returning NULL Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c?rev=810609&r1=810608&r2=810609&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c Wed Sep 2 16:59:27 2009 @@ -23,42 +23,52 @@ char *ACR_FileReadTxt(const char *name) { - FILE *f; + FILE *f; size_t rd = ACR_MIN_FREAD_LEN; - char *b; + char *rb; + int rc = 0; if (!(f = fopen(name, "r"))) return NULL; - if ((b = malloc(rd))) { - size_t nr = fread(b, 1, rd - 2, f); + if ((rb = malloc(rd))) { + size_t nr = fread(rb, 1, rd - 2, f); if (nr == (rd - 2)) { /* Try with larger buffer size */ char *nb = malloc(ACR_MAX_FREAD_LEN); if (nb) { - memcpy(nb, b, nr); - free(b); - b = nb; + memcpy(nb, rb, nr); + free(rb); + rb = nb; rd = ACR_MAX_FREAD_LEN - nr; - nr += fread(b + nr, 1, rd - 2, f); + nr += fread(rb + nr, 1, rd - 2, f); } - else + else { + rc = errno; nr = 0; + } } if (nr > 0) { int i; /* Remove all trailing zero and space characters */ - for (i = (int)(nr - 1); i >= 0 && (acr_iscntrl(b[i]) || - acr_isspace(b[i])); i--) + for (i = (int)(nr - 1); i >= 0 && (acr_iscntrl(rb[i]) || + acr_isspace(rb[i])); i--) ; - b[i + 1] = '\0'; - b[i + 2] = '\0'; + rb[i + 1] = '\0'; + rb[i + 2] = '\0'; } else { - free(b); + free(rb); fclose(f); + errno = rc; return NULL; } } + else { + rc = errno; + fclose(f); + errno = rc; + return NULL; + } fclose(f); - return b; + return rb; }