gtpc2m60 | C/C++ Language Support User's Guide |
This function removes a directory.
TPF deviation from POSIX |
---|
The TPF system does not support the ctime (change time) time stamp. |
Format
#include <unistd.h> int rmdir(const char *pathname);
This function removes a directory, pathname, provided that the directory is empty. pathname must not end in dot (.) or dot-dot (..).
The rmdir function does not remove a directory that still contains files or subdirectories.
If pathname refers to a symbolic link, the rmdir function fails and sets errno to ENOTDIR.
If no process currently has the directory open, the rmdir function deletes the directory itself. The space occupied by the directory is freed for new use. If one or more processes have the directory open when it is removed, the directory remains accessible to those processes. New files cannot be created under a directory after the last link is removed even if the directory is still open.
The rmdir function removes the directory even if it is the working directory of a process.
If a rmdir function is successful, the modification time for the parent directory is updated.
Normal Return
If successful, the rmdir function returns a value of 0.
Error Return
If unsuccessful, the rmdir function returns a value of -1 and sets errno to one of the following:
Programming Considerations
The TPF system does not support creating, updating, or deleting files in 1052 or UTIL state. Special files may or may not be writable in 1052 or UTIL state depending on the device driver implementation.
Because the rmdir function requires an update to a directory file and the deletion of a second directory file, directories cannot be removed in 1052 or UTIL state.
Examples
The following example removes a directory.
#include <fcntl.h> #include <sys/stat.h> #include <sys/stat.h> #include <unistd.h> #include <stdio.h> main() { char new_dir[]="new.dir"; char new_file[]="new.dir/new.file"; int fd; if (mkdir(new_dir, S_IRWXU|S_IRGRP|S_IXGRP) != 0) perror("mkdir() error"); else if ((fd = creat(new_file, S_IWUSR)) < 0) perror("creat() error"); else { close(fd); unlink(new_file); } if (rmdir(new_dir) != 0) perror("rmdir() error"); else puts("removed!"); }
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.