snprintf

From: Douglas Gilbert (dougg@torque.net)
Date: Tue Apr 18 2000 - 08:47:32 EST


While browsing a draft copy of the C99 standard I thought
a stripped down version of snprintf would be useful in
the kernel. I can think of some proc_fs handling that would
be cleaner and safer using this call.

"man snprintf" (rh 6.2) indicates that glibc 2.1 has a C99
conforming implementation of this function for the user space.

Any comments on the "restrict"?

---------------------------------------------------------------
       The snprintf function

       Synopsis

       [#1]

               #include <stdio.h>
               int snprintf(char * restrict s, size_t n,
                       const char * restrict format, ...);

       Description

       [#2] The snprintf function is equivalent to fprintf, except |
       that the output is written into an array (specified by |
       argument s) rather than to a stream. If n is zero, nothing
       is written, and s may be a null pointer. Otherwise, output
       characters beyond the n-1st are discarded rather than being
       written to the array, and a null character is written at the
       end of the characters actually written into the array. If
       copying takes place between objects that overlap, the
       behavior is undefined.

       Returns

       [#3] 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. Thus, the null-
       terminated output has been completely written if and only if
       the returned value is nonnegative and less than n.

Doug Gilbert

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Apr 23 2000 - 21:00:13 EST