dirent.cc

来自「早期freebsd实现」· CC 代码 · 共 108 行

CC
108 行
字号
/* Define a portable UNIX directory-entry manipulation interface.    This code is heavily based upon Doug Gwyn's public domain directory-access   routines written in C.  Hacked into C++ conformance for the GNU libg++   library by Douglas C. Schmidt (schmidt@ics.uci.edu). */#include <std.h>#include "Dirent.h"// error handlersvoid verbose_Dirent_error_handler(const char* msg){  perror(msg);  errno = 0;}void quiet_Dirent_error_handler(const char*){  errno = 0;}void fatal_Dirent_error_handler(const char* msg){  perror(msg);  exit(1);}one_arg_error_handler_t Dirent_error_handler = verbose_Dirent_error_handler;one_arg_error_handler_t set_Dirent_error_handler(one_arg_error_handler_t f){  one_arg_error_handler_t old = Dirent_error_handler;  Dirent_error_handler = f;  return old;}#ifndef __OPTIMIZE__/* Initialize the directory-entry control block from the given DIRNAME.   Equivalent to opendir (). */Dirent::Dirent (char *dirname) {  if ((dirp = ::opendir (dirname)) == 0)    (*Dirent_error_handler) ("Dirent::Dirent");}/* Frees up the dynamically allocated buffer. */Dirent::~Dirent (void){  ::closedir (dirp);}/* Re-initialize the directory-entry control block from the given DIRNAME.   Equivalent to opendir (). */voidDirent::opendir (char *dirname) {  if ((dirp = ::opendir (dirname)) == 0)    (*Dirent_error_handler) ("Dirent::Dirent");}/* Read next entry from a directory stream. */struct dirent *Dirent::readdir (void){  return ::readdir (dirp);}/* Close a directory stream. */voidDirent::closedir (void){  ::closedir (dirp);}/* Rewind a directory stream. */voidDirent::rewinddir (void){  ::seekdir (dirp, long (0));}/* Reposition a directory stream. */voidDirent::seekdir (long loc){  ::seekdir (dirp, loc);}/* Report directory stream position. */longDirent::telldir (void){  return ::telldir (dirp);}#endif // __OPTIMIZE__

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?