Created
September 11, 2023 14:38
-
-
Save haesbaert/729360e3c004a976bc5bbf59c8198284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <err.h> | |
#include <fcntl.h> | |
#include <malloc.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <strings.h> | |
#include <unistd.h> | |
#include <sys/mman.h> | |
#include <sys/stat.h> | |
char * | |
load_file(const char *filename, char *buf, ssize_t nr) | |
{ | |
int fd; | |
ssize_t n; | |
if (nr <= 0) | |
errx(1, "bad nr"); | |
if ((fd = open(filename, O_RDONLY)) == -1) | |
err(1, "open"); | |
bzero(buf, nr); | |
n = read(fd, buf, nr - 1); | |
printf("nr=%zd n=%zd\n", nr, n); | |
if (n == -1) | |
err(1, "read"); | |
else if (n == 0) | |
errx(1, "read EOF"); | |
close(fd); | |
return (buf); | |
} | |
int | |
main(int argc, char *argv[]) | |
{ | |
char *filename, *start, *s, *send; | |
char buf[4096]; | |
if (argc != 2) | |
errx(1, "%s: filename", argv[0]); | |
filename = argv[1]; | |
start = load_file(filename, buf, sizeof(buf)); | |
s = strstr(start, "\n\n"); | |
if (s == NULL) | |
errx(1, "s1 not found"); | |
s = strstr(s, ";\toffset:"); | |
if (s == NULL) | |
errx(1, "s2 not found"); | |
s += strlen(";\toffset:"); | |
send = strchr(s, ';'); | |
printf("s[0]=%c s[1]=%c (end - start) = %zd\n", s[0], s[1], send - s); | |
return (0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment