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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

This appendix contains the complete versions of some of the sample programs<br />

discussed in this book:<br />

• atoz.c<br />

• time1.c<br />

• tp1.c<br />

• tt1.c<br />

atoz.c<br />

For more information about this program, see the example in the “Returning directory<br />

entries” section of the Resource Managers chapter.<br />

/*<br />

* atoz.c<br />

*<br />

* /dev/atoz using the resource manager library<br />

*/<br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#define ALIGN(x) (((x) + 3) & ˜3)<br />

#define NUM_ENTS 26<br />

static iofunc_attr_t atoz_attrs [NUM_ENTS];<br />

static int<br />

my_open (resmgr_context_t *ctp, io_open_t *msg, iofunc_attr_t *attr, void *extra)<br />

{<br />

if (msg -> connect.path [0] == 0)<br />

{ // the directory (/dev/atoz)<br />

return (iofunc_open_default (ctp, msg, attr, extra));<br />

} else if (msg -> connect.path [1] == 0 &&<br />

(msg -> connect.path [0] >= ’a’ &&<br />

msg -> connect.path [0] connect.path [0] - ’a’, extra));<br />

} else {<br />

return (ENOENT);<br />

}<br />

}<br />

int<br />

dirent_size (char *fname)<br />

{<br />

return (ALIGN (sizeof (struct dirent) - 4 + strlen (fname)));<br />

}<br />

struct dirent *<br />

April 30, 2009 Appendix: C • Sample Programs 313

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

Saved successfully!

Ooh no, something went wrong!