diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2016-07-10 20:27:27 +0200 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2016-07-10 20:27:27 +0200 |
commit | 30f0686fb2d332cdc0ced15ac2c04094a127783a (patch) | |
tree | 33f3e088d2583e4c4708076a074eaab96e431ab1 /next.c | |
download | mblaze-30f0686fb2d332cdc0ced15ac2c04094a127783a.tar.gz mblaze-30f0686fb2d332cdc0ced15ac2c04094a127783a.tar.xz mblaze-30f0686fb2d332cdc0ced15ac2c04094a127783a.zip |
various code that may end up as a mail client
Diffstat (limited to 'next.c')
-rw-r--r-- | next.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/next.c b/next.c new file mode 100644 index 0000000..f82e437 --- /dev/null +++ b/next.c @@ -0,0 +1,44 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <unistd.h> +#include <sys/mman.h> +#include <stdlib.h> +#include <string.h> +#include <stdio.h> + +int +main(int argc, char *argv[]) +{ + int fd; + struct stat st; + + fd = open("map", O_RDONLY); + if (!fd) + exit(101); + + fstat(fd, &st); + char *map = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (!map) + exit(102); + + char *s = strstr(map, argv[1]); + if (!argv[1][0] || !s) { + // default to first line + s = map; + } else { + while (*s && *s != '\n') + s++; + s++; + } + char *t = s; + while (*t && *t != '\n') + t++; + if (!*t) + exit(1); + t++; + write(1, s, t-s); + + return 0; +} |