/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1990-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* *18***********************************************************************/19#pragma prototyped20/*21* Glenn Fowler22* AT&T Research23*24* write n bytes to fd, using multiple write(2) if necessary25*/2627#include "cslib.h"2829ssize_t30cswrite(register Cs_t* state, int fd, const void* buf, register size_t n)31{32register char* p = (char*)buf;33register ssize_t i;3435while (n > 0)36{37messagef((state->id, NiL, -9, "write(%d,%d) `%-.*s'", fd, n, n - 1, (n > 0 && *((char*)buf + n - 1) == '\n') ? (char*)buf : "..."));38if ((i = write(fd, p, n)) <= 0)39{40messagef((state->id, NiL, -9, "write(%d,%d) [%d]", fd, n, i));41if (i && p == (char*)buf)42return i;43break;44}45n -= i;46p += i;47}48return p - (char*)buf;49}5051ssize_t52_cs_write(int fd, const void* buf, size_t n)53{54return cswrite(&cs, fd, buf, n);55}565758