Implementing a custom stdndup for windows

This commit is contained in:
Zoe Roux
2021-04-15 00:48:03 +02:00
parent cd5cec6a93
commit 540f70a0cf
3 changed files with 25 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ add_library(transcoder SHARED
src/transmuxer.c
src/path_helper.c
src/destroyer.c
src/compatibility.c
)
set_property(TARGET transcoder PROPERTY C_STANDARD 11)
set_property(TARGET transcoder PROPERTY POSITION_INDEPENDENT_CODE ON)

View File

@@ -7,9 +7,11 @@
#define _GNU_SOURCE // For asprintf
#include <stdio.h>
#ifdef __WIN32__
#if defined(_WIN32) || defined(WIN32)
#define kmkdir(dir, mode) mkdir(dir)
#include <io.h>
#include <stddef.h>
char *strndup(const char *str, size_t count);
#else
#define kmkdir(dir, mode) mkdir(dir, mode)
#include <unistd.h>

21
src/compatibility.c Normal file
View File

@@ -0,0 +1,21 @@
//
// Created by Zoe Roux on 2021-04-15.
//
#include "compatibility.h"
#include <stdlib.h>
#include <string.h>
#if defined(_WIN32) || defined(WIN32)
char *strndup(const char *str, size_t count)
{
size_t len = strnlen(str, count);
char *ret = malloc(sizeof(char) * (len + 1));
if (!ret)
return NULL;
ret[len] = '\0';
memcpy(ret, str, len);
return ret;
}
#endif