/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#include "sfhdr.h"2223/* Write out a character n times24**25** Written by Kiem-Phong Vo.26*/2728#if __STD_C29ssize_t sfnputc(Sfio_t* f, int c, size_t n)30#else31ssize_t sfnputc(f,c,n)32Sfio_t* f; /* file to write */33int c; /* char to be written */34size_t n; /* number of time to repeat */35#endif36{37reg uchar* ps;38reg ssize_t p, w;39uchar buf[128];40reg int local;41SFMTXDECL(f); /* declare a local stream variable for multithreading */4243SFMTXENTER(f,-1);4445GETLOCAL(f,local);46if(SFMODE(f,local) != SF_WRITE && _sfmode(f,SF_WRITE,local) < 0)47SFMTXRETURN(f, -1);4849SFLOCK(f,local);5051/* write into a suitable buffer */52if((size_t)(p = (f->endb-(ps = f->next))) < n)53{ ps = buf; p = sizeof(buf); }54if((size_t)p > n)55p = n;56MEMSET(ps,c,p);57ps -= p;5859w = n;60if(ps == f->next)61{ /* simple sfwrite */62f->next += p;63if(c == '\n')64(void)SFFLSBUF(f,-1);65goto done;66}6768for(;;)69{ /* hard write of data */70if((p = SFWRITE(f,(Void_t*)ps,p)) <= 0 || (n -= p) <= 0)71{ w -= n;72goto done;73}74if((size_t)p > n)75p = n;76}77done :78SFOPEN(f,local);79SFMTXRETURN(f, w);80}818283