What is the technical term for current (.) and parent (..) directory?

I got a function that checks whether the passed in file name is . or ... But I don't know how to name it properly. Something like IsCurrentOrParentDirectory() is ambiguous, since the function takes a file name and not a full path. (Intuitively a fellow programmer would expect passing /usr/ while I'm in /usr/ would return true, while this is actually not the case.)

Is there a technical term for these directory entries? If there is one, what is it?


Solution 1:

From the POSIX standard:

The special filename dot shall refer to the directory specified by its predecessor. The special filename dot-dot shall refer to the parent directory of its predecessor directory. As a special case, in the root directory, dot-dot may refer to the root directory itself.

So, really, if you want to check whether the filename is . or .. you would have to call it IsDotOrDotDot(), or, using the POSIX terminology of pathname resolution, IsPredecessorOrParentOfPredecessor(), or maybe even PointsToPredecessorOrParentOfPrecedessor() … you get the idea. The problem is that the latter terminology only makes sense when looking at full pathnames. But nobody would understand that anyway.

Considering that . and .. are valid filenames (just interpreted differently), you should just stick to what you have, relying on the meaning rather than how they are called internally.

Solution 2:

. and .. are usually used to describe relative paths vs. absolute ones like /usr. I'd use this difference and declare the function as IsRelativeCurrentOrParentDirectory().

Be aware the dot-references may occur anywhere in the path. What about /usr/local/..?

Solution 3:

The POSIX Standard, which slhck♦ usefully quoted, says,

The special filename dot shall refer to ….  The special filename dot-dot shall refer to ….

(emphasis added).  So, while it’s not exactly technical, it looks like “special filename” just might be the official name.  Your users would probably understand it if you called your function any of the following: IsSpecialDirectory(), IsSpecialFilename(), or simply IsSpecialName().

Or you could go with IsStandardDirectory(), IsStandardFilename(), or IsStandardName().  This follows the Unix naming convention (standard input, standard output) for things that are established for you automatically (in this case, by mkfs and mkdir).  IsAutomatic…() or IsDefault…(), on the other hand, probably are not intuitive enough.