/* a sample program that writes two strings from specified
memory address into a file. */
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/uio.h>

int main() {
    struct iovec iov[2];
    char string1[]= "This is a test line1.";
    char string2[]= "This is a test line2.";
    char *name;
    int iovcnt = 2;
    int fd1;

    if((name = tmpnam(NULL)) == NULL) {
        printf("temp file name could not be made. \n");
        exit(1);
    }
    if((fd1=open(name,O_WRONLY | O_CREAT))==-1){
      printf("Cannot open file.\n");
      exit(1);
    }
    iov[0].iov_base = string1;
    iov[0].iov_len  = strlen(string1);
    iov[1].iov_base = string2;
    iov[1].iov_len  = strlen(string2);
    writev(fd1,iov,iovcnt);
    printf("'%s' has been written to a temporary file.\n",string1);
    printf("'%s' has been written to a temporary file.\n",string2);
    close(fd1);
    remove(name);
}



        
