[Wlug] writing to tape

Brad Noyes maitre@ccs.neu.edu
Wed, 17 Jul 2002 20:36:16 -0400


--HcAYCG3uE/tztfnV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi All,
I trying to write a program that will write to tape, but i can't seem to get it
to work correctly. i have attached a simple piece of source code that will open
a file (or device) and write the string "hello, tape". This program will work
with a file, and a floppy device, but not a tape device.

can anyone give me some pointers? what do i have to do differently to write to
tape?

Thanks,
--brad

--HcAYCG3uE/tztfnV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="write.c"

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char ** argv)
{
    int fd = 0;
    int nbytes;
    char * string = "hello, tape\n";

    /* check argumentst */
    if (argc != 2)
    {
        printf("%s: <device>\n", argv[0]);
        return 1;
    }

    /* open op device and check for a valid file descripter */
    printf("opening %s\n", argv[1]);
    if((fd = open(argv[1],  O_RDWR|O_CREAT | O_TRUNC,  S_IRUSR|S_IWUSR )) <= 0)
    {
        perror("open: ");
        return 1;
    }
    printf("fd = %d\n", fd);

    /* write the string to file */
    if((nbytes = write(fd, string, strlen(string))) < 0);
    {
        perror("write: ");
    }
    printf("write %d bytes, to %s, fd = %d\n", nbytes, argv[1], fd);

    close(fd);
}

--HcAYCG3uE/tztfnV--