opendir

Opens a directory for reading with the attributes set by calling SetReaddirAttribute and the next matching file found by calling readdir functions

Local Servers:blocking
Remote Servers:blocking
Classification:POSIX
Platform:NLM
Service:File System

Syntax

   #include <dirent.h>  
    
   DIR  * opendir  (  
      const char   *pathname);
   

Parameters

pathname

(IN) Can be either relative to the current working directory or it can be an absolute path name (must include file specification—accepts wild cards).

Return Values

Returns a pointer to the DIR structure (required for subsequent calls to the readdir function) containing the file names matching the pattern specified by the pathname parameter.

Returns NULL if the path name is not valid or if there are no files matching the path name. If an error occurs, errno and NetWareErrno are set.

Remarks

The last part of the path name can contain the characters `?’ and `*’ for matching multiple files, as in the following example:

   odir = opendir ("sys:\\public\\*.*");
   

More than one directory can be read at the same time by calling the opendir, readdir, and closedir functions.

opendir calls the malloc function to allocate memory for a DIR structure. The closedir function frees the memory.

Information about the first file or directory matching the specified path name is not placed in the DIR structure until after the first call to the readdir function.

Beginning with Release 9 of NW SDK, opendir returns long names in the d_name field of the dirent structure if the target namespace is previously set to something other than DOS by calling SetTargetNameSpace. To have use of this long name functionality, you must compile with the dirent.h file included with Release 9 or later. In addition, with NetWare versions lower than 5, you might need CLIBAUX.NLM loaded on the server for symbol resolution. (Currently opendir support for spaces other than DOS is availible only on calls to the local server.)

NOTE:The position in the structure of the d_name field prior to Release 9 has been assumed by the new d_nameDOS field to ensure backward compatibility, and the d_name field has been moved to the end of the structure. The new code puts the DOS name space name at the d_nameDOS field offset so old code will still work. This can all be done with relative ease because CLIB allocates the memory.

By default, opendir returns all file and directory names when the pattern *.* is specified for the DOS name space only (only names with one dot are returned for the long name space). To use *.* to return all names for the long name space, call UnAugmentAsterisk before calling opendir. You can also call SetCurrentNameSpace(0) to set the name space to DOS, call opendir, then call SetCurrentNameSpace(4) to reset the name space to long.

See Also

closedir, readdir, SetReaddirAttribute, UnAugmentAsterisk