help w/ write() function and open() function
I'm having some trouble w/ the write() function and open() function.
here we go
BTW -> fd = file descriptor
int n_open_write(const char *pathname,unsigned int buffsize)
fd = open(pathname,O_WRONLY);
if(fd == -1)
fd = open(pathname,O_CREAT);
w/ this function my question is....if fd does equal -1, will i have to close that fd(like i'm doing above) to reopen fd w/ O_CREAT.
and secondly....when i implement this it tells me that my file that i've created is not readable, which i'm guessin is because i'm not passing in a 3rd argument to open when i use O_CREAT, so what would i pass into it if i wanted to creat a file w/ write permissions.
and here is my last question.
when i use this, i seg fault obviously. my question is.....what type does mychar have to be, I've got conflicting man pages telling me that it takes a const void* and another that says it just takes a char*.
int n_putc(int c, int fd)
unsigned char *mychar;
*mychar = (unsigned char)c;
status = write(fd,mychar,1);
if(status == -1)
thanks ahead of time to anyone who posts. :D