github.com/golang-haiku/go-1.4.3@v0.0.0-20190609233734-1f5ae41cc308/src/lib9/fmt/fmtvprint.c (about)

     1  /*
     2   * The authors of this software are Rob Pike and Ken Thompson,
     3   * with contributions from Mike Burrows and Sean Dorward.
     4   *
     5   *     Copyright (c) 2002-2006 by Lucent Technologies.
     6   *     Portions Copyright (c) 2004 Google Inc.
     7   * 
     8   * Permission to use, copy, modify, and distribute this software for any
     9   * purpose without fee is hereby granted, provided that this entire notice
    10   * is included in all copies of any software which is or includes a copy
    11   * or modification of this software and in all copies of the supporting
    12   * documentation for such software.
    13   * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
    14   * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 
    15   * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 
    16   * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
    17   */
    18  
    19  #include <u.h>
    20  #include <libc.h>
    21  #include "fmtdef.h"
    22  
    23  
    24  /*
    25   * Format a string into the output buffer.
    26   * Designed for formats which themselves call fmt.
    27   * Flags, precision and width are preserved.
    28   */
    29  int
    30  fmtvprint(Fmt *f, char *fmt, va_list args)
    31  {
    32  	va_list va;
    33  	int n, w, p;
    34  	unsigned long fl;
    35  
    36  	w = f->width;
    37  	p = f->prec;
    38  	fl = f->flags;
    39  	VA_COPY(va, f->args);
    40  	VA_END(f->args);
    41  	VA_COPY(f->args, args);
    42  	n = dofmt(f, fmt);
    43  	VA_END(f->args);
    44  	VA_COPY(f->args, va);
    45  	VA_END(va);
    46  	f->width = w;
    47  	f->prec = p;
    48  	f->flags = fl;
    49  	if(n >= 0)
    50  		return 0;
    51  	return n;
    52  }