(__getlogin_r_loginuid): Also fail if tpwd after pwuid call is NULL.
[glibc.git] / libio / iowpadn.c
blob7bbb06192b0cdfba260af515a6de7bea86b0b02b
1 /* Copyright (C) 1993, 1997, 1999 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library 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 GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA.
19 As a special exception, if you link the code in this file with
20 files compiled with a GNU compiler to produce an executable,
21 that does not cause the resulting executable to be covered by
22 the GNU Lesser General Public License. This exception does not
23 however invalidate any other reasons why the executable file
24 might be covered by the GNU Lesser General Public License.
25 This exception applies to code released by its copyright holders
26 in files containing the exception. */
28 #include "libioP.h"
30 #define PADSIZE 16
31 static wchar_t const blanks[PADSIZE] =
33 L' ', L' ', L' ', L' ', L' ', L' ', L' ', L' ',
34 L' ', L' ', L' ', L' ', L' ', L' ', L' ', L' '
36 static wchar_t const zeroes[PADSIZE] =
38 L'0', L'0', L'0', L'0', L'0', L'0', L'0', L'0',
39 L'0', L'0', L'0', L'0', L'0', L'0', L'0', L'0'
42 _IO_ssize_t
43 _IO_wpadn (fp, pad, count)
44 _IO_FILE *fp;
45 wint_t pad;
46 _IO_ssize_t count;
48 wchar_t padbuf[PADSIZE];
49 const wchar_t *padptr;
50 int i;
51 _IO_size_t written = 0;
52 _IO_size_t w;
54 if (pad == L' ')
55 padptr = blanks;
56 else if (pad == L'0')
57 padptr = zeroes;
58 else
60 for (i = PADSIZE; --i >= 0; )
61 padbuf[i] = pad;
62 padptr = padbuf;
64 for (i = count; i >= PADSIZE; i -= PADSIZE)
66 w = _IO_sputn (fp, (char *) padptr, PADSIZE);
67 written += w;
68 if (w != PADSIZE)
69 return written;
72 if (i > 0)
74 w = _IO_sputn (fp, (char *) padptr, i);
75 written += w;
77 return written;