+eina_error_msg_modify to change the error string of a registered error; preserves...
authordiscomfitor <discomfitor>
Sun, 25 Jul 2010 06:25:06 +0000 (06:25 +0000)
committerdiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sun, 25 Jul 2010 06:25:06 +0000 (06:25 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@50484 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/include/eina_error.h
src/lib/eina_error.c

index 7c119d4..47ce2fd 100644 (file)
@@ -49,7 +49,7 @@ EAPI extern Eina_Error EINA_ERROR_OUT_OF_MEMORY;
 
 EAPI Eina_Error eina_error_msg_register(const char *msg) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
 EAPI Eina_Error eina_error_msg_static_register(const char *msg) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
-
+EAPI Eina_Bool  eina_error_msg_modify(Eina_Error error, const char *msg) EINA_ARG_NONNULL(1, 2);
 EAPI Eina_Error eina_error_get(void);
 EAPI void eina_error_set(Eina_Error err);
 EAPI const char * eina_error_msg_get(Eina_Error error) EINA_PURE;
index 219cbc0..3130816 100644 (file)
@@ -365,6 +365,46 @@ eina_error_msg_static_register(const char *msg)
 }
 
 /**
+ * @brief Change the message of an already registered message
+ *
+ * @param error The Eina_Error to change the message of
+ * @param msg The description of the error. This string will be
+ * duplicated only if the error was registered with @ref eina_error_msg_register
+ * otherwise it must remain intact for the duration
+ * @return EINA_TRUE if successful, EINA_FALSE on error
+ *
+ * This function modifies the message associated with @p error and changes
+ * it to @p msg.  If the error was previously registered by @ref eina_error_msg_static_register
+ * then the string will not be duplicated, otherwise the previous message
+ * will be freed and @p msg copied.
+ *
+ * @see eina_error_msg_register()
+ */
+EAPI Eina_Bool
+eina_error_msg_modify(Eina_Error error, const char *msg)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(msg, EINA_FALSE);
+   if (error < 1)
+     return EINA_FALSE;
+   if ((size_t)error > _eina_errors_count)
+     return EINA_FALSE;
+   if (_eina_errors[error - 1].string_allocated)
+     {
+        const char *tmp;
+
+        if (!(tmp = strdup(msg)))
+             return EINA_FALSE;
+
+        free((void*)_eina_errors[error - 1].string);
+        _eina_errors[error - 1].string = tmp;
+        return EINA_TRUE;
+     }
+
+   _eina_errors[error - 1].string = msg;
+   return EINA_TRUE;
+}
+
+/**
  * @brief Return the description of the given an error number.
  *
  * @param error The error number.