[Haiku-commits] r30941 - haiku/trunk/src/kits/network/dns/irs

axeld at BerliOS axeld at mail.berlios.de
Mon Jun 1 22:47:41 CEST 2009


Author: axeld
Date: 2009-06-01 22:47:41 +0200 (Mon, 01 Jun 2009)
New Revision: 30941
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=30941&view=rev

Modified:
   haiku/trunk/src/kits/network/dns/irs/lcl_sv.cpp
Log:
* Reintroduced the find_own_image() function, as I think this is the cleaner
  approach.
* Made get_next_line() static as it should have been in the first place.


Modified: haiku/trunk/src/kits/network/dns/irs/lcl_sv.cpp
===================================================================
--- haiku/trunk/src/kits/network/dns/irs/lcl_sv.cpp	2009-06-01 20:44:59 UTC (rev 30940)
+++ haiku/trunk/src/kits/network/dns/irs/lcl_sv.cpp	2009-06-01 20:47:41 UTC (rev 30941)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006, Haiku, Inc. All Rights Reserved.
+ * Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  */
 
@@ -85,13 +85,32 @@
 
 struct service_private {
 	FILE*	file;
-	char	line[BUFSIZ+1];
+	char	line[BUFSIZ + 1];
 	struct servent servent;
 	char*	aliases[IRS_SV_MAXALIASES];
 };
 
 
-char *
+static status_t
+find_own_image(image_info* _info)
+{
+	int32 cookie = 0;
+	image_info info;
+	while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
+		if (((uint32)info.text <= (uint32)find_own_image
+			&& (uint32)info.text + (uint32)info.text_size
+					> (uint32)find_own_image)) {
+			// found us
+			*_info = info;
+			return B_OK;
+		}
+	}
+
+	return B_ENTRY_NOT_FOUND;
+}
+
+
+static char*
 get_next_line(struct service_private* service)
 {
 	if (service->file == NULL)
@@ -139,24 +158,12 @@
 	// opening the standard file has file has failed, use the attribute
 
 	// find our library image
-	addr_t addressInImage = (addr_t)&sv_rewind;
-	const char* path = NULL;
 	image_info info;
-	int32 cookie = 0;
-
-	while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
-		if (addressInImage >= (addr_t)info.text
-			&& addressInImage < (addr_t)info.text + info.text_size) {
-			path = info.name;
-			break;
-		}
-	}
-
-	if (path == NULL)
+	if (find_own_image(&info) != B_OK)
 		return;
 
 	// open the library
-	int libraryFD = open(path, O_RDONLY);
+	int libraryFD = open(info.name, O_RDONLY);
 	if (libraryFD < 0)
 		return;
 




More information about the Haiku-commits mailing list