Re: [PATCH 2/8] kern: add snprintf

2014-02-01 Thread Samuel Thibault
Justus Winter, le Sat 01 Feb 2014 15:09:22 +0100, a écrit :
> * kern/printf.c (snprintf): New function.
> * kern/printf.h (snprintf): New declaration.

Ack.

> ---
>  kern/printf.c | 10 ++
>  kern/printf.h |  1 +
>  2 files changed, 11 insertions(+)
> 
> diff --git a/kern/printf.c b/kern/printf.c
> index af59d5a..ea78d48 100644
> --- a/kern/printf.c
> +++ b/kern/printf.c
> @@ -615,6 +615,16 @@ vsnprintf(char *buf, size_t size, const char *fmt, 
> va_list args)
>    return cookie.index;
>  }
>  
> +int
> +snprintf(char *buf, size_t size, const char *fmt, ...)
> +{
> + int written;
> + va_list listp;
> + va_start(listp, fmt);
> + written = vsnprintf(buf, size, fmt, listp);
> + va_end(listp);
> + return written;
> +}
>  
>  void safe_gets(str, maxlen)
>   char *str;
> diff --git a/kern/printf.h b/kern/printf.h
> index 8b4e760..0f8b328 100644
> --- a/kern/printf.h
> +++ b/kern/printf.h
> @@ -40,6 +40,7 @@ extern void printnum (unsigned long u, int base,
>    vm_offset_t putc_arg);
>  
>  extern int sprintf (char *buf, const char *fmt, ...);
> +extern int snprintf (char *buf, size_t size, const char *fmt, ...);
>  extern int vsnprintf (char *buf, size_t size, const char *fmt, va_list args);
>  
>  extern int printf (const char *fmt, ...);
> -- 
> 1.8.5.2
> 

-- 
Samuel
 RM> Mauvais OS, changer d'OS (c)(r)(tm)
 J'ai windows 98 et comment faire pour changer l'os de windows 98?
 Dans ajout et suppression du programme et il ne parle pas d'os.
 -+- DN in : GNU -+- L'O.S. est las, hélas, c'est là qu'est l'os -+-



[PATCH 2/8] kern: add snprintf

2014-02-01 Thread Justus Winter
* kern/printf.c (snprintf): New function.
* kern/printf.h (snprintf): New declaration.
---
 kern/printf.c | 10 ++
 kern/printf.h |  1 +
 2 files changed, 11 insertions(+)

diff --git a/kern/printf.c b/kern/printf.c
index af59d5a..ea78d48 100644
--- a/kern/printf.c
+++ b/kern/printf.c
@@ -615,6 +615,16 @@ vsnprintf(char *buf, size_t size, const char *fmt, va_list 
args)
   return cookie.index;
 }
 
+int
+snprintf(char *buf, size_t size, const char *fmt, ...)
+{
+   int written;
+   va_list listp;
+   va_start(listp, fmt);
+   written = vsnprintf(buf, size, fmt, listp);
+   va_end(listp);
+   return written;
+}
 
 void safe_gets(str, maxlen)
char *str;
diff --git a/kern/printf.h b/kern/printf.h
index 8b4e760..0f8b328 100644
--- a/kern/printf.h
+++ b/kern/printf.h
@@ -40,6 +40,7 @@ extern void printnum (unsigned long u, int base,
   vm_offset_t putc_arg);
 
 extern int sprintf (char *buf, const char *fmt, ...);
+extern int snprintf (char *buf, size_t size, const char *fmt, ...);
 extern int vsnprintf (char *buf, size_t size, const char *fmt, va_list args);
 
 extern int printf (const char *fmt, ...);
-- 
1.8.5.2




Re: snprintf

2001-11-29 Thread Marcus Brinkmann

On Wed, Nov 28, 2001 at 06:27:31PM -0800, James Morrison wrote:
> This same code on GNU/Hurd with stdio sets limited[0] to '\0'
> but does not touch any other characters.  snprintf returns 5
> on GNU/Hurd as well.

It's a bug in stdio.  Please debug and fix it.

Marcus

-- 
`Rhubarb is no Egyptian god.' Debian http://www.debian.org [EMAIL PROTECTED]
Marcus Brinkmann  GNUhttp://www.gnu.org[EMAIL PROTECTED]
[EMAIL PROTECTED]
http://www.marcus-brinkmann.de

___
Bug-hurd mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-hurd



Re: snprintf

2001-11-29 Thread Andreas Schwab

James Morrison <[EMAIL PROTECTED]> writes:

|>  Hello,
|> I've noticed that on GNU/Hurd snprintf doesn't work if
|> the expanded template exceeds the size given.
|> 
|> eg
|>     char limited[5];
|> snprintf(limited,5,"12345");
|> 
|> On GNU/Linux with libio snprintf sets limited to "1234" and returns
|> 5.

This is correct:

7.19.6.5 The snprintf function

[#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 neg ative 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.

Andreas.

-- 
Andreas Schwab  "And now for something
[EMAIL PROTECTED]  completely different."
SuSE Labs, SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5

___
Bug-hurd mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-hurd



snprintf

2001-11-28 Thread James Morrison

 Hello,
I've noticed that on GNU/Hurd snprintf doesn't work if
the expanded template exceeds the size given.

eg
char limited[5];
    snprintf(limited,5,"12345");

On GNU/Linux with libio snprintf sets limited to "1234" and returns
5.

This same code on GNU/Hurd with stdio sets limited[0] to '\0'
but does not touch any other characters.  snprintf returns 5
on GNU/Hurd as well.

If the template string is extended the results say the same with the
return value changing appropriatly. snprintf works fine on GNU/Hurd
if the resulting string is less than maxsize passed to snprintf.

=
James Morrison
   University of Waterloo
   Computer Science - Digital Hardware
   2A co-op
http://hurd.dyndns.org

Anyone refering this as 'Open Source' shall be eaten by a GNU

__
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1

___
Bug-hurd mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-hurd