Added option to disable error message altogether, to save space footprint

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@330 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib-util/src/pjlib-util/errno.c b/pjlib-util/src/pjlib-util/errno.c
index b5e43e7..bce785a 100644
--- a/pjlib-util/src/pjlib-util/errno.c
+++ b/pjlib-util/src/pjlib-util/errno.c
@@ -25,6 +25,7 @@
  * MUST KEEP THIS ARRAY SORTED!!
  * Message must be limited to 64 chars!
  */
+#if defined(PJ_HAS_ERROR_STRING) && PJ_HAS_ERROR_STRING!=0
 static const struct 
 {
     int code;
@@ -47,7 +48,7 @@
     /* XML errors */
     { PJLIB_UTIL_EINXML,	    "Invalid XML message" },
 };
-
+#endif	/* PJ_HAS_ERROR_STRING */
 
 
 /*
@@ -58,6 +59,8 @@
 {
     pj_str_t errstr;
 
+#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
+
     if (statcode >= PJLIB_UTIL_ERRNO_START && 
 	statcode < PJLIB_UTIL_ERRNO_START + PJ_ERRNO_SPACE_SIZE)
     {
@@ -96,10 +99,13 @@
 	} 
     }
 
+#endif	/* PJ_HAS_ERROR_STRING */
+
+
     /* Error not found. */
     errstr.ptr = buf;
     errstr.slen = pj_ansi_snprintf(buf, bufsize, 
-				   "Unknown error %d",
+				   "Unknown pjlib-util error %d",
 				   statcode);
 
     return errstr;
diff --git a/pjlib/src/pj/errno.c b/pjlib/src/pj/errno.c
index 9843105..086bfcd 100644
--- a/pjlib/src/pj/errno.c
+++ b/pjlib/src/pj/errno.c
@@ -39,6 +39,7 @@
 } err_msg_hnd[PJLIB_MAX_ERR_MSG_HANDLER];
 
 /* PJLIB's own error codes/messages */
+#if defined(PJ_HAS_ERROR_STRING) && PJ_HAS_ERROR_STRING!=0
 static const struct 
 {
     int code;
@@ -62,6 +63,8 @@
     { PJ_EEXISTS,       "Object already exists" },
     { PJ_EEOF,		"End of file" },
 };
+#endif	/* PJ_HAS_ERROR_STRING */
+
 
 /*
  * pjlib_error()
@@ -70,6 +73,7 @@
  */
 static int pjlib_error(pj_status_t code, char *buf, pj_size_t size)
 {
+#if defined(PJ_HAS_ERROR_STRING) && PJ_HAS_ERROR_STRING!=0
     unsigned i;
 
     for (i=0; i<sizeof(err_str)/sizeof(err_str[0]); ++i) {
@@ -81,12 +85,9 @@
             return len;
         }
     }
+#endif
 
-    *buf++ = '?';
-    *buf++ = '?';
-    *buf++ = '?';
-    *buf++ = '\0';
-    return 3;
+    return pj_ansi_snprintf( buf, size, "Unknown pjlib error %d", code);
 }
 
 #define IN_RANGE(val,start,end)	    ((val)>=(start) && (val)<(end))
diff --git a/pjlib/src/pj/os_error_win32.c b/pjlib/src/pj/os_error_win32.c
index 8c6d56c..80a4eb2 100644
--- a/pjlib/src/pj/os_error_win32.c
+++ b/pjlib/src/pj/os_error_win32.c
@@ -33,6 +33,8 @@
 /*
  * From Apache's APR:
  */
+#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING!=0)
+
 static const struct {
     pj_os_err_type code;
     const char *msg;
@@ -89,6 +91,9 @@
     {0,                  NULL}
 };
 
+#endif	/* PJ_HAS_ERROR_STRING */
+
+
 
 PJ_DEF(pj_status_t) pj_get_os_error(void)
 {
@@ -155,6 +160,8 @@
 #endif
 
     if (!len) {
+
+#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING!=0)
 	int i;
         for (i = 0; gaErrorList[i].msg; ++i) {
             if (gaErrorList[i].code == os_errcode) {
@@ -167,6 +174,7 @@
                 break;
             }
         }
+#endif	/* PJ_HAS_ERROR_STRING */
 
     } else {
 	/* Remove trailing newlines. */
diff --git a/pjmedia/src/pjmedia/errno.c b/pjmedia/src/pjmedia/errno.c
index e6eeccd..5a63e07 100644
--- a/pjmedia/src/pjmedia/errno.c
+++ b/pjmedia/src/pjmedia/errno.c
@@ -26,6 +26,9 @@
  * MUST KEEP THIS ARRAY SORTED!!
  * Message must be limited to 64 chars!
  */
+
+#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
+
 static const struct 
 {
     int code;
@@ -121,6 +124,8 @@
     { PJMEDIA_EWAVETOOSHORT,	    "WAVE file too short" },
 };
 
+#endif	/* PJ_HAS_ERROR_STRING */
+
 
 
 /*
@@ -131,6 +136,8 @@
 {
     pj_str_t errstr;
 
+#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
+
     /* See if the error comes from PortAudio. */
     if (statcode >= PJMEDIA_ERRNO_FROM_PORTAUDIO(paNotInitialized) &&
 	statcode <  PJMEDIA_ERRNO_FROM_PORTAUDIO(paNotInitialized + 10000))
@@ -184,10 +191,12 @@
 	} 
     }
 
+#endif	/* PJ_HAS_ERROR_STRING */
+
     /* Error not found. */
     errstr.ptr = buf;
     errstr.slen = pj_ansi_snprintf(buf, bufsize, 
-				   "Unknown error %d",
+				   "Unknown pjmedia error %d",
 				   statcode);
 
     return errstr;
diff --git a/pjsip/src/pjsip-simple/errno.c b/pjsip/src/pjsip-simple/errno.c
index a2e588d..3f5c2e6 100644
--- a/pjsip/src/pjsip-simple/errno.c
+++ b/pjsip/src/pjsip-simple/errno.c
@@ -23,6 +23,9 @@
  * MUST KEEP THIS ARRAY SORTED!!
  * Message must be limited to 64 chars!
  */
+
+#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
+
 static const struct 
 {
     int code;
@@ -46,6 +49,8 @@
 };
 
 
+#endif	/* PJ_HAS_ERROR_STRING */
+
 
 /*
  * pjsipsimple_strerror()
@@ -55,6 +60,8 @@
 {
     pj_str_t errstr;
 
+#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
+
     if (statcode >= PJSIP_SIMPLE_ERRNO_START && 
 	statcode < PJSIP_SIMPLE_ERRNO_START + PJ_ERRNO_SPACE_SIZE)
     {
@@ -93,10 +100,13 @@
 	} 
     }
 
+#endif	/* PJ_HAS_ERROR_STRING */
+
+
     /* Error not found. */
     errstr.ptr = buf;
     errstr.slen = pj_ansi_snprintf(buf, bufsize, 
-				   "Unknown error %d",
+				   "Unknown pjsip-simple error %d",
  				   statcode);
 
     return errstr;
diff --git a/pjsip/src/pjsip/sip_errno.c b/pjsip/src/pjsip/sip_errno.c
index ab4d72d..6bac6f9 100644
--- a/pjsip/src/pjsip/sip_errno.c
+++ b/pjsip/src/pjsip/sip_errno.c
@@ -24,6 +24,9 @@
 /* PJSIP's own error codes/messages 
  * MUST KEEP THIS ARRAY SORTED!!
  */
+
+#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
+
 static const struct 
 {
     int code;
@@ -91,6 +94,9 @@
 };
 
 
+#endif	/* PJ_HAS_ERROR_STRING */
+
+
 /*
  * pjsip_strerror()
  */
@@ -99,6 +105,8 @@
 {
     pj_str_t errstr;
 
+#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
+
     if (statcode >= PJSIP_ERRNO_START && statcode < PJSIP_ERRNO_START+800) 
     {
 	/* Status code. */
@@ -144,20 +152,18 @@
 	    pj_strncpy_with_null(&errstr, &msg, bufsize);
 	    return errstr;
 
-	} else {
-	    /* Error not found. */
-	    errstr.ptr = buf;
-	    errstr.slen = pj_ansi_snprintf(buf, bufsize, 
-					   "Unknown error %d",
-					   statcode);
+	} 
+    }
 
-	    return errstr;
-	}
-    }
-    else {
-	/* Not our code. Give it to PJLIB. */
-	return pj_strerror(statcode, buf, bufsize);
-    }
+#endif	/* PJ_HAS_ERROR_STRING */
+
+    /* Error not found. */
+    errstr.ptr = buf;
+    errstr.slen = pj_ansi_snprintf(buf, bufsize, 
+				   "Unknown pjsip error %d",
+				   statcode);
+
+    return errstr;
 
 }