Revision: 42147
          http://brlcad.svn.sourceforge.net/brlcad/?rev=42147&view=rev
Author:   d_rossberg
Date:     2011-01-12 16:07:41 +0000 (Wed, 12 Jan 2011)

Log Message:
-----------
introduced bu_strcmp() with a more graceful string comparison as strcmp() does
"" and NULL are considered as equal

Modified Paths:
--------------
    brlcad/trunk/include/bu.h
    brlcad/trunk/src/libbu/str.c

Modified: brlcad/trunk/include/bu.h
===================================================================
--- brlcad/trunk/include/bu.h   2011-01-12 15:58:03 UTC (rev 42146)
+++ brlcad/trunk/include/bu.h   2011-01-12 16:07:41 UTC (rev 42147)
@@ -2529,7 +2529,7 @@
 /**
  * Return array with filenames with suffix matching substr
  */
-BU_EXPORT BU_EXTERN(void bu_list_path, (char *path, char *substr, char 
**filearray)); 
+BU_EXPORT BU_EXTERN(void bu_list_path, (char *path, char *substr, char 
**filearray));
 
 
 /** @file brlcad_path.c
@@ -5066,6 +5066,18 @@
 BU_EXPORT BU_EXTERN(char *bu_strdupm, (const char *cp, const char *label));
 #define bu_strdup(s) bu_strdupm(s, BU_FLSTR)
 
+/**
+ * b u _ s t r c m p  / b u _ s t r c m p m
+ *
+ * Compares two strings more gracefully as standard library's strcmp().
+ * It accepts NULL as valid input values and considers "" and NULL as equal.
+ *
+ * bu_strcmp() is a macro that includes the current file name and line
+ * number that can be used when bu debugging is enabled.
+ */
+BU_EXPORT BU_EXTERN(int bu_strcmpm, (const char *string1, const char *string2, 
const char *label));
+#define bu_strcmp(s) bu_strcmpm(s, BU_FLSTR)
+
 /** @} */
 
 /** @addtogroup bu_log */

Modified: brlcad/trunk/src/libbu/str.c
===================================================================
--- brlcad/trunk/src/libbu/str.c        2011-01-12 15:58:03 UTC (rev 42146)
+++ brlcad/trunk/src/libbu/str.c        2011-01-12 16:07:41 UTC (rev 42147)
@@ -158,6 +158,31 @@
     return base;
 }
 
+
+int
+bu_strcmpm(const char *string1, const char *string2, const char *label)
+{
+    const char *s1 = "";
+    const char *s2 = "";
+
+    if ((!string1 || !string2) && label) {
+       bu_semaphore_acquire(BU_SEM_SYSCALL);
+       fprintf(stderr, "WARNING: [%s] string comparison with NULL\n", label);
+       bu_semaphore_release(BU_SEM_SYSCALL);
+    }
+
+    /* "" and NULL are considered as equal */
+
+    if (string1)
+       s1 = string1;
+
+    if (string2)
+       s2 = string2;
+
+    return strcmp(s1, s2);
+}
+
+
 /*
  * Local Variables:
  * mode: C


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to