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

[tyndur-devel] [PATCH] libc: Vorzeichen beachten in atol



! atol beachted jetzt auch das gespeicherte Vorzeichen

Signed-off-by: Andreas Freimuth <m.nemo@xxxxxxx>
---
 src/lib/string.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/lib/string.c b/src/lib/string.c
index d6d662f..939bcb9 100644
--- a/src/lib/string.c
+++ b/src/lib/string.c
@@ -165,12 +165,12 @@ long atol(const char *str)
     if (!*str) {
         return 0;
     }
-    int positive = 1;
+    bool positive = true;
     long result = 0;
     int length = 0;
     //Vorzeichen
     if (*str == '-') {
-        positive = 0;
+        positive = false;
         str++;
     } else if (*str == '+') {
         str++;
@@ -184,17 +184,20 @@ long atol(const char *str)
             //Ziffer hinzuf�            result = result * 10 + c - '0';
         } else {
-            if (!length) {
-                return 0;
-            }
-            return result;
-        } 
+            break;
+        }
         str++;
     }
-            
+
     if (!length) {
         return 0;
     }
+
+    // Vorzeichen anwenden
+    if (!positiv) {
+        result = -result;
+    }
+
     return result;
 }
 
-- 
1.7.4.2