Fossil SCM
Redo the enhancement of check-in [1e881f59786bd891] in a way that is portable to legacy systems. The strnlen() function is now always available.
Commit
1a84fe09c7a09db713e53746d2527eeb4330ff72a757679820a72f41f9d59b1a
Parent
2f7527e88c169da…
1 file changed
+18
-2
+18
-2
| --- src/printf.c | ||
| +++ src/printf.c | ||
| @@ -198,10 +198,26 @@ | ||
| 198 | 198 | /* |
| 199 | 199 | ** Size of temporary conversion buffer. |
| 200 | 200 | */ |
| 201 | 201 | #define etBUFSIZE 500 |
| 202 | 202 | |
| 203 | +/* | |
| 204 | +** Find the length of a string as long as that length does not | |
| 205 | +** exceed N bytes. If no zero terminator is seen in the first | |
| 206 | +** N bytes then return N. If N is negative, then this routine | |
| 207 | +** is an alias for strlen(). | |
| 208 | +*/ | |
| 209 | +#if _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L | |
| 210 | +# define StrNLen32(Z,N) (int)strnlen(Z,N) | |
| 211 | +#else | |
| 212 | +static int StrNLen32(const char *z, int N){ | |
| 213 | + int n = 0; | |
| 214 | + while( (N-- != 0) && *(z++)!=0 ){ n++; } | |
| 215 | + return n; | |
| 216 | +} | |
| 217 | +#endif | |
| 218 | + | |
| 203 | 219 | /* |
| 204 | 220 | ** Return an appropriate set of flags for wiki_convert() for displaying |
| 205 | 221 | ** comments on a timeline. These flag settings are determined by |
| 206 | 222 | ** configuration parameters. |
| 207 | 223 | ** |
| @@ -640,11 +656,11 @@ | ||
| 640 | 656 | case etPATH: { |
| 641 | 657 | int i; |
| 642 | 658 | int limit = flag_alternateform ? va_arg(ap,int) : -1; |
| 643 | 659 | char *e = va_arg(ap,char*); |
| 644 | 660 | if( e==0 ){e="";} |
| 645 | - length = (int)strnlen(e,limit); | |
| 661 | + length = StrNLen32(e, limit); | |
| 646 | 662 | zExtra = bufpt = fossil_malloc(length+1); |
| 647 | 663 | for( i=0; i<length; i++ ){ |
| 648 | 664 | if( e[i]=='\\' ){ |
| 649 | 665 | bufpt[i]='/'; |
| 650 | 666 | }else{ |
| @@ -669,11 +685,11 @@ | ||
| 669 | 685 | }else if( xtype==etDYNSTRING ){ |
| 670 | 686 | zExtra = bufpt; |
| 671 | 687 | }else if( xtype==etSTRINGID ){ |
| 672 | 688 | precision = hash_digits(flag_altform2); |
| 673 | 689 | } |
| 674 | - length = (int)strnlen(bufpt,limit); | |
| 690 | + length = StrNLen32(bufpt, limit); | |
| 675 | 691 | if( precision>=0 && precision<length ) length = precision; |
| 676 | 692 | break; |
| 677 | 693 | } |
| 678 | 694 | case etBLOB: { |
| 679 | 695 | int limit = flag_alternateform ? va_arg(ap, int) : -1; |
| 680 | 696 |
| --- src/printf.c | |
| +++ src/printf.c | |
| @@ -198,10 +198,26 @@ | |
| 198 | /* |
| 199 | ** Size of temporary conversion buffer. |
| 200 | */ |
| 201 | #define etBUFSIZE 500 |
| 202 | |
| 203 | /* |
| 204 | ** Return an appropriate set of flags for wiki_convert() for displaying |
| 205 | ** comments on a timeline. These flag settings are determined by |
| 206 | ** configuration parameters. |
| 207 | ** |
| @@ -640,11 +656,11 @@ | |
| 640 | case etPATH: { |
| 641 | int i; |
| 642 | int limit = flag_alternateform ? va_arg(ap,int) : -1; |
| 643 | char *e = va_arg(ap,char*); |
| 644 | if( e==0 ){e="";} |
| 645 | length = (int)strnlen(e,limit); |
| 646 | zExtra = bufpt = fossil_malloc(length+1); |
| 647 | for( i=0; i<length; i++ ){ |
| 648 | if( e[i]=='\\' ){ |
| 649 | bufpt[i]='/'; |
| 650 | }else{ |
| @@ -669,11 +685,11 @@ | |
| 669 | }else if( xtype==etDYNSTRING ){ |
| 670 | zExtra = bufpt; |
| 671 | }else if( xtype==etSTRINGID ){ |
| 672 | precision = hash_digits(flag_altform2); |
| 673 | } |
| 674 | length = (int)strnlen(bufpt,limit); |
| 675 | if( precision>=0 && precision<length ) length = precision; |
| 676 | break; |
| 677 | } |
| 678 | case etBLOB: { |
| 679 | int limit = flag_alternateform ? va_arg(ap, int) : -1; |
| 680 |
| --- src/printf.c | |
| +++ src/printf.c | |
| @@ -198,10 +198,26 @@ | |
| 198 | /* |
| 199 | ** Size of temporary conversion buffer. |
| 200 | */ |
| 201 | #define etBUFSIZE 500 |
| 202 | |
| 203 | /* |
| 204 | ** Find the length of a string as long as that length does not |
| 205 | ** exceed N bytes. If no zero terminator is seen in the first |
| 206 | ** N bytes then return N. If N is negative, then this routine |
| 207 | ** is an alias for strlen(). |
| 208 | */ |
| 209 | #if _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L |
| 210 | # define StrNLen32(Z,N) (int)strnlen(Z,N) |
| 211 | #else |
| 212 | static int StrNLen32(const char *z, int N){ |
| 213 | int n = 0; |
| 214 | while( (N-- != 0) && *(z++)!=0 ){ n++; } |
| 215 | return n; |
| 216 | } |
| 217 | #endif |
| 218 | |
| 219 | /* |
| 220 | ** Return an appropriate set of flags for wiki_convert() for displaying |
| 221 | ** comments on a timeline. These flag settings are determined by |
| 222 | ** configuration parameters. |
| 223 | ** |
| @@ -640,11 +656,11 @@ | |
| 656 | case etPATH: { |
| 657 | int i; |
| 658 | int limit = flag_alternateform ? va_arg(ap,int) : -1; |
| 659 | char *e = va_arg(ap,char*); |
| 660 | if( e==0 ){e="";} |
| 661 | length = StrNLen32(e, limit); |
| 662 | zExtra = bufpt = fossil_malloc(length+1); |
| 663 | for( i=0; i<length; i++ ){ |
| 664 | if( e[i]=='\\' ){ |
| 665 | bufpt[i]='/'; |
| 666 | }else{ |
| @@ -669,11 +685,11 @@ | |
| 685 | }else if( xtype==etDYNSTRING ){ |
| 686 | zExtra = bufpt; |
| 687 | }else if( xtype==etSTRINGID ){ |
| 688 | precision = hash_digits(flag_altform2); |
| 689 | } |
| 690 | length = StrNLen32(bufpt, limit); |
| 691 | if( precision>=0 && precision<length ) length = precision; |
| 692 | break; |
| 693 | } |
| 694 | case etBLOB: { |
| 695 | int limit = flag_alternateform ? va_arg(ap, int) : -1; |
| 696 |