[英]C99: Custom implementations of non-standard functions
In my project, I want to use a non-standard library function, which which may not be defined on certain systems.在我的项目中,我想使用一个非标准库 function,在某些系统上可能没有定义。 In my case, it is strlcpy
.就我而言,它是strlcpy
。
From man strcpy
:从man strcpy
:
Some systems (the BSDs, Solaris, and others) provide the following function:
size_t strlcpy(char *dest, const char *src, size_t size);
...
My system does not implement strlcpy
, so I rolled my own.我的系统没有实现strlcpy
,所以我自己推出了。 All is well, until compiling on a system that already has strlcpy
defined: error: conflicting types for strlcpy
.一切都很好,直到在已经定义了strlcpy
的系统上编译: error: conflicting types for strlcpy
。
My question: how can I implement a function that may cause naming conflicts down the road?我的问题:如何实现可能导致命名冲突的 function? Can I use some directive like #ifdef some_macro(strlcpy)
, or am I simply left with renaming strlcpy
to my_strlcpy
?我可以使用像#ifdef some_macro(strlcpy)
这样的指令,还是我只是将strlcpy
重命名为my_strlcpy
?
check if you need to include.检查是否需要包含。
Example - the list of systems will be much longer I think示例 - 我认为系统列表会更长
#if !defined(__FreeBSD__)
#include "mystring.h"
#endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.