[gnome-applets] Bug 603997: Don't unconditionally use PATH_MAX
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-applets] Bug 603997: Don't unconditionally use PATH_MAX
- Date: Thu, 28 Aug 2014 12:18:47 +0000 (UTC)
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]