strnzcpy - strncpy mit 0-terminierungsgarantie

This commit is contained in:
Enno Rehling 2002-04-21 10:52:05 +00:00
parent 4d7210014f
commit 0960a541ea
1 changed files with 10 additions and 4 deletions

View File

@ -23,9 +23,6 @@
#define CONFIG_H #define CONFIG_H
/**** **** /**** ****
** Debugging Libraries ** ** Debugging Libraries **
**** ****/ **** ****/
@ -71,6 +68,10 @@
** Architecture Dependent ** ** Architecture Dependent **
**** ****/ **** ****/
#if _MSC_VER
# define STRNCPY_HAS_ZEROTERMINATION
#endif
/* für solaris: */ /* für solaris: */
#ifdef SOLARIS #ifdef SOLARIS
# define _SYS_PROCSET_H # define _SYS_PROCSET_H
@ -89,7 +90,7 @@
/* warning C4100: <name> : unreferenced formal parameter */ /* warning C4100: <name> : unreferenced formal parameter */
#endif #endif
#ifdef __linux__ #ifdef __GNUC__
# ifndef _BSD_SOURCE # ifndef _BSD_SOURCE
# define _BSD_SOURCE # define _BSD_SOURCE
# define __USE_BSD # define __USE_BSD
@ -240,4 +241,9 @@ extern char * strdup(const char *s);
# define true ((boolean)!false) # define true ((boolean)!false)
#endif #endif
#ifdef STRNCPY_HAS_ZEROTERMINATION
# define strnzcpy(dst, src, len) strncpy(dst, src, len)
#else
# define strnzcpy(dst, src, len) for(;;) { strncpy(dst, src, len); if (len) dst[len-1]=0; break; }
#endif
#endif #endif