git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/libc/atol.c

      1 #include <stdint.h>
      2 #include <stdbool.h>
      3 
      4 inline bool _isdigit(char c) {
      5     return ((uint8_t)((uint8_t)c - '0') < 10u) ? true : false;
      6 }
      7 
      8 long atol(const char *s) {
      9     bool sign = false;
     10     long n;
     11 
     12     const uint8_t * pc = (const uint8_t *)s;
     13 
     14     for(; ((*pc == ' ') || (*pc == '\t') || (*pc == '\n')); ++pc);
     15     
     16     switch(*pc) {
     17         case '-':
     18             sign = true;
     19             /* and fall through */
     20         case '+':
     21             ++pc;
     22             break;
     23     }
     24     
     25     for(n = 0; _isdigit(*pc); ++pc) n = 10 * n + (*pc - '0');
     26 
     27     return (sign == 0 ? n : -n);
     28 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.