O'Reilly logo

Writing Apache Modules with Perl and C by Lincoln Stein, Doug MacEachern

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.4. File and Directory Management

Apache provides routines for opening files, reading and writing to them, and closing them. Some of these routines are wrappers around the standard operating system calls in order to provide a compatibility layer for the Unix, Win32, and other ports. Other functions are an improvement over their operating system equivalents because they take advantage of Apache's memory management system.

11.4.1. Pathname Manipulation

These routines are handy for parsing strings that contain filenames and paths. See the next section, Section 11.4.2," for functions that operate on files and directories themselves.

These functions are all declared in httpd.h:

void ap_chdir_ file (const char *file)

Given a pathname in file, this peculiar little function identifies the directory part and invokes chdir() to make it the current working directory. Here's an example of calling the function on the request record's filename field in order to chdir() to the directory that contains the requested file:

ap_chdir_file(r->filename);

int ap_os_is_path_absolute (const char *filename)

This function provides a portable test as to whether a filename is absolute or not. On Unix systems, an absolute filename begins with a /, whereas under Win32 systems, an absolute filename may begin with a drive letter, a colon delimiter, and a / or \.

if(!ap_os_is_path_absolute(filename)) {
   ... must resolve the relative filename somehow ...

char *ap_make_ full_path (pool *p, const char *directory, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required