💾 Archived View for gemini.thededem.de › lc19 › src › include › util.h captured on 2024-08-18 at 18:17:54.
⬅️ Previous capture (2021-12-03)
-=-=-=-=-=-=-
/* Copyright 2020, 2021 Lukas Wedeking * * This file is part of LC19. * * LC19 is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * LC19 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LC19. If not, see <https://www.gnu.org/licenses/>. */ #ifndef GEMINI_SERVER_UTIL_H #define GEMINI_SERVER_UTIL_H #include "../include/conf.h" #include<stddef.h> /* * Take a UTF-8 encoded string and get the codepoint of the first character. * * s is the UTF-8 encoded string, max_length the maximum number of bytes that * can be read from s. The codepoint is stored in the arugment codepoint. * * The return value denotes the number of bytes of the UTF-8 character that was * read. */ size_t util_utf8_get_codepoint(const char *s, size_t max_length, unsigned char codepoint[3]); /* * Log a message to a FILE stream. * * msg is the string written to the log. It is automatically prepended with a * timestamp and suffixed with a newline. */ void log_msg(enum Loglevel level, const char *fmt, ...); /* * Copy a string from src to dest. * * The function copies at most max chars, including the terminating NUL byte. * The function returns the number of bytes copied, excluding the terminating * NUL byte. */ size_t util_strcpy(char *dest, const char *src, size_t max); /* * Parse a MIME type string to retrieve the type without parameters from it. * * Stores the MIME type in dest and returns the length of the MIME type. */ size_t util_mime_type(const char *mime_str, char *dest, size_t size); /* * Get the next mime type parameter name. * * The parameter name is read from the beginning of param_str and written to * dest, including NUL termination. size specifies the size of dest. If a * parameter was found in param_str, the function returns the length of the * parameter name written to dest, excluding the NUL termination. */ size_t util_mime_next_param(const char *param_str, char *dest, size_t size); #endif /* GEMINI_SERVER_UTIL_H */