Name: Anonymous 2011-01-22 13:55
That is all.
int copy_data(int srcfd, int dstfd)
{
char buf[8192];
ssize_t n;
int total = 0;
/* Copy the little bytes themselves. (Source from cp.c). */
while ((n = read(srcfd, buf, sizeof(buf))) > 0)
{
char *bp = buf;
ssize_t r;
while (n > 0 && (r= write(dstfd, bp, n)) > 0)
{
bp += r;
n -= r;
total += r;
}
if (r <= 0)
{
if (r == 0)
{
fprintf(stderr, "Warning: EOF writing to output file.\n");
return(-1);
}
}
}
return(total);
}
if (r <= 0)
{
if (r == 0)
{
fprintf(stderr, "Warning: EOF writing to output file.\n");
return(-1);
}
}
/* A small utility to append an a.out header to an arbitrary file. This allows
* inclusion of arbitrary data in the boot image, so that it is magically
* loaded as a RAM disk. The a.out header is structured as follows:
*
* a_flags: A_IMG to indicate this is not an executable
*
* Created: April 2005, Jorrit N. Herder
*/
static int copy_data(int srcfd, int dstfd)
{
char buf[8192];
ssize_t n;
int total=0;
/** FIXME: handle error from read() */
/* Copy the little bytes themselves. (Source from cp.c). */
while ((n= read(srcfd, buf, sizeof(buf))) > 0) {
char *bp = buf;
ssize_t r = 0;
/** FIXME: handle error from write() */
while (n > 0 && (r= write(dstfd, bp, n)) > 0) {
bp += r;
n -= r;
total += r;
}
if (r == 0) {
fprintf(stderr, "Warning: EOF writing to output file.\n");
return(-1);
}
}
return(total);
}
# define ALLOC_BUF(_B, _S, _R) \
do { \
(_B) = (char*)malloc(_S); \
if ((_B) == NULL) \
return (_R); \
} while (0)