move open() outside the loop - hbb - hyperbitblock
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit ca8b59231bb5266e3dedcfd633b6379b04b64638
DIR parent c01752d0dd02e8071d8cf8f6ce346b1f8fc66ec2
HTML Author: kroovy <me@kroovy.de>
Date: Tue, 22 Apr 2025 21:08:14 +0200
move open() outside the loop
Diffstat:
M hyperbitblock.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
---
DIR diff --git a/hyperbitblock.c b/hyperbitblock.c
@@ -1,5 +1,6 @@
#define _POSIX_SOURCE
#include <signal.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
@@ -53,8 +54,9 @@ int main(void) {
char c;
char line[64];
+ fd = open("mynamedpipe", O_RDWR);
+
nextline:
- fd = open("mynamedpipe", O_RDONLY);
for (i=0; (res = read(fd, &c, 1)) > 0; i++) { //consider readline/getline
line[i] = c;
if (c == '\n') {
@@ -65,9 +67,9 @@ nextline:
}
str_to_ip(line, v4);
i32 = (v4[0] << 24) | (v4[1] << 16) | (v4[2] << 8) | v4[3];
- printf("My IP is: %u.%u.%u.%u\n",v4[0],v4[1],v4[2],v4[3]);
- printf("That calculates to: %u\n\n",i32);
- close(fd);
- sleep(1); //fix with fcntl
+ printf("My IP is: %u.%u.%u.%u | ",v4[0],v4[1],v4[2],v4[3]);
+ printf("That calculates to: %u\n",i32);
goto nextline;
+
+ close(fd);
}