version 1.23, 2003/08/05 18:13:43 |
version 1.24, 2003/08/05 18:20:33 |
|
|
} |
} |
if (i_size > SIZE_MAX) { |
if (i_size > SIZE_MAX) { |
say("block too large to mmap\n"); |
say("block too large to mmap\n"); |
return false; |
return false; |
} |
} |
if ((ifd = open(filename, O_RDONLY)) < 0) |
if ((ifd = open(filename, O_RDONLY)) < 0) |
pfatal("can't open file %s", filename); |
pfatal("can't open file %s", filename); |
|
|
/* test for NUL too, to maintain the behavior of the original code */ |
/* test for NUL too, to maintain the behavior of the original code */ |
for (i = 0; i < i_size && i_womp[i] != '\0'; i++) { |
for (i = 0; i < i_size && i_womp[i] != '\0'; i++) { |
if (i_womp[i] == '\n') |
if (i_womp[i] == '\n') |
iline++; |
iline++; |
} |
} |
if (i_size > 0 && i_womp[i_size - 1] != '\n') |
if (i_size > 0 && i_womp[i_size - 1] != '\n') |
iline++; |
iline++; |
|
|
|
|
i_ptr = (char **) malloc((iline + 2) * sizeof(char *)); |
i_ptr = (char **) malloc((iline + 2) * sizeof(char *)); |
|
|
if (i_ptr == NULL) { /* shucks, it was a near thing */ |
if (i_ptr == NULL) { /* shucks, it was a near thing */ |
munmap(i_womp, i_size); |
munmap(i_womp, i_size); |
i_womp = NULL; |
i_womp = NULL; |
return false; |
return false; |
} |
} |
|
|
/* now scan the buffer and build pointer array */ |
/* now scan the buffer and build pointer array */ |
iline = 1; |
iline = 1; |
|
|
i_womp = NULL; |
i_womp = NULL; |
return false; |
return false; |
} |
} |
|
|
memcpy(p, i_ptr[iline], sz); |
memcpy(p, i_ptr[iline], sz); |
p[sz] = '\n'; |
p[sz] = '\n'; |
i_ptr[iline] = p; |
i_ptr[iline] = p; |