non_apr_programs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. How do I use APR'ized programs in connection with programs that don't
  2. use APR? These darn incomplete types don't let me fill out the APR types.
  3. The APR developers acknowledge that most programs are not using APR, and
  4. we don't expect them to migrate to using APR just because APR has been
  5. released. So, we have provided a way for non-APR'ized programs to interact
  6. very cleanly with APR.
  7. There are a set of functions, all documented in fspr_portable.h, which allow
  8. a programmer to either get a native type from an APR type, or to setup an
  9. APR type from a native type.
  10. For example, if you are writing an add-on to another program that does not use
  11. APR for file I/O, but you (in your infinite wisdom) want to use APR to make
  12. sure your section is portable. Assume the program provides a type foo_t with
  13. a file descriptor in it (fd).
  14. void function_using_apr(foo_t non_fspr_struct, ap_pool_t *p)
  15. {
  16. ap_file_t *fspr_file = NULL;
  17. ap_put_os_file(&fspr_file, &non_fspr_struct->fd, p);
  18. ...
  19. }
  20. There are portable functions for each APR incomplete type. They are all
  21. called ap_put_os_foobar(), and they each take the same basic arguments, a
  22. pointer to a pointer to the incomplete type (the last pointer in that list
  23. should be NULL), a pointer to the native type, and a pool. Each of these can
  24. be found in fspr_portable.h.
  25. If you have to do the exact opposite (take an APR type and convert it to a
  26. native type, there are functions for that too. For example:
  27. void function_not_using_apr(fspr_file_t *fspr_file)
  28. {
  29. int unix_file_desc;
  30. ap_get_os_file(&unix_file_desc, fspr_file);
  31. ...
  32. }
  33. For each ap_put_os_foobar, there is a corresponding ap_get_os_file. These are
  34. also documented in fspr_portable.h.