home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / sys / runtime / basic_directory.c < prev    next >
C/C++ Source or Header  |  1999-06-05  |  2KB  |  86 lines

  1. /*
  2. -- This file is  free  software, which  comes  along  with  SmallEiffel. This
  3. -- software  is  distributed  in the hope that it will be useful, but WITHOUT 
  4. -- ANY  WARRANTY;  without  even  the  implied warranty of MERCHANTABILITY or
  5. -- FITNESS  FOR A PARTICULAR PURPOSE. You can modify it as you want, provided
  6. -- this header is kept unaltered, and a notification of the changes is added.
  7. -- You  are  allowed  to  redistribute  it and sell it, alone or as a part of 
  8. -- another product.
  9. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  10. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  11. --                       http://www.loria.fr/SmallEiffel
  12. --
  13. */
  14. /*
  15.   This file (basic_directory.c) is automatically included when some external
  16.   "SmallEiffel" feature of class BASIC_DIRECTORY is live.
  17. */
  18.  
  19. /*
  20.   The current active entry while scanning a directory :
  21. */
  22. static struct dirent* se_dir_entry = NULL;
  23.  
  24. void* se_dir_open(void* path) {
  25.   /* Try to open directory `path'. */
  26.   DIR* dirstream = opendir(((char*) path));
  27.  
  28.   if (dirstream != NULL) {
  29.     se_dir_entry = readdir((DIR*) dirstream);
  30.   }
  31.   else {
  32.     se_dir_entry = NULL;
  33.   }
  34.   return ((void*) dirstream);
  35. }
  36.  
  37. void* se_dir_name(void* dirstream) {
  38.   /* Return the name of the current entry. */
  39.   char* entry;
  40.  
  41.   if (se_dir_entry != NULL) {
  42.     entry = se_dir_entry->d_name;
  43.     return entry;
  44.   }
  45.   else {
  46.     return NULL;
  47.   }
  48. }
  49.  
  50. void* se_dir_next(void* dirstream_pointer) {
  51.   /* Try to read the next entry. */
  52.   DIR* dirstream = dirstream_pointer;
  53.  
  54.   if (se_dir_entry != NULL) {
  55.     se_dir_entry = readdir(dirstream);
  56.     if (se_dir_entry == NULL) {
  57.       closedir(dirstream);
  58.       return NULL;
  59.     }
  60.     else {
  61.       return dirstream;
  62.     }
  63.   }
  64.   else {
  65.     return NULL;
  66.   }
  67. }
  68.  
  69. void* se_dir_gcwd(int unused) {
  70.   static char* buf = NULL;
  71.   static size_t size = 0;
  72.   if (buf == NULL) {
  73.     size = 256;
  74.     buf = (char*)malloc(size);
  75.   }
  76.   if (getcwd(buf,size) != NULL) {
  77.     return buf;
  78.   }
  79.   else {
  80.     free(buf);
  81.     size = size * 2;
  82.     buf = (char*)malloc(size);
  83.     return se_dir_gcwd(0);
  84.   }
  85. }
  86.