diff options
author | metamuffin <metamuffin@disroot.org> | 2024-10-09 10:13:59 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-10-09 10:13:59 +0200 |
commit | 7e89b781e7f1e8d7cedc20601642bec525200176 (patch) | |
tree | d5263e7cfe48b47e313ec6e99f1eaf3a10960778 | |
parent | 1109973fc1aae971439331c76eb46cbaf976690b (diff) | |
download | attocc-7e89b781e7f1e8d7cedc20601642bec525200176.tar attocc-7e89b781e7f1e8d7cedc20601642bec525200176.tar.bz2 attocc-7e89b781e7f1e8d7cedc20601642bec525200176.tar.zst |
fix strncmp
-rw-r--r-- | attocc.c | 16 | ||||
-rw-r--r-- | makefile | 2 |
2 files changed, 11 insertions, 7 deletions
@@ -16,6 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -26,6 +27,8 @@ #define DEBUG #endif +#define TRAP kill(getpid(), SIGTRAP); + const int NUM_KEYWORDS = 32; static char *KEYWORDS[] = { "auto", "break", "case", "char", "const", "continue", @@ -273,17 +276,19 @@ void *memcpy(void *dest, const void *src, unsigned long size) { // not to specification but this program only needs to check equality int strncmp(const char *a, const char *b, unsigned long len) { - while (len--) - if (*a++ != *b++) - return 1; + while (len--) { + if (*a != *b) + return *a - *b; + a++; + b++; + } return 0; } - unsigned long strlen(const char *s) { int len = 0; while (*s++) len++; - return len - 1; + return len; } char *strdup(const char *s) { int len = strlen(s); @@ -316,7 +321,6 @@ struct token *tokenize(char *source) { struct token *tokens = NULL; while (*p) { unsigned long remaining = end - p; - printf("%li\n", p - source); //* whitespace if (p[0] == ' ' || p[0] == '\t' || p[0] == '\n') { @@ -11,7 +11,7 @@ attocc: attocc.c cc -DDEBUG -O3 -o $@ $< attocc-debug: attocc.c - cc -DDEBUG -Wall -Wextra -Wpedantic -o $@ $< + cc -DDEBUG -Wall -Wextra -Wpedantic -Og -g -o $@ $< attocc-small: attocc.c cc -DDEBUG -Wl,--gc-sections -flto -ffunction-sections -fdata-sections -fPIC -s -Os -o $@ $< |