Advertisement
Guest User

Untitled

a guest
Jul 17th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <apr.h>
  2. #include <apr_general.h>
  3. #include <apr_pools.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <apr_strings.h>
  7. #include <apr_time.h>
  8.  
  9. /* Compile this beast with
  10. * $> export APR_LIBS="`apr-1-config --cflags --cppflags --includes --ldflags --link-ld --libs`"
  11. * $> gcc simple_apr.c -o simple_apr $APR_LIBS
  12. */
  13. typedef struct user
  14. {
  15. apr_time_t *creationDate;
  16. char *username;
  17. char *password;
  18. } user;
  19.  
  20. int main(int argc, char **argv)
  21. {
  22.  
  23. apr_pool_t *pool = NULL;
  24. user *user = NULL;
  25. char *time = NULL;
  26.  
  27. /* Initialize APR at the program start */
  28. apr_initialize();
  29.  
  30. /* atexit(apr_terminate()); gives
  31. * error: invalid use of void expression
  32. */
  33. atexit(apr_terminate);
  34.  
  35. /* create a managed memory pool with APR */
  36. apr_pool_create(&pool, NULL);
  37.  
  38. /* Init the struct */
  39. user = apr_palloc(pool, sizeof(struct user));
  40.  
  41. /* Assign strings via the pool */
  42. user->username = apr_pstrdup(pool, "Jens Frey");
  43. user->password = apr_pstrdup(pool, "secret");
  44.  
  45. /* Assign binary mem */
  46. apr_time_t now = apr_time_now();
  47. user->creationDate = apr_pmemdup(pool, &now, sizeof(apr_time_t));
  48.  
  49. printf("Username: %s\n", user->username);
  50. printf("Password: %s\n", user->password);
  51. printf("Time: %" APR_TIME_T_FMT "\n", *user->creationDate);
  52.  
  53. time = apr_palloc(pool, APR_RFC822_DATE_LEN);
  54. apr_rfc822_date(time, *user->creationDate);
  55. printf("Time readable: %s\n", time);
  56.  
  57. apr_pool_destroy(pool);
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement