You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/02 18:59:27 UTC
svn commit: r810609 -
/commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c
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;
}