From b01d0b08b9209f9f63c933d9c88a90b35d86be79 Mon Sep 17 00:00:00 2001 From: Gerardo Marx Date: Thu, 24 Sep 2026 09:08:05 -0600 Subject: [PATCH 1/2] error catcher tested --- main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.c b/main.c index c666ccb..6a685b7 100644 --- a/main.c +++ b/main.c @@ -6,6 +6,12 @@ int main(int argc, char *argv[]){ int fd; // export fd = open("/sys/class/gpio/chip0/export", O_WRONLY); + if(fd<0) + { + perror("Error opening the GPIO export path"); + return -1; + } + write(fd,"17",2); close(fd); // pin direction From 8e6d3c458e4a3765fa9cb087323163f01ff2cbee Mon Sep 17 00:00:00 2001 From: Gerardo Marx Date: Thu, 24 Sep 2026 09:16:40 -0600 Subject: [PATCH 2/2] error cathcer in all fds --- main.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 6a685b7..3ed705a 100644 --- a/main.c +++ b/main.c @@ -8,7 +8,7 @@ int main(int argc, char *argv[]){ fd = open("/sys/class/gpio/chip0/export", O_WRONLY); if(fd<0) { - perror("Error opening the GPIO export path"); + perror("Error opening the GPIO path"); return -1; } @@ -16,21 +16,41 @@ int main(int argc, char *argv[]){ close(fd); // pin direction fd = open("/sys/class/gpio/chip0/gpio17/direction", O_WRONLY); + if(fd<0) + { + perror("Error opening the GPIO path"); + return -1; + } write(fd,"out",3); close(fd); // pin value to 1 fd = open("/sys/class/gpio/chip0/gpio17/value", O_WRONLY); + if(fd<0) + { + perror("Error opening the GPIO path"); + return -1; + } write(fd,"1",1); close(fd); sleep(1); // pin valu to 0 fd = open("/sys/class/gpio/chip0/gpio17/value", O_WRONLY); + if(fd<0) + { + perror("Error opening the GPIO path"); + return -1; + } write(fd,"0",1); close(fd); sleep(1); // unexport fd = open("/sys/class/gpio/chip0/unexport", O_WRONLY); + if(fd<0) + { + perror("Error opening the GPIO path"); + return -1; + } write(fd,"17",2); close(fd);