Re: problem w/ function write(...)
From: Floyd L. Davidson (floyd_at_apaflo.com)
Date: 09/28/05
- Next message: garth_rockett_at_yahoo.com: "Mapping error codes to error messages"
- Previous message: Fletcher Glenn: "Re: problem w/ function write(...)"
- In reply to: ferbar: "Re: problem w/ function write(...)"
- Next in thread: ferbar: "Re: problem w/ function write(...)"
- Reply: ferbar: "Re: problem w/ function write(...)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 28 Sep 2005 07:56:18 -0800
"ferbar" <fbarsoba@gmail.com> wrote:
>Maxim Yegorushkin wrote:
>> ferbar wrote:
>>
>>
>> > fd = open(pathnameX, O_RDWR|O_CREAT|S_IWGRP);
>>
>> You messed up flags. It sould be:
>>
>> open(pathnameX, O_RDWR | O_CREAT, S_IWGRP);
>
>Thanks.. that helped. However, I still having problems.. when the file
>exist, now I get a permission denied message. I change the instruction
>with this:
>
>>> fd = open(pathnameX, O_RDWR | O_CREAT, S_IWUSR);
That gives the user write permission... but not read permission.
Before you were giving the group write permission only. But in
neither case does the user have read permission too.
>With user rights now works until de point it creates the file... but
>the second time I execute it, I get an error. So I changed it for
>this..
>
>>> fd = open(pathnameX, O_RDWR | O_APPEND, S_IWUSR);
>
>But now I get an error if the file exists.
Try this:
fd = open(pathnameX, O_RDWR | O_APPEND | O_CREAT, (S_IWUSR | S_IRUSR);
With that you will creat the file if it does not exist, it will
be in append mode, and will have read and write permissions for
the owner only.
If you are going to write to one fd and read from another, you
should probably open the first as O_WRONLY and the second as
O_RDONLY, though using O_RDWR will not harm anything.
>Also, when I try to write with this function, does not work either..
>let me show it..
>
>void write1test(int fd, int fd_o, void *buffer, int block_size, char
>*pathnameX) {
>
> ssize_t bytesw, bytesr;
> double t, t_t=0;
> size_t nbytes;
nbytes is not initialized.
> while (bytesr != 0) {
> bytesr = read(fd, buffer, block_size);
> t = now();
> bytesw = write(fd_o, buffer, nbytes);
So how many bytes is this going to write? Undetermined...
> t = now() - t;
> t_t += t;
> if (bytesw < 0) {
> perror("write:");
> exit(bytesw);
The value of bytesw is guaranteed to be negative here, but
exit() needs an argument that is an unsigned char value, between
0 and 255.
It is the exit status returned to the shell, which *will* be a
value from 0 to 255, regardless of the argument you give to
exit(). In other words, a -1 will cause a return status of 255,
and a 256 will cause a return status of 0. There is no harm in
providing values outside the range of 0-255, but it will not be
of any benefit either, and merely confuses the potential value
in having a meaningful exit status for your program.
> }
> }
> printf("time to write blocksizes %d to file %s: %g\n", block_size,
>pathnameX, t_t);
>}
>
>fd is a file desc. of an open file, pointing to the beginning..
>now() gets time of the day..
You might be better off keeping track of time using a long int rather
than a double?
-- Floyd L. Davidson <http://www.apaflo.com/floyd_davidson> Ukpeagvik (Barrow, Alaska) floyd@apaflo.com
- Next message: garth_rockett_at_yahoo.com: "Mapping error codes to error messages"
- Previous message: Fletcher Glenn: "Re: problem w/ function write(...)"
- In reply to: ferbar: "Re: problem w/ function write(...)"
- Next in thread: ferbar: "Re: problem w/ function write(...)"
- Reply: ferbar: "Re: problem w/ function write(...)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|