void Sg_SetCurrentDirectory(SgString *path)
{
  if (chdir(Sg_Utf32sToUtf8s(path)) < 0) {
    Sg_IOError(io_error_type(errno), SG_INTERN("set-current-directory"),
	       Sg_GetLastErrorMessage(), SG_FALSE, SG_FALSE);
  }
}
Example #2
0
SgObject Sg_FindFile(SgString *path, SgObject loadPaths,
		     SgString *suffix, int quiet)
{
  SgObject dir;
  SgObject realPath;
  const SgObject sep = Sg_String(Sg_NativeFileSeparator());
  SG_FOR_EACH(dir, loadPaths) {
    if (suffix) {
      realPath = Sg_StringAppend(SG_LIST4(SG_CAR(dir),
					  sep,
					  path,
					  suffix));
    } else {
      realPath = Sg_StringAppend(SG_LIST3(SG_CAR(dir),
					  sep,
					  path));
    }
    if (Sg_FileExistP(SG_STRING(realPath))) {
      return realPath;
    }
  }
  if (!quiet) {
    Sg_IOError(SG_IO_FILE_NOT_EXIST_ERROR,
	       SG_INTERN("find-file"),
	       SG_MAKE_STRING("given file was not found"),
	       path, SG_FALSE);
  }
  return SG_FALSE;
}
SgObject Sg_CurrentDirectory()
{
  char buf[MAXPATHLEN];
  if (getcwd(buf, MAXPATHLEN) == NULL) {
    Sg_IOError(io_error_type(errno), SG_INTERN("current-directory"),
	       Sg_GetLastErrorMessage(), SG_FALSE, SG_FALSE);
    return SG_UNDEF;
  }
  return Sg_Utf8sToUtf32s(buf, strlen(buf));
}
static int posix_ready(SgObject self)
{
#ifdef HAVE_SELECT
  struct timeval tm = {0 , 0};
  fd_set fds;
  int state;
  FD_ZERO(&fds);
  /* what would be the best behaviour if the given FD is larger than
     FD_SETSIZE? I don't like predicates raise an error, so for now
     I only return #f. */
  /* if FD id less than 0, then it must be invalid and signaled error by now
     but just in case. (NB: I've seen bunch of stack overflow dump on 64 bit
     Linux, checking negative FD may prevent it) */
  if (SG_FD(self)->fd < 0 || SG_FD(self)->fd >= FD_SETSIZE) return FALSE;

  FD_SET(SG_FD(self)->fd, &fds);
  state = select(SG_FD(self)->fd + 1, &fds, NULL, NULL, &tm);
  if (state < 0) {
    /* in this case it's basically bad file descriptor means
       either it's closed or exceed the FD_SETSIZE. 
       However, I don't think predicate should raise an error
       so just return FALSE. */
#if 0
    SgObject err;
    if (errno == EINTR) return FALSE;
    setLastError(self);
    err = Sg_Sprintf(UC("%A [FD %d]"), get_last_error_message(self),
		     SG_FD(self)->fd);
    Sg_IOError(-1, SG_INTERN("file ready"), err, self, self);
#endif
    return FALSE;
  }
  return (state != 0);
#else
  /* default true */
  return TRUE;
#endif  
}