~ubuntu-branches/ubuntu/precise/corosync/precise-proposed

« back to all changes in this revision

Viewing changes to lcr/lcr_ifact.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2010-07-02 01:24:53 UTC
  • mfrom: (1.1.4 upstream) (5.1.9 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100702012453-qky79tg6hjly2dmq
Tags: 1.2.1-1ubuntu1
* Merge from debian unstable (LP: #600900). Remaining changes:
  - Raised consensus time out to 5000ms
  - debian/control, debian/rules: Removing now-unnecessary quilt build-dep

Show diffs side-by-side

added added

removed removed

Lines of Context:
285
285
        int (*compar)(const struct dirent **, const struct dirent **))
286
286
{
287
287
        DIR *d;
288
 
        struct dirent *entry, **names = NULL;
 
288
        struct dirent *entry;
 
289
        struct dirent *result;
 
290
        struct dirent **names = NULL;
289
291
        int namelist_items = 0, namelist_size = 0;
 
292
        size_t len;
 
293
        int return_code;
290
294
 
291
295
        d = opendir(dir);
292
296
        if (d == NULL)
293
297
                return -1;
294
298
 
295
299
        names = NULL;
296
 
        while ((entry = readdir (d)) != NULL) {
 
300
 
 
301
        len = offsetof(struct dirent, d_name) +
 
302
                     pathconf(dir, _PC_NAME_MAX) + 1;
 
303
        entry = malloc(len);
 
304
 
 
305
        for (return_code = readdir_r (d, entry, &result);
 
306
                dirent != NULL && return_code == 0;
 
307
                return_code = readdir_r(d, entry, &result)) {
 
308
 
297
309
                struct dirent *tmpentry;
298
 
                if ((filter != NULL) && ((*filter)(entry) == 0)) {
 
310
                if ((filter != NULL) && ((*filter)(result) == 0)) {
299
311
                        continue;
300
312
                }
301
313
                if (namelist_items >= namelist_size) {
312
324
                        }
313
325
                        names = tmp;
314
326
                }
315
 
                tmpentry = malloc (entry->d_reclen);
 
327
                tmpentry = malloc (result->d_reclen);
316
328
                if (tmpentry == NULL) {
317
329
                        goto fail;
318
330
                }
319
 
                (void) memcpy (tmpentry, entry, entry->d_reclen);
 
331
                (void) memcpy (tmpentry, result, result->d_reclen);
320
332
                names[namelist_items++] = tmpentry;
321
333
        }
322
334
        (void) closedir (d);
337
349
                namelist_items--;
338
350
                free (*namelist[namelist_items]);
339
351
        }
 
352
        free (entry);
340
353
        free (names);
341
354
        *namelist = NULL;
342
355
        errno = err;