aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremias Stotter <jeremias@stotter.eu>2022-04-20 21:09:25 +0200
committerJeremias Stotter <jeremias@stotter.eu>2022-04-20 23:37:59 +0200
commit463fd7d47d56e6f9f4a0e08ac641c862b800a5b5 (patch)
tree02b7903d09bcf7764f4e9fe7c228670766323cfe
parentdd0640bf637a74ebfeb4773b82ef1a2bdaa3ba59 (diff)
downloadJBlog-463fd7d47d56e6f9f4a0e08ac641c862b800a5b5.tar.gz
JBlog-463fd7d47d56e6f9f4a0e08ac641c862b800a5b5.tar.bz2
JBlog-463fd7d47d56e6f9f4a0e08ac641c862b800a5b5.zip
Changed a few things to compile on more systems / compilers
Removed clock because it might cause problems If CLOCKS_PER_SEC is 0 we get a division by 0 error. There is no need for tracking the time anyway. Added empty statements to switch-case where necessary Read pattern in without mmap Update makefile to use default compiler And some other minor things
-rw-r--r--jblog.c11
-rw-r--r--makefile1
-rw-r--r--md.c13
3 files changed, 10 insertions, 15 deletions
diff --git a/jblog.c b/jblog.c
index 5115a82..847c42c 100644
--- a/jblog.c
+++ b/jblog.c
@@ -27,7 +27,6 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
-#include <sys/mman.h>
#include <signal.h>
#include <string.h>
#include <stdbool.h>
@@ -395,7 +394,8 @@ int main(int argc, char* argv[]) {
return -1;
}
pid_t daemon_pid = getpid();
- if(dprintf(pidfile, "%d\n", daemon_pid) < 1) {
+ char pid_str[24] = ""; // This should always be enough, even with 64 bit PIDs
+ if(write(pidfile, pid_str, sprintf(pid_str, "%d\n", daemon_pid) + 1) < 1) {
jb_log(LL_ERR, true, "writing pidfile");
(void)!write(parentpipe[1], &errorparent_sig, 1);
return -1;
@@ -456,9 +456,10 @@ int main(int argc, char* argv[]) {
(void)!write(parentpipe[1], &errorparent_sig, 1);
return -1;
}
- char* pattern = mmap(NULL, pattern_stat.st_size, PROT_WRITE, MAP_PRIVATE, patternfd, 0);
+ char* pattern = calloc(pattern_stat.st_size + 1, 1);
+ read(patternfd, pattern, pattern_stat.st_size);
close(patternfd);
- if(strnlen(pattern, MAX_REPLY + 1) > MAX_REPLY) {
+ if(strlen(pattern) > MAX_REPLY) {
jb_log(LL_ERR, false, "pattern to big");
if(daemon)
(void)!write(parentpipe[1], &errorparent_sig, 1);
@@ -514,7 +515,7 @@ int main(int argc, char* argv[]) {
struct sockaddr_un socket_address;
socket_address.sun_family = AF_LOCAL;
- memcpy(&(socket_address.sun_path), un_path, UN_MAX_LEN);
+ strncpy((socket_address.sun_path), un_path, UN_MAX_LEN);
socklen_t un_socklen = sizeof(struct sockaddr_un);
diff --git a/makefile b/makefile
index 4ca92ee..f227313 100644
--- a/makefile
+++ b/makefile
@@ -1,4 +1,3 @@
-CC=gcc
CFLAGS=-O0 -g -std=c99 -Wall
BINDIR=/usr/bin
INITDIR=/etc/init.d
diff --git a/md.c b/md.c
index f194269..7b30059 100644
--- a/md.c
+++ b/md.c
@@ -23,9 +23,6 @@
#include <stdbool.h>
#include <limits.h>
-
-#include <time.h>
-
#include "jblog.h"
//#define LINE_MAX 4096
@@ -155,7 +152,7 @@ char* tree_to_html(struct tree_element* root) {
inner_html = realloc_append(inner_html, child->value);
break;
default:
- char* child_html = tree_to_html(child);
+ ; char* child_html = tree_to_html(child);
inner_html = realloc_append(inner_html, child_html);
free(child_html);
break;
@@ -407,7 +404,6 @@ void str_chr_hit(struct tree_element* root, struct tree_element** active_element
int parse_markdown(char* input, char* buffer, size_t buffer_size) {
utf8_length = 0;
unicode_char = 0;
- clock_t before = clock();
memset(buffer, 0, buffer_size);
bool escaped = false;
bool newline = false;
@@ -676,7 +672,7 @@ int parse_markdown(char* input, char* buffer, size_t buffer_size) {
}
break;
case('['):
- char* link_text = NULL;
+ ; char* link_text = NULL;
char* link_loc = NULL;
size_t link_len = 0;
char* new_position = get_link_components(cur_char, &link_text, &link_loc, &link_len);
@@ -700,7 +696,7 @@ int parse_markdown(char* input, char* buffer, size_t buffer_size) {
} else
goto default2;
case('!'):
- char* alt_text = NULL;
+ ; char* alt_text = NULL;
char* img_loc = NULL;
size_t img_len = 0;
new_position = get_link_components(cur_char + 1, &alt_text, &img_loc, &img_len);
@@ -754,7 +750,7 @@ int parse_markdown(char* input, char* buffer, size_t buffer_size) {
} else
goto default2;
case('<'):
- char* closing_gt = cur_char;
+ ; char* closing_gt = cur_char;
while(*closing_gt != 0 && *closing_gt != '\n') {
if(*closing_gt == '>') break;
closing_gt++;
@@ -858,7 +854,6 @@ int parse_markdown(char* input, char* buffer, size_t buffer_size) {
strncpy(buffer, html, buffer_size - 1);
}
free(html);
- printf("Time to process in ns: %ld\n", (clock() - before) / (CLOCKS_PER_SEC / 1000000));
depth--;
return 0;
}
Jeremias Stotters git repositories generated by CGIT