26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG. atoz.c<br />

}<br />

// tell resource manager library we already did the reply<br />

return (_RESMGR_NOREPLY);<br />

static int<br />

my_read_file (resmgr_context_t *ctp, io_read_t *msg, iofunc_ocb_t *ocb)<br />

{<br />

int nbytes;<br />

int nleft;<br />

char string;<br />

// we don’t do any xtypes here...<br />

if ((msg -> i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE) {<br />

return (ENOSYS);<br />

}<br />

// figure out how many bytes are left<br />

nleft = ocb -> attr -> nbytes - ocb -> offset;<br />

// and how many we can return to the client<br />

nbytes = min (nleft, msg -> i.nbytes);<br />

if (nbytes) {<br />

// create the output string<br />

string = ocb -> attr -> inode - 1 + ’A’;<br />

// return it to the client<br />

MsgReply (ctp -> rcvid, nbytes, &string + ocb -> offset, nbytes);<br />

// update flags and offset<br />

ocb -> attr -> flags |= IOFUNC_ATTR_ATIME | IOFUNC_ATTR_DIRTY_TIME;<br />

ocb -> offset += nbytes;<br />

} else {<br />

// nothing to return, indicate End Of File<br />

MsgReply (ctp -> rcvid, EOK, NULL, 0);<br />

}<br />

}<br />

// already done the reply ourselves<br />

return (_RESMGR_NOREPLY);<br />

static int<br />

my_read (resmgr_context_t *ctp, io_read_t *msg, iofunc_ocb_t *ocb)<br />

{<br />

int sts;<br />

// use the helper function to decide if valid<br />

if ((sts = iofunc_read_verify (ctp, msg, ocb, NULL)) != EOK) {<br />

return (sts);<br />

}<br />

}<br />

// decide if we should perform the "file" or "dir" read<br />

if (S_ISDIR (ocb -> attr -> mode)) {<br />

return (my_read_dir (ctp, msg, ocb));<br />

} else if (S_ISREG (ocb -> attr -> mode)) {<br />

return (my_read_file (ctp, msg, ocb));<br />

} else {<br />

return (EBADF);<br />

}<br />

int<br />

main (int argc, char **argv)<br />

April 30, 2009 Appendix: C • Sample Programs 315

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!