[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH] strftime()



* itoa durch snprintf ersetzt
* Dank vim nun alles tyndur-Konform

Signed-off-by: Alexander Hartmut Kluth <alexanderkluth@xxxxxx>
---
 src/modules/lib/stdlibc/time.c |  119 ++++++++++++++++++++--------------------
 1 files changed, 60 insertions(+), 59 deletions(-)

diff --git a/src/modules/lib/stdlibc/time.c b/src/modules/lib/stdlibc/time.c
index ca1d8f8..43a7a06 100644
--- a/src/modules/lib/stdlibc/time.c
+++ b/src/modules/lib/stdlibc/time.c
@@ -75,14 +75,14 @@ static const char *__time[] = {
 time_t time(time_t* t)
 {
     time_t result = 0;
-    
+
     FILE* time_file = fopen("cmos:/unix_time", "r");
     if (time_file == NULL) {
         printf("time():Konnte 'cmos:/unix_time' nicht oeffnen. Ist das ");
         printf("cmos-Modul geladen?\n");
         return 0;
     }
-    
+
     fread(&result, sizeof(time_t), 1, time_file);
     fclose(time_file);
 
@@ -163,7 +163,8 @@ time_t mktime(struct tm* time_ptr)
  *
  * @return 0 bei Misserfolg, ansonsten Anzahl erzeugter Zeichen
  **/
-size_t strftime(char *str, size_t maxs, const char *datestr, const struct tm *tm)
+size_t strftime(char *str, size_t maxs, const char *datestr,
+const struct tm *tm)
 {
     char i, c;
     size_t size = 0, n;
@@ -181,160 +182,160 @@ size_t strftime(char *str, size_t maxs, const char *datestr, const struct tm *tm
             if (++size >= maxs) {
                 return 0;
             }
-       
+
             *str++ = c;
             continue;
         }
 
         switch (*datestr++) {
-            case '%':	
+            case '%':
                 nstr = "%";
                 break;
-			
+
             case 'a':	// Abgekürzter Wochentagsname
                 nstr = (char *)__time[aSun + tm->tm_wday];
                 break;
-			
+
             case 'A':	// Wochentagsname
                 nstr = (char *)__time[Sun + tm->tm_wday];
                 break;
-			
+
 			case 'b':	// Abgekürzter Montatsname
 		    case 'h':
                 nstr = (char *)__time[aJan + tm->tm_mon];
                 break;
-			
-			
+
+
             case 'B':	// Monatsname
                 nstr = (char *)__time[Jan + tm->tm_mon];
-                
+
                 if ((n = strftime(str, maxs-size, nstr, tm)) == 0) {
                     return 0;
                 }
-			
+
                 str += n;
                 size += n;
                 break;
-			
+
             case 'd':	// Tagesnummer
-                //p = itoa(tm->tm_mday, nstr, 2);
+                snprintf(nstr, 2, "%i", tm->tm_mday);
                 break;
-			
+
             case 'D':
                 nstr = "%m/%d/%y";
                 if ((n = strftime(str, maxs-size, nstr, tm)) == 0) {
                     return 0;
                 }
-			
+
                 str += n;
                 size += n;
                 break;
-			
+
             case 'e':
-                itoa(tm->tm_mday, nstr, 2);
+                snprintf(nstr, 2, "%i", tm->tm_mday);
                 if (tm->tm_mday < 10) {
                     nstr[0] = ' ';
                 }
 
                 break;
-			
+
             case 'H':	// 24-Stunden
-                itoa(tm->tm_hour, nstr, 2);
-                 break;
-			
+                snprintf(nstr, 2, "%i", tm->tm_hour);
+                break;
+
             case 'I':	// 12-Stunden
                 if ((i = tm->tm_hour % 12) == 0)
                 i = 12;
-                itoa(i, nstr, 2);
+                snprintf(nstr, 2, "%i", i);
                 break;
-			
+
             case 'j':	// Julianisches Datum
-                itoa(tm->tm_yday + 1, nstr, 3);
-            break;
-			
+                snprintf(nstr, 3, "%i", tm->tm_yday + 1);
+                break;
+
             case 'm':	// Monats-Nummer
-                itoa(tm->tm_mon + 1, nstr, 2);
+                snprintf(nstr, 2, "%i", tm->tm_mmon + 2);
                 break;
-			
+
             case 'M':	// Minute
-                itoa(tm->tm_min, nstr, 2);
+                snprintf(nstr, 2, "%i", tm->tm_min);
                 break;
-			
-            case 'n':	// Newline 
+
+            case 'n':	// Newline
                 nstr = "\n";
                 break;
-			
-            case 'p':	// AM oder PM 
+
+            case 'p':	// AM oder PM
                 if (tm->tm_hour >= 12)
                     nstr = (char *)__time[PM];
                 else
                     nstr = (char *)__time[AM];
                 break;
-			
+
             case 'r':
                 if (tm->tm_hour >= 12)
                     nstr = "%I:%M:%S PM";
                 else
                     nstr = "%I:%M:%S AM";
-				
+
                 if ((n = strftime(str, maxs-size, nstr, tm)) == 0) {
                     return 0;
                 }
-			
+
                 str += n;
                 size += n;
                 break;
-			
+
             case 'R':
                 nstr = "%H:%M";
                 if ((n = strftime(str, maxs-size, nstr, tm)) == 0) {
                     return 0;
                 }
-			
+
                 str += n;
                 size += n;
                 break;
-			
-            case 'S':	// Sekunden 
+
+            case 'S':	// Sekunden
                 //p = itoa(tm->tm_sec, nstr, 2);
                 break;
-			
+
             case 't':	// Tabulator
                 nstr = "\t";
                 break;
-			
+
             case 'T':
                 nstr = "%H:%M:%S";
                 if ((n = strftime(str, maxs-size, nstr, tm)) == 0) {
                     return 0;
                 }
-			
+
                 str += n;
                 size += n;
                 break;
-			
+
             case 'U':	// Tagesnummer des Jahres, bei Sonntag als 1. Tag
-                itoa((tm->tm_yday - tm->tm_wday + 7)/7, nstr, 2);
+                snprintf(nstr, 2, "%i", (tm->tm_yday - tm->tm_wday + 7)/7);
                 break;
-			
+
             case 'w':	// Wochentagsnummer
-                itoa(tm->tm_wday, nstr, 1);
+                snprintf(nstr, 2, "%i", tm->tm_wday);
                 break;
-			
+
             case 'W':	// Tagesnummer des Jahres, bei Montag als 1. Tag
                 if ((i = 8 - tm->tm_wday) == 8) {
                     i = 1;
                 }
-                itoa((tm->tm_yday + i)/7, nstr, 2);
+                snprintf(nstr, 2, "%i", (tm->tm_yday + i)/7);
                 break;
-			
-			
+
+
             case 'y':	// Jahr in Form von "xx"
-                itoa(tm->tm_year, nstr, 2);
+                snprintf(nstr, 2, "%i", tm->tm_year);
                 break;
-			
+
             case 'Y':	// Jahr in Form von "xxxx"
-                itoa(1900 + tm->tm_year, nstr, 4);
+                snprintf(nstr, 4, "%i", 1900 + tm->tm_year);
                 break;
 
             default:
@@ -344,17 +345,17 @@ size_t strftime(char *str, size_t maxs, const char *datestr, const struct tm *tm
 
 			continue;
         }
-		
+
         n = strlen(nstr);
-        
+
         if ((size += n) >= maxs) {
             return 0;
 		}
-        
+
         strcpy(str, nstr);
         str += n;
     }
-    
+
     *str = '\0';
     return size;
 }
-- 
1.6.0.4