mirror of
https://git.savannah.gnu.org/git/grub.git
synced 2026-10-21 06:49:35 +00:00
* grub-core/osdep/unix/platform.c (get_ofpathname): Trim ending newline.
Don't rely on PATH_MAX.
This commit is contained in:
1 parent
c98dd165b0
commit
61e1b9a49d
2 files changed
+27
-6
No files matched your search
@@ -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>
|
2013-11-25 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* grub-core/genmoddep.awk: Use more portable && rather than and.
|
* grub-core/genmoddep.awk: Use more portable && rather than and.
|
||||||
|
|||||||
@@ -31,11 +31,11 @@
|
|||||||
static char *
|
static char *
|
||||||
get_ofpathname (const char *dev)
|
get_ofpathname (const char *dev)
|
||||||
{
|
{
|
||||||
char *ret = xmalloc (2 * PATH_MAX);
|
size_t alloced = 4096;
|
||||||
char *end = ret + 2 * PATH_MAX - 1;
|
char *ret = xmalloc (alloced);
|
||||||
|
size_t offset = 0;
|
||||||
int fd;
|
int fd;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
char *ptr = ret;
|
|
||||||
|
|
||||||
pid = grub_util_exec_pipe ((const char * []){ "ofpathname", dev, NULL }, &fd);
|
pid = grub_util_exec_pipe ((const char * []){ "ofpathname", dev, NULL }, &fd);
|
||||||
if (!pid)
|
if (!pid)
|
||||||
@@ -45,12 +45,28 @@ get_ofpathname (const char *dev)
|
|||||||
if (!fp)
|
if (!fp)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
while (!feof (fp) && ptr < end)
|
while (!feof (fp))
|
||||||
{
|
{
|
||||||
size_t r;
|
size_t r;
|
||||||
r = fread (ptr, 1, end - ptr, fp);
|
if (alloced == offset)
|
||||||
ptr += r;
|
{
|
||||||
|
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);
|
fclose (fp);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user