]> granicus.if.org Git - php/commitdiff
Fix snprintf test.
authorSascha Schumann <sas@php.net>
Sat, 28 Jun 2003 12:29:07 +0000 (12:29 +0000)
committerSascha Schumann <sas@php.net>
Sat, 28 Jun 2003 12:29:07 +0000 (12:29 +0000)
C99 allows for the Single Unix Spec semantics which prescribe a return
value of -1 for n == 0 which is treated as an encoding error.
This reenables use of snprintf on Solaris at least.

Relevant excerpts from ection 7.19.6.5:

    Description

    [..] If n is zero, nothing is written, and s may be a null pointer. [..]

    Returns

    The snprintf function returns the number of characters that would have been
    written had n been sufficiently large, not counting the terminating null
    character, or a negative value if an encoding error occurred.

Single Unix Spec:

http://www.opengroup.org/onlinepubs/007908799/xsh/fprintf.html

acinclude.m4

index 356fe1e44141d0bf91efd23eb3a4c0be6c507da7..68590a0e9d6a12cc8790e602d73afb2efce6ec44 100644 (file)
@@ -1186,7 +1186,9 @@ main() {
        int res = 0;
        res = res || (snprintf(buf, 2, "marcus") != 6); 
        res = res || (buf[1] != '\0');
-       res = res || (snprintf(buf, 0, "boerger") != 7);
+       /* Implementations may consider this as an encoding error */
+       snprintf(buf, 0, "boerger");
+       /* However, they MUST ignore the pointer */
        res = res || (buf[0] != 'm');
        res = res || (snprintf(NULL, 0, "boerger") != 7);
        res = res || (snprintf(buf, sizeof(buf), "%f", 0.12345678) != 8);