All pastes #421778 Raw Edit

Mine

public text v1 · immutable
·published 2007-04-03 01:32 UTC
rendered paste body
void addDir(queue<dirent_t> *q, char *searchPath, int recursive = 0) {
  DIR *searchDir = NULL;
  dirent_t *tmpDirent;

  if ((searchDir = opendir(searchPath)) == NULL) {
    switch (errno) {
      case EACCES:
        printf(" Access denied to \"%s\"!\n");
        break;
      case ENOENT:
        printf(" \"%s\" doesn't exist!\n");
        break;
      default:
        printf(" Couldn't open \"%s\"!\n");
    }
    return;
  }
#if 0
  if ((tmpDirent = (dirent_t *)malloc(sizeof(dirent_t))) == NULL) {
    printf(" Failed allocation of tmpDirent");
    exit(0);
  }
#endif
  while ((tmpDirent = readdir(searchDir)) != NULL) {
    if (strncmp(tmpDirent->d_name, ".", 1) == 0) {
      continue;
    } else if (isJPEG(tmpDirent->d_name)) {
      q->push(*tmpDirent);
      continue;
    } else if (recursive /*&& (tmpDirent->d_type == DT_DIR)*/) {
      printf("Recursing into %s\n", tmpDirent->d_name);
      addDir(q, tmpDirent->d_name, recursive);
      continue;
    }
  }
}