Mercurial > dwindows
comparison dwcompat.c @ 1609:e4a641036581
Last commit didn't help, seems getmntinfo() isn't thread safe on Mac or FreeBSD...
So created a _getmntinfo_r() function protected by a mutex.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 03 Mar 2012 06:15:22 +0000 |
parents | ff844a41193b |
children | f8d1da63fb77 |
comparison
equal
deleted
inserted
replaced
1608:ff844a41193b | 1609:e4a641036581 |
---|---|
72 va_end(args); | 72 va_end(args); |
73 | 73 |
74 return buf; | 74 return buf; |
75 } | 75 } |
76 | 76 |
77 /* Get around getmntinfo() not being thread safe */ | |
78 #if defined(__FreeBSD__) || defined(__MAC__) | |
79 int _getmntinfo_r(struct statfs **mntbufp, int flags) | |
80 { | |
81 static HMTX mutex = 0; | |
82 int result; | |
83 | |
84 if(!mutex) | |
85 mutex = dw_mutex_new(); | |
86 | |
87 dw_mutex_lock(mutex); | |
88 result = getmntinfo(mntbufp, flags); | |
89 dw_mutex_unlock(mutex); | |
90 return result; | |
91 } | |
92 #endif | |
93 | |
77 long double API drivefree(int drive) | 94 long double API drivefree(int drive) |
78 { | 95 { |
79 #if defined(__EMX__) || defined(__OS2__) | 96 #if defined(__EMX__) || defined(__OS2__) |
80 ULONG aulFSInfoBuf[40] = {0}; | 97 ULONG aulFSInfoBuf[40] = {0}; |
81 APIRET rc = NO_ERROR; | 98 APIRET rc = NO_ERROR; |
103 return (long double)((double)spc*(double)bps*(double)fc); | 120 return (long double)((double)spc*(double)bps*(double)fc); |
104 #elif defined(__FreeBSD__) || defined(__MAC__) | 121 #elif defined(__FreeBSD__) || defined(__MAC__) |
105 struct statfs *fsp = NULL; | 122 struct statfs *fsp = NULL; |
106 int entries, index = 1; | 123 int entries, index = 1; |
107 | 124 |
108 entries = getmntinfo (&fsp, MNT_NOWAIT); | 125 entries = _getmntinfo_r(&fsp, MNT_NOWAIT); |
109 | 126 |
110 for (; entries-- > 0; fsp++) | 127 for (; entries-- > 0; fsp++) |
111 { | 128 { |
112 if(index == drive) | 129 if(index == drive) |
113 return (long double)((double)fsp->f_bsize * (double)fsp->f_bavail); | 130 return (long double)((double)fsp->f_bsize * (double)fsp->f_bavail); |
205 return (long double)((double)spc*(double)bps*(double)tc); | 222 return (long double)((double)spc*(double)bps*(double)tc); |
206 #elif defined(__FreeBSD__) || defined(__MAC__) | 223 #elif defined(__FreeBSD__) || defined(__MAC__) |
207 struct statfs *fsp = NULL; | 224 struct statfs *fsp = NULL; |
208 int entries, index = 1; | 225 int entries, index = 1; |
209 | 226 |
210 entries = getmntinfo (&fsp, MNT_NOWAIT); | 227 entries = _getmntinfo_r(&fsp, MNT_NOWAIT); |
211 | 228 |
212 for (; entries-- > 0; fsp++) | 229 for (; entries-- > 0; fsp++) |
213 { | 230 { |
214 if(index == drive) | 231 if(index == drive) |
215 return (long double)((double)fsp->f_bsize * (double)fsp->f_blocks); | 232 return (long double)((double)fsp->f_bsize * (double)fsp->f_blocks); |
304 return 1; | 321 return 1; |
305 #elif defined(__FreeBSD__) || defined(__MAC__) | 322 #elif defined(__FreeBSD__) || defined(__MAC__) |
306 struct statfs *fsp = NULL; | 323 struct statfs *fsp = NULL; |
307 int entries, index = 1; | 324 int entries, index = 1; |
308 | 325 |
309 entries = getmntinfo (&fsp, MNT_NOWAIT); | 326 entries = _getmntinfo_r(&fsp, MNT_NOWAIT); |
310 | 327 |
311 for (; entries-- > 0; fsp++) | 328 for (; entries-- > 0; fsp++) |
312 { | 329 { |
313 if(index == drive && fsp->f_blocks) | 330 if(index == drive && fsp->f_blocks) |
314 return 1; | 331 return 1; |
377 struct statfs *fsp = NULL; | 394 struct statfs *fsp = NULL; |
378 int entries, index = 1; | 395 int entries, index = 1; |
379 | 396 |
380 strncpy(buf, "Unknown", len); | 397 strncpy(buf, "Unknown", len); |
381 | 398 |
382 entries = getmntinfo (&fsp, MNT_NOWAIT); | 399 entries = _getmntinfo_r(&fsp, MNT_NOWAIT); |
383 | 400 |
384 for (; entries-- > 0; fsp++) | 401 for (; entries-- > 0; fsp++) |
385 { | 402 { |
386 if(index == drive) | 403 if(index == drive) |
387 strncpy(buf, fsp->f_mntonname, len); | 404 strncpy(buf, fsp->f_mntonname, len); |