minix/commands/aal/wr_bytes.c

34 lines
778 B
C
Raw Normal View History

2005-04-21 16:53:53 +02:00
/* $Header$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#define MININT (1 << (sizeof(int) * 8 - 1))
#define MAXCHUNK (~MININT) /* Highest count we write(2). */
/* Notice that MAXCHUNK itself might be too large with some compilers.
You have to put it in an int!
*/
2010-07-05 01:01:32 +02:00
#include <sys/types.h>
#include <unistd.h>
#include "wr_bytes.h"
#include "archiver.h"
2005-04-21 16:53:53 +02:00
static int maxchunk = MAXCHUNK;
/*
* Just write "cnt" bytes to file-descriptor "fd".
*/
2010-07-05 01:01:32 +02:00
void wr_bytes(int fd, register char *string, long cnt)
2005-04-21 16:53:53 +02:00
{
while (cnt) {
register int n = cnt >= maxchunk ? maxchunk : cnt;
if (write(fd, string, n) != n)
wr_fatal();
string += n;
cnt -= n;
}
}