Mihail Mihaylov wrote:

> Right now I experience some difficulties using int write( int, char*, int );
> In the simple program that I have attached I first move to a location within
> a file using long lseek(int, long, int) and then I write some dummy data 
> using the int write( int, char*, int ) function. 
> I am doing that under Solaris, and for unknown reason the dummy string 
> that I am trying to write goes not at the pre-set location, but instead 
> goes to the very beginning of the file. The file size though is updatedA 
> correctly, if I move to a location that is currently outside the file 
> range.

Your program works fine for me under Linux.

C++ is notoriously non-portable. Try rewriting it as a C program, i.e.

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

int main(void) 
{
        int fd;
        long offset = 512;

        if ((fd = open("save.txt", O_WRONLY | O_CREAT, 0644)) < 0)
        {
                perror("Error opening file save.txt");
                exit(1);
        }

        lseek(fd, offset, SEEK_SET);
        write(fd, "string1", 7);

        close(fd);

        return 0;
}

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to