Dr Andrew Scott G7VAV

My photo
 
June 2025
Mo Tu We Th Fr Sa Su
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 1 2 3 4 5 6


string3.h
001: /* Copyright (C) 2004, 2005, 2007, 2009, 2010 Free Software Foundation, Inc.
002:    This file is part of the GNU C Library.
003: 
004:    The GNU C Library is free software; you can redistribute it and/or
005:    modify it under the terms of the GNU Lesser General Public
006:    License as published by the Free Software Foundation; either
007:    version 2.1 of the License, or (at your option) any later version.
008: 
009:    The GNU C Library is distributed in the hope that it will be useful,
010:    but WITHOUT ANY WARRANTY; without even the implied warranty of
011:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:    Lesser General Public License for more details.
013: 
014:    You should have received a copy of the GNU Lesser General Public
015:    License along with the GNU C Library; if not, write to the Free
016:    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
017:    02111-1307 USA.  */
018: 
019: #ifndef _STRING_H
020: # error "Never use <bits/string3.h> directly; include <string.h> instead."
021: #endif
022: 
023: __warndecl (__warn_memset_zero_len,
024:             "memset used with constant zero length parameter; this could be due to transposed parameters");
025: 
026: #ifndef __cplusplus
027: /* XXX This is temporarily.  We should not redefine any of the symbols
028:    and instead integrate the error checking into the original
029:    definitions.  */
030: # undef memcpy
031: # undef memmove
032: # undef memset
033: # undef strcat
034: # undef strcpy
035: # undef strncat
036: # undef strncpy
037: # ifdef __USE_GNU
038: #  undef mempcpy
039: #  undef stpcpy
040: # endif
041: # ifdef __USE_BSD
042: #  undef bcopy
043: #  undef bzero
044: # endif
045: #endif
046: 
047: 
048: __extern_always_inline void *
049: __NTH (memcpy (void *__restrict __dest, __const void *__restrict __src,
050:                size_t __len))
051: {
052:   return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
053: }
054: 
055: __extern_always_inline void *
056: __NTH (memmove (void *__dest, __const void *__src, size_t __len))
057: {
058:   return __builtin___memmove_chk (__dest, __src, __len, __bos0 (__dest));
059: }
060: 
061: #ifdef __USE_GNU
062: __extern_always_inline void *
063: __NTH (mempcpy (void *__restrict __dest, __const void *__restrict __src,
064:                 size_t __len))
065: {
066:   return __builtin___mempcpy_chk (__dest, __src, __len, __bos0 (__dest));
067: }
068: #endif
069: 
070: 
071: /* The first two tests here help to catch a somewhat common problem
072:    where the second and third parameter are transposed.  This is
073:    especially problematic if the intended fill value is zero.  In this
074:    case no work is done at all.  We detect these problems by referring
075:    non-existing functions.  */
076: __extern_always_inline void *
077: __NTH (memset (void *__dest, int __ch, size_t __len))
078: {
079:   if (__builtin_constant_p (__len) && __len == 0
080:       && (!__builtin_constant_p (__ch) || __ch != 0))
081:     {
082:       __warn_memset_zero_len ();
083:       return __dest;
084:     }
085:   return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
086: }
087: 
088: #ifdef __USE_BSD
089: __extern_always_inline void
090: __NTH (bcopy (__const void *__src, void *__dest, size_t __len))
091: {
092:   (void) __builtin___memmove_chk (__dest, __src, __len, __bos0 (__dest));
093: }
094: 
095: __extern_always_inline void
096: __NTH (bzero (void *__dest, size_t __len))
097: {
098:   (void) __builtin___memset_chk (__dest, '\0', __len, __bos0 (__dest));
099: }
100: #endif
101: 
102: __extern_always_inline char *
103: __NTH (strcpy (char *__restrict __dest, __const char *__restrict __src))
104: {
105:   return __builtin___strcpy_chk (__dest, __src, __bos (__dest));
106: }
107: 
108: #ifdef __USE_GNU
109: __extern_always_inline char *
110: __NTH (stpcpy (char *__restrict __dest, __const char *__restrict __src))
111: {
112:   return __builtin___stpcpy_chk (__dest, __src, __bos (__dest));
113: }
114: #endif
115: 
116: 
117: __extern_always_inline char *
118: __NTH (strncpy (char *__restrict __dest, __const char *__restrict __src,
119:                 size_t __len))
120: {
121:   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
122: }
123: 
124: // XXX We have no corresponding builtin yet.
125: extern char *__stpncpy_chk (char *__dest, __const char *__src, size_t __n,
126:                             size_t __destlen) __THROW;
127: extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest,
128:                                                __const char *__src,
129:                                                size_t __n), stpncpy);
130: 
131: __extern_always_inline char *
132: __NTH (stpncpy (char *__dest, __const char *__src, size_t __n))
133: {
134:   if (__bos (__dest) != (size_t) -1
135:       && (!__builtin_constant_p (__n) || __n <= __bos (__dest)))
136:     return __stpncpy_chk (__dest, __src, __n, __bos (__dest));
137:   return __stpncpy_alias (__dest, __src, __n);
138: }
139: 
140: 
141: __extern_always_inline char *
142: __NTH (strcat (char *__restrict __dest, __const char *__restrict __src))
143: {
144:   return __builtin___strcat_chk (__dest, __src, __bos (__dest));
145: }
146: 
147: 
148: __extern_always_inline char *
149: __NTH (strncat (char *__restrict __dest, __const char *__restrict __src,
150:                 size_t __len))
151: {
152:   return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
153: }
154: 


for client (none)
© Andrew Scott 2006 - 2025,
All Rights Reserved
http://www.andrew-scott.uk/
Andrew Scott
http://www.andrew-scott.co.uk/