Integrate contributed implementation into Mbed TLS

A reduced implementation of the snprintf function has been provided.
This commit integrates it with Mbed TLS by putting it in the platform.c
translation unit and making it configurable via the config file.
Additionally the code has been formated to fit Mbed TLS style
guidelines.
diff --git a/library/platform.c b/library/platform.c
index a295f9b..d177449 100644
--- a/library/platform.c
+++ b/library/platform.c
@@ -98,6 +98,111 @@
 }
 #endif
 
+#if defined(MBEDTLS_PLATFORM_TF_SNPRINTF)
+
+static void unsigned_dec_print( char **s, size_t n, size_t *chars_printed,
+                                unsigned int unum )
+{
+    /* Enough for a 32-bit unsigned decimal integer (4294967295). */
+    unsigned char num_buf[10];
+    int i = 0, rem;
+
+    do
+    {
+        rem = unum % 10;
+        num_buf[i++] = '0' + rem;
+    } while( unum /= 10 );
+
+    while( --i >= 0 )
+    {
+        if( *chars_printed < n )
+            *(*s)++ = num_buf[i];
+        (*chars_printed)++;
+    }
+}
+
+int tf_snprintf( char *s, size_t n, const char *fmt, ... )
+{
+    va_list args;
+    int num;
+    unsigned int unum;
+    size_t chars_printed = 0;
+
+    if( n == 1 )
+    {
+        /* Buffer is too small to actually write anything else. */
+        *s = '\0';
+        n = 0;
+    }
+    else if( n >= 2 )
+    {
+        /* Reserve space for the terminator character. */
+        n--;
+    }
+
+    va_start( args, fmt );
+    while( *fmt ) {
+
+        if( *fmt == '%' )
+        {
+            fmt++;
+            /* Check the format specifier. */
+            switch( *fmt )
+            {
+            case 'i':
+            case 'd':
+                num = va_arg( args, int );
+
+                if( num < 0 )
+                {
+                    if( chars_printed < n )
+                        *s++ = '-';
+                    chars_printed++;
+
+                    unum = (unsigned int)-num;
+                }
+                else
+                {
+                    unum = (unsigned int)num;
+                }
+
+                unsigned_dec_print( &s, n, &chars_printed, unum );
+                break;
+            case 'u':
+                unum = va_arg( args, unsigned int );
+                unsigned_dec_print( &s, n, &chars_printed, unum );
+                break;
+            default:
+                /* Return error on any other specifier. */
+                chars_printed = -1;
+                goto exit;
+            }
+            fmt++;
+            continue;
+        }
+
+        if( chars_printed < n )
+            *s++ = *fmt;
+        fmt++;
+        chars_printed++;
+    }
+
+exit:
+    va_end( args );
+
+    if( n > 0 )
+        *s = '\0';
+
+    return( chars_printed );
+}
+
+#if defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
+#undef MBEDTLS_PLATFORM_STD_SNPRINTF
+#endif
+#define MBEDTLS_PLATFORM_STD_SNPRINTF tf_snprintf;
+
+#endif /* MBEDTLS_PLATFORM_TF_SNPRINTF */
+
 #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
 #if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
 /*