I'm having some trouble w/ the write() function and open() function.
here we go
BTW -> fd = file descriptor
Code:
int n_open_write(const char *pathname,unsigned int buffsize)
{
int fd;
fd = open(pathname,O_WRONLY);
if(fd == -1)
{
n_close(fd);
fd = open(pathname,O_CREAT);
}
return fd;
}
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.
Code:
int n_putc(int c, int fd)
{
int status;
unsigned char *mychar;
*mychar = (unsigned char)c;
status = write(fd,mychar,1);
if(status == -1)
return -1;
else
return 1;
}
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*.
thanks ahead of time to anyone who posts.