#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#define BUFFER_SIZE 50
int main()
{
int fd;
int i,bytes_write;
int len;
char *ptr;
char buffer_write[BUFFER_SIZE] = "hello!";
if((fd = open(buffer_print,O_WRONLY|O_CREAT)) == -1)
{
perror("open from file");
exit(-1);
}
for(i = 0; i < 3; i++)
{
ptr = buffer_write;
len = strlen(buffer_write);
while(bytes_write = write(fd,ptr,len))
{
if((bytes_write == -1) && (errno != EINTR) )
{
break;
}
else if(bytes_write == len)
{
break;
}
else if(bytes_write > 0)
{
ptr += bytes_write;
len -= bytes_write;
}
}
printf("\n");
}
close(fd);
return 0;
}
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#define BUFFER_SIZE 50
int main()
{
int fd;
int i,bytes_write;
int len;
char *ptr;
char buffer_write[BUFFER_SIZE] = "hello!";
if((fd = open(buffer_print,O_WRONLY|O_CREAT)) == -1)
{
perror("open from file");
exit(-1);
}
for(i = 0; i < 3; i++)
{
ptr = buffer_write;
len = strlen(buffer_write);
while(bytes_write = write(fd,ptr,len))
{
if((bytes_write == -1) && (errno != EINTR) )
{
break;
}
else if(bytes_write == len)
{
break;
}
else if(bytes_write > 0)
{
ptr += bytes_write;
len -= bytes_write;
}
}
printf("\n");
}
close(fd);
return 0;
}