Re: write



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. ------


.



Relevant Pages

  • Re: REFERENCES REVEALED
    ... > void Repot(unsigned int* pX) ... > void Repot ... > about references, I detested them, I thought they were extremely stupid. ... Would the compiler turn my preceeding code (written ...
    (comp.lang.cpp)
  • Suggestions for refactoring unusual tables
    ... id (int, primary key) ... systext (string) ... catalog_id ... type_id (int, references catalog_entry) ...
    (comp.databases)
  • Re: Finding a constant-space algorithm
    ... Make a linked list of the forward references. ... int flip45(unsigned *arr, unsigned count); ... unsigned idx; ...
    (comp.programming)
  • [PATCH 1/3] vmscan: report vm_flags in page_referenced()
    ... eg. to protect executable file pages more aggressively. ... static inline int page_mkclean ... static int page_referenced_anon(struct page *page, ... the page we're checking references on. ...
    (Linux-Kernel)
  • [PATCH 1/3] vmscan: report vm_flags in page_referenced()
    ... eg. to protect executable file pages more aggressively. ... static inline int page_mkclean ... static int page_referenced_anon(struct page *page, ... the page we're checking references on. ...
    (Linux-Kernel)