Exemplo n.º 1
0
dirq_t dirq_new (const char *path)
{
  dirq_t dirq;
  int offset;
  struct timespec ts;

  if (strlen(path) > 2048)
    die("path too long: %s", path);
  dirq = (dirq_t)safe_malloc(sizeof(struct dirq_s));
  clock_setup(dirq);
  dirq_now(dirq, &ts);
  dirq->allocated = 8192;
  dirq->buffer = (char *)safe_malloc(dirq->allocated);
  /* set path */
  strcpy(dirq->buffer, path);
  dirq->pathlen = strlen(path);
  while (dirq->pathlen > 1 && dirq->buffer[dirq->pathlen - 1] == '/') {
    dirq->pathlen--;
    dirq->buffer[dirq->pathlen] = '\0';
  }
  /* set tmp1 */
  offset = dirq->pathlen + 1 /* NULL */ + 3 /* align */;
  offset -= offset % 4;
  dirq->tmp1_offset = offset;
  strcpy(TMP1BUF(dirq), dirq->buffer);
  dirq->buffer[dirq->tmp1_offset + dirq->pathlen] = '/';
  /* set tmp2 */
  offset = dirq->pathlen + 1 /* slash */ + 8 /* dir */ + 1 /* slash */ +
    14 /* elt */ + 4 /* suffix */ + 1 /* NULL */ + 3 /* align */;
  offset -= offset % 4;
  dirq->tmp2_offset = dirq->tmp1_offset + offset;
  strcpy(TMP2BUF(dirq), dirq->buffer);
  dirq->buffer[dirq->tmp2_offset + dirq->pathlen] = '/';
  /* reset iterator */
  dirq->dirs_offset = dirq->tmp2_offset + offset;
  dirq->elts_offset = 0;
  iter_reset(dirq);
  /* set defaults */
  dirq->granularity = 60;
  dirq->rndhex = ts.tv_nsec % 16;
  dirq->umask = 0;
  dirq->maxlock = 600;
  dirq->maxtemp = 300;
  dirq->errcode = 0;
  /* make sure toplevel directory exists (up to caller to check for success!) */
  /* this is dirty but the only way to pass back the error message... */
  (void) ensure_directory_recursively(dirq, dirq->buffer);
  return(dirq);
}
Exemplo n.º 2
0
Iterator* perm_fetch_iter(Permutation* perm){
   if(!perm) return 0;
   iter_reset(perm->iter); 
   perm->fetched = 1;
   return perm->iter;
}