~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/cached_directory.cc

  • Committer: Brian Aker
  • Date: 2009-08-15 00:59:30 UTC
  • mfrom: (1115.1.7 merge)
  • Revision ID: brian@gaz-20090815005930-q47yenjrq1esiwsz
Merge of Trond + Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
 
51
51
bool CachedDirectory::open(const string &in_path)
52
52
{
53
 
  size_t size;
54
 
  DIR *dirp;
 
53
  DIR *dirp= opendir(in_path.c_str());
55
54
 
56
 
  if ((dirp= opendir(in_path.c_str())) == NULL)
 
55
  if (dirp == NULL)
57
56
  {
58
57
    error= errno;
59
58
    return false;
60
59
  }
61
60
 
62
 
  /*
63
 
   * The readdir_r() call on Solaris operates a bit differently from other
64
 
   * systems in that the dirent structure must be allocated along with enough
65
 
   * space to contain the filename (see man page for readdir_r on Solaris).
66
 
   */
67
 
 
68
 
#ifdef SOLARIS
69
 
  size= sizeof(dirent) + pathconf(in_path.c_str(), _PC_NAME_MAX);
70
 
#else
71
 
  size= sizeof(dirent);
 
61
  union {
 
62
    dirent entry;
 
63
#ifdef __sun
 
64
    /*
 
65
     * The readdir_r() call on Solaris operates a bit differently from other
 
66
     * systems in that the dirent structure must be allocated along with enough
 
67
     * space to contain the filename (see man page for readdir_r on Solaris).
 
68
     * Instead of dynamically try to allocate this buffer, just set the max
 
69
     * name for a path instead.
 
70
     */
 
71
    char space[sizeof(dirent) + PATH_MAX + 1];
72
72
#endif
73
 
 
74
 
  dirent *entry= (dirent *) malloc(size);
75
 
 
76
 
  if (entry == NULL)
77
 
  {
78
 
    error= errno;
79
 
    closedir(dirp);
80
 
    return false;
81
 
  }
 
73
  } buffer;
82
74
 
83
75
  int retcode;
84
76
  dirent *result;
85
77
 
86
 
  retcode= readdir_r(dirp, entry, &result);
87
 
  while ((retcode == 0) && (result != NULL))
88
 
  {
89
 
    entries.push_back(new Entry(entry->d_name));
90
 
    retcode= readdir_r(dirp, entry, &result);
91
 
  }
 
78
  while ((retcode= readdir_r(dirp, &buffer.entry, &result)) == 0 &&
 
79
         result != NULL)
 
80
    entries.push_back(new Entry(result->d_name));
92
81
    
93
82
  closedir(dirp);
94
 
  free(entry);
95
 
 
96
83
  error= retcode;
97
84
 
98
85
  return error == 0;