* grub-core/osdep/unix/platform.c (get_ofpathname): Trim ending newline.

Don't rely on PATH_MAX.
This commit is contained in:
Vladimir Serbinenko 2013-11-25 07:34:49 +01:00
parent c98dd165b0
commit 61e1b9a49d
2 changed files with 27 additions and 6 deletions

View file

@ -1,3 +1,8 @@
2013-11-25 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/osdep/unix/platform.c (get_ofpathname): Trim ending newline.
Don't rely on PATH_MAX.
2013-11-25 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/genmoddep.awk: Use more portable && rather than and.

View file

@ -31,11 +31,11 @@
static char *
get_ofpathname (const char *dev)
{
char *ret = xmalloc (2 * PATH_MAX);
char *end = ret + 2 * PATH_MAX - 1;
size_t alloced = 4096;
char *ret = xmalloc (alloced);
size_t offset = 0;
int fd;
pid_t pid;
char *ptr = ret;
pid = grub_util_exec_pipe ((const char * []){ "ofpathname", dev, NULL }, &fd);
if (!pid)
@ -45,13 +45,29 @@ get_ofpathname (const char *dev)
if (!fp)
goto fail;
while (!feof (fp) && ptr < end)
while (!feof (fp))
{
size_t r;
r = fread (ptr, 1, end - ptr, fp);
ptr += r;
if (alloced == offset)
{
alloced *= 2;
ret = xrealloc (ret, alloced);
}
r = fread (ret + offset, 1, alloced - offset, fp);
offset += r;
}
if (offset > 0 && ret[offset - 1] == '\n')
offset--;
if (offset > 0 && ret[offset - 1] == '\r')
offset--;
if (alloced == offset)
{
alloced++;
ret = xrealloc (ret, alloced);
}
ret[offset] = '\0';
fclose (fp);
return ret;