Re: write
- From: Lew Pitcher <lpitcher@xxxxxxxxxxxx>
- Date: Sun, 27 Apr 2008 19:05:26 -0400
In comp.os.linux.development.system, Bill Cunningham wrote:
"Lew Pitcher" <lpitcher@xxxxxxxxxxxx> wrote in message
news:707af$4814f545$4c0a8485$12038@xxxxxxxxxxxxxxxxxxxx
To correct your program...
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main (void) {
int file;
char buf[]="hello world\n";
size_t c;
/*
c = 20000;
*/
if ((file = open("my_file",O_WRONLY | O_CREAT | O_TRUNC,0644)) != -1)
{
c = sizeof(buf);
write(file,buf,c);
close(file);
}
}
Hope this helps
At your file=open(). Doesn't open return a ssize_t ? You have file
declared as a int.
open(2) returns the integer -1 on error, and a non-negative integer on
success. This non-negative integer is the "file descriptor" for the file;
it is just a unique number that keeps references to /this/ file separate
from references to any other file, in your program.
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
.
- Follow-Ups:
- Re: write
- From: Bill Cunningham
- Re: write
- Prev by Date: Re: write
- Next by Date: Re: write
- Previous by thread: Re: write
- Next by thread: Re: write
- Index(es):
Relevant Pages
|