c-md/srcs/utils/string/infer_ext_from_filename.c.md
lohhiiccc 80f7a1b9b6 feat(build): add build instructions in README and convert sources to .c.md format
- Add detailed build and bootstrap instructions to README.md.
 - Convert all source and header files from .c/.h to .c.md/.h.md.
 - Add bootstrap.sh script for automated building across version history.
 - Update Makefile and sources.mk to reflect new markdown-based source organization.
2026-01-12 14:54:49 +01:00

780 B

#include <string.h>

#include "utils.h"

const char *
infer_ext_from_filename(const char *path)
{
	static char	ext_buffer[32];
	const char	*md_ext;
	const char	*before_md;
	const char	*dot;
	size_t		len;
	size_t		ext_len;

	if (NULL == path)
		return (NULL);
	len = strlen(path);
	if (len < 6)
		return (NULL);
	md_ext = path + len - 3;
	if (0 != strcmp(md_ext, ".md"))
		return (NULL);
	before_md = md_ext - 1;
	while (before_md > path && '.' != *before_md)
		before_md--;
	if (before_md == path || '.' != *before_md)
		return (NULL);
	dot = before_md;
	if (dot + 1 >= md_ext)
		return (NULL);
	ext_len = md_ext - (dot + 1);
	if (ext_len >= sizeof(ext_buffer))
		return (NULL);
	memcpy(ext_buffer, dot + 1, ext_len);
	ext_buffer[ext_len] = '\0';
	return (ext_buffer);
}