[gnome-applets] Bug 603997: Don't unconditionally use PATH_MAX



commit 877359047a4c3327d574955a72a102cc7320f6d3
Author: Emilio Pozuelo Monfort <pochu27 gmail com>
Date:   Mon Dec 7 17:18:35 2009 +0100

    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 3b38a9f..431dbea 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]