mirror of
https://github.com/zoriya/Kyoo.Transcoder.git
synced 2025-12-06 06:26:11 +00:00
Implementing a custom stdndup for windows
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
21
src/compatibility.c
Normal 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
|
||||
Reference in New Issue
Block a user