aboutsummaryrefslogtreecommitdiff
blob: 1065c41e4cc7735f8a7a7a0201bf13a8c95473d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
From 12a6d7c88cfb32cd3f811146d1f9af614d90fec2 Mon Sep 17 00:00:00 2001
From: Richard Hughes <richard@hughsie.com>
Date: Mon, 3 Nov 2008 09:07:09 +0000
Subject: [PATCH 28/48] remove the forced removal of the trailing newline to fix OLPC probing

While doing some patches for OLPC, all the OFW firmware strings are not
terminated with \n\0 just with \0.

This means that we get results like OLP when we should be getting
OLPC.

data  = OLPC0
index = 01234

len = 4
data[len-1] = C

data  = IBMn0
index = 01234

len = 4
data[len-1] = \n

Now, the isspace check checks for \n, so we can remove the explicit \0
termination, and rely on the code three lines down. Removing the
explicit code allows non-newline terminated strings to be got with
hal_util_get_string_from_file().
---
 hald/util.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/hald/util.c b/hald/util.c
index 51f5d8a..44645a4 100644
--- a/hald/util.c
+++ b/hald/util.c
@@ -305,13 +305,14 @@ hal_util_get_string_from_file (const gchar *directory, const gchar *file)
 		//HAL_ERROR (("Cannot read from '%s'", path));
 		goto out;
 	}
-       
+
+	/* blank file, no data */
 	len = strlen (buf);
-	if (len>0)
-		buf[len-1] = '\0';
+	if (len == 0)
+		goto out;
 
-	/* Clear remaining whitespace */
-	for (i = len - 2; i >= 0; --i) {
+	/* clear remaining whitespace */
+	for (i = len - 1; i >= 0; --i) {
 		if (!g_ascii_isspace (buf[i]))
 			break;
 		buf[i] = '\0';
-- 
1.6.1.2