c - File IO in the apache portable runtime library -


while working through zed shaw's learn c hard way, encountered function apr_dir_make_recursive() according the documentation here has type signature

apr_status_t apr_dir_make_recursive(const char *path, apr_fileperms_t perm, apr_pool_t *pool)

which makes directory, identical unix command mkdir -p.

why io function need memory pool in order operate?

my first thought was perhaps optional argument populate newly made directory, code below uses initialized presumptively empty memory pool. mean io function needs memory pool, passing in use? doesn't seem either; couldn't function create local memory pool use destroyed upon return or error?

so, use memory pool? documentation linked unhelpful on point.

code shortened , shown below, curious.

int db_init() {      apr_pool_t *p = null;      apr_pool_initialize();      apr_pool_create(&p, null);       if(access(db_dir, w_ok | x_ok) == -1) {           apr_status_t rc = apr_dir_make_recursive(db_dir,                apr_uread | apr_uwrite | apr_uexecute |                apr_gread | apr_gwrite | apr_gexecute, p);      }       if(access(db_file, w_ok) == -1) {           file *db = db_open(db_file, "w");           check(db, "cannot open database: %s", db_file);           db_close(db);      }       apr_pool_destroy(p);      return 0;  } 

the implementation of function (found here) shows pool used allocate strings representing individual components of path.

the reason function not create own local pool because pool may reused across multiple calls apr_*() functions. happens db_init() not have need reuse apr_pool_t.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -