Add safeguards to never use errno == 0 as setrunelocale() error return code

This commit is contained in:
Andrey A. Chernov 2002-08-09 08:22:29 +00:00
parent 4ecb22fb96
commit ec5ca2eba7
3 changed files with 5 additions and 7 deletions

View File

@ -78,7 +78,7 @@ _EUC_init(rl)
++v;
if ((ei = malloc(sizeof(_EucInfo))) == NULL)
return (ENOMEM);
return (errno == 0 ? ENOMEM : errno);
new__mb_cur_max = 0;
for (x = 0; x < 4; ++x) {

View File

@ -70,10 +70,8 @@ _Read_RuneMagi(fp)
return (NULL);
}
if ((data = malloc(sb.st_size)) == NULL) {
errno = ENOMEM;
if ((data = malloc(sb.st_size)) == NULL)
return (NULL);
}
errno = 0;
rewind(fp); /* Someone might have read the magic number once already */

View File

@ -106,7 +106,7 @@ setrunelocale(char *encoding)
return (ENAMETOOLONG);
_PathLocale = strdup(p);
if (_PathLocale == NULL)
return (ENOMEM);
return (errno == 0 ? ENOMEM : errno);
} else
_PathLocale = _PATH_LOCALE;
}
@ -117,10 +117,10 @@ setrunelocale(char *encoding)
(void) strcat(name, "/LC_CTYPE");
if ((fp = fopen(name, "r")) == NULL)
return (errno);
return (errno == 0 ? ENOENT : errno);
if ((rl = _Read_RuneMagi(fp)) == NULL) {
saverr = errno;
saverr = (errno == 0 ? EFTYPE : errno);
(void)fclose(fp);
return (saverr);
}