| 9 |
|
* Assume the passed pointer array is big enough to hold them all. |
| 10 |
|
*/ |
| 11 |
|
|
| 12 |
+ |
#include <ctype.h> |
| 13 |
+ |
|
| 14 |
|
#define NULL 0 |
| 15 |
|
|
| 16 |
< |
#define BUFSIZ 4096 /* file must be smaller than this */ |
| 16 |
> |
#define MAXFLEN 10240 /* file must be smaller than this */ |
| 17 |
|
|
| 16 |
– |
#include <ctype.h> |
| 17 |
– |
|
| 18 |
|
extern char *bmalloc(); |
| 19 |
|
|
| 20 |
|
|
| 29 |
|
register int n; |
| 30 |
|
register char *cp; |
| 31 |
|
/* allocate memory */ |
| 32 |
< |
if ((cp = buf = bmalloc(BUFSIZ)) == NULL) |
| 32 |
> |
if ((cp = buf = bmalloc(MAXFLEN)) == NULL) |
| 33 |
|
return(-1); |
| 34 |
|
if ((fd = open(fname, 0)) < 0) |
| 35 |
|
goto err; |
| 36 |
< |
n = read(fd, buf, BUFSIZ); |
| 36 |
> |
n = read(fd, buf, MAXFLEN); |
| 37 |
|
close(fd); |
| 38 |
|
if (n < 0) |
| 39 |
|
goto err; |
| 40 |
< |
if (n == BUFSIZ) /* file too big, take what we can */ |
| 40 |
> |
if (n == MAXFLEN) /* file too big, take what we can */ |
| 41 |
|
while (!isspace(buf[--n])) |
| 42 |
|
if (n <= 0) |
| 43 |
|
goto err; |
| 44 |
< |
bfree(buf+n+1, BUFSIZ-n-1); /* return unneeded memory */ |
| 44 |
> |
bfree(buf+n+1, MAXFLEN-n-1); /* return unneeded memory */ |
| 45 |
|
while (n > 0) { /* break buffer into words */ |
| 46 |
|
while (isspace(*cp)) { |
| 47 |
|
cp++; |
| 56 |
|
} |
| 57 |
|
*cp++ = '\0'; n--; |
| 58 |
|
} |
| 59 |
+ |
*wp = NULL; /* null terminator */ |
| 60 |
|
return(wp - words); |
| 61 |
|
err: |
| 62 |
< |
bfree(buf, BUFSIZ); |
| 62 |
> |
bfree(buf, MAXFLEN); |
| 63 |
|
return(-1); |
| 64 |
|
} |