FreeNOS
vprintf.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <unistd.h>
19 #include "stdarg.h"
20 #include "stdio.h"
21 #include "stdlib.h"
22 
23 int vprintf(const char *format, va_list args)
24 {
25  char buf[1024];
26  Size size, written = 0;
27  Error e;
28 
29  // Write formatted string
30  size = vsnprintf(buf, sizeof(buf), format, args);
31 
32  // Write it to standard output
33  while (written < size)
34  {
35  e = write(1, buf + written, size - written);
36 
37  switch (e)
38  {
39  // Error occurred
40  case -1:
41  return e;
42 
43  // End of file reached
44  case 0:
45  return written;
46 
47  // Process bytes
48  default:
49  written += e;
50  }
51  }
52 
53  // Done
54  return written;
55 }
write
ssize_t write(int fildes, const void *buf, size_t nbyte)
Write on a file.
Definition: write.cpp:22
vsnprintf
int vsnprintf(char *buffer, unsigned int size, const char *fmt, va_list args)
Write a formatted string into a buffer.
Definition: vsnprintf.cpp:23
stdarg.h
va_list
__gnuc_va_list va_list
Definition: stdarg.h:105
Error
slong Error
Error code defined in Error.h.
Definition: Types.h:159
stdio.h
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
unistd.h
vprintf
int vprintf(const char *format, va_list args)
Output a formatted string to standard output, using a variable argument list.
Definition: vprintf.cpp:23
stdlib.h