/*
  Returns one path from PATH environment variable
  This function is meant to be called in a loop, where the counter starts 
  from 0. The counter variable is passed to this function as a second argument
*/

static char *get_paths(char *pathenv, unsigned int pathnum)
{
  unsigned l;
  char *ptr;
  char *retval = malloc(67*sizeof(char));

  if(!retval)
  {
    nomemory();
    return 0;
  }

  while(pathnum--)
  {
    pathenv = strchr(pathenv, ';');
    if(!pathenv)
    {
      error:free(retval);
      return 0;
    }
    pathenv++;
  }
  ptr = strchr(pathenv, ';');
  if(ptr)
    l = ptr - pathenv;
  else
    l = strlen(pathenv);
  if(l >= 67) goto error;
  memcpy(retval, pathenv, l);
  retval[l] = 0;

  return retval;
}
