From beada5329098bb50f7b0dca3e96b577b9e3de3eb Mon Sep 17 00:00:00 2001
From: Emilio Pozuelo Monfort <pochu27@gmail.com>
Date: Mon, 7 Dec 2009 17:18:35 +0100
Subject: [PATCH] Bug 603997: Don't unconditionally use PATH_MAX

Since PATH_MAX is not guaranteed to be defined, unconditionally
using it will cause a build failure on platforms that don't define
it. So stop using it and use dynamic allocation to achieve the same
result.
---
 multiload/linux-proc.c |   28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/multiload/linux-proc.c b/multiload/linux-proc.c
index e168722..5782eec 100644
--- a/multiload/linux-proc.c
+++ b/multiload/linux-proc.c
@@ -288,21 +288,25 @@ is_net_device_virtual(char *device)
      * /sys/class/net/name-of-dev/ .  This second method is more complex
      * but more reliable.
      */
-    char path[PATH_MAX];
+    gboolean ret = FALSE;
+    char *path = malloc (strlen (device) + strlen ("/sys/class/net//device") + 1);
 
     /* Check if /sys/class/net/name-of-dev/ exists (may be old linux kernel
      * or not linux at all). */
-    if (sprintf(path, "/sys/class/net/%s", device) < 0)
-        return FALSE;
-    if (access(path, F_OK) != 0)
-        return FALSE; /* unknown */
-
-    if (sprintf(path, "/sys/class/net/%s/device", device) < 0)
-        return FALSE;
-    if (access(path, F_OK) != 0)
-        return TRUE;
-
-    return FALSE;
+    do {
+        if (sprintf(path, "/sys/class/net/%s", device) < 0)
+            break;
+        if (access(path, F_OK) != 0)
+            break; /* unknown */
+
+        if (sprintf(path, "/sys/class/net/%s/device", device) < 0)
+            break;
+        if (access(path, F_OK) != 0)
+            ret = TRUE;
+    } while (0);
+
+    free (path);
+    return ret;
 }
 
 void
-- 
1.6.5.4

