xref: /inferno-os/libkern/fmtprint.c (revision 3cd4f1d15146c08f05206d6328ecbc1c7fdc8dfa)
137da2899SCharles.Forsyth /*
237da2899SCharles.Forsyth  * The authors of this software are Rob Pike and Ken Thompson.
337da2899SCharles.Forsyth  *              Copyright (c) 2002 by Lucent Technologies.
437da2899SCharles.Forsyth  * Permission to use, copy, modify, and distribute this software for any
537da2899SCharles.Forsyth  * purpose without fee is hereby granted, provided that this entire notice
637da2899SCharles.Forsyth  * is included in all copies of any software which is or includes a copy
737da2899SCharles.Forsyth  * or modification of this software and in all copies of the supporting
837da2899SCharles.Forsyth  * documentation for such software.
937da2899SCharles.Forsyth  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
1037da2899SCharles.Forsyth  * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
1137da2899SCharles.Forsyth  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
1237da2899SCharles.Forsyth  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
1337da2899SCharles.Forsyth  */
1437da2899SCharles.Forsyth #include "lib9.h"
1537da2899SCharles.Forsyth #include "fmtdef.h"
1637da2899SCharles.Forsyth 
1737da2899SCharles.Forsyth 
1837da2899SCharles.Forsyth /*
1937da2899SCharles.Forsyth  * format a string into the output buffer
2037da2899SCharles.Forsyth  * designed for formats which themselves call fmt,
2137da2899SCharles.Forsyth  * but ignore any width flags
2237da2899SCharles.Forsyth  */
2337da2899SCharles.Forsyth int
fmtprint(Fmt * f,char * fmt,...)2437da2899SCharles.Forsyth fmtprint(Fmt *f, char *fmt, ...)
2537da2899SCharles.Forsyth {
2637da2899SCharles.Forsyth 	va_list va;
2737da2899SCharles.Forsyth 	int n;
2837da2899SCharles.Forsyth 
2937da2899SCharles.Forsyth 	f->flags = 0;
3037da2899SCharles.Forsyth 	f->width = 0;
3137da2899SCharles.Forsyth 	f->prec = 0;
32*3cd4f1d1SCharles Forsyth 	va_copy(va, f->args);
33*3cd4f1d1SCharles Forsyth 	va_end(f->args);
3437da2899SCharles.Forsyth 	va_start(f->args, fmt);
3537da2899SCharles.Forsyth 	n = dofmt(f, fmt);
3637da2899SCharles.Forsyth 	va_end(f->args);
3737da2899SCharles.Forsyth 	f->flags = 0;
3837da2899SCharles.Forsyth 	f->width = 0;
3937da2899SCharles.Forsyth 	f->prec = 0;
40*3cd4f1d1SCharles Forsyth 	va_copy(f->args, va);
41*3cd4f1d1SCharles Forsyth 	va_end(va);
4237da2899SCharles.Forsyth 	if(n >= 0)
4337da2899SCharles.Forsyth 		return 0;
4437da2899SCharles.Forsyth 	return n;
4537da2899SCharles.Forsyth }
4637da2899SCharles.Forsyth 
47