Beispiel #1
0
int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result)
{
	int ret;
	ssize_t bytes;
	struct dirent *de;

	if (!dir) {
	    __set_errno(EBADF);
	    return(EBADF);
	}
	de = NULL;

	__UCLIBC_MUTEX_LOCK(dir->dd_lock);

	do {
	    if (dir->dd_size <= dir->dd_nextloc) {
		/* read dir->dd_max bytes of directory entries. */
		bytes = __getdents(dir->dd_fd, dir->dd_buf, dir->dd_max);
		if (bytes <= 0) {
		    *result = NULL;
		    ret = (bytes==0)? 0 : errno;
		    goto all_done;
		}
		dir->dd_size = bytes;
		dir->dd_nextloc = 0;
	    }

	    de = (struct dirent *) (((char *) dir->dd_buf) + dir->dd_nextloc);

	    /* Am I right? H.J. */
	    dir->dd_nextloc += de->d_reclen;

	    /* We have to save the next offset here. */
	    dir->dd_nextoff = de->d_off;
	    /* Skip deleted files.  */
	} while (de->d_ino == 0);

	if (de == NULL) {
	    *result = NULL;
	} else {
	    *result = memcpy (entry, de, de->d_reclen);
	}
	ret = 0;

all_done:

	__UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
	return((de != NULL)? 0 : ret);
}
Beispiel #2
0
struct dirent *readdir(DIR *dir)
{
	struct dirent *de;
	
	if (dir->buf_pos >= dir->buf_end) {
		int len = __getdents(dir->fd, (void *)dir->buf, sizeof dir->buf);
		if (len <= 0) return 0;
		dir->buf_end = len;
		dir->buf_pos = 0;
	}
	de = (void *)(dir->buf + dir->buf_pos);
	dir->buf_pos += de->d_reclen;
	dir->tell = de->d_off;
	return de;
}
Beispiel #3
0
struct dirent *readdir(DIR * dir)
{
    ssize_t bytes;
    struct dirent *de;

    if (!dir) {
        __set_errno(EBADF);
        return NULL;
    }

#ifdef __UCLIBC_HAS_THREADS__
    __pthread_mutex_lock(&(dir->dd_lock));
#endif

    do {
        if (dir->dd_size <= dir->dd_nextloc) {
            /* read dir->dd_max bytes of directory entries. */
            bytes = __getdents(dir->dd_fd, dir->dd_buf, dir->dd_max);
            if (bytes <= 0) {
                de = NULL;
                goto all_done;
            }
            dir->dd_size = bytes;
            dir->dd_nextloc = 0;
        }

        de = (struct dirent *) (((char *) dir->dd_buf) + dir->dd_nextloc);

        /* Am I right? H.J. */
        dir->dd_nextloc += de->d_reclen;

        /* We have to save the next offset here. */
        dir->dd_nextoff = de->d_off;

        /* Skip deleted files.  */
    } while (de->d_ino == 0);

all_done:
#ifdef __UCLIBC_HAS_THREADS__
    __pthread_mutex_unlock(&(dir->dd_lock));
#endif
    return de;
}
Beispiel #4
0
/* Export getdents().  Not an internal_function.  */
ssize_t
getdents (int fd, char *buf, size_t nbytes)
{
  return __getdents (fd, buf, nbytes);
}
Beispiel #5
0
static hp_timing_t
__get_clockfreq_via_proc_openprom (void)
{
  hp_timing_t result;
  int obp_fd;

  result = 0;

  obp_fd = __open ("/proc/openprom", O_RDONLY);
  if (obp_fd != -1)
    {
      unsigned long int buf[4096 / sizeof (unsigned long int)];
      struct dirent *dirp = (struct dirent *) buf;
      ssize_t len;

      while ((len = __getdents (obp_fd, (char *) dirp, sizeof (buf))) > 0)
	{
	  struct dirent *this_dirp = dirp;

	  while (len > 0)
	    {
	      char node[strlen ("/proc/openprom/")
			+ _D_ALLOC_NAMLEN (this_dirp)
			+ strlen ("/clock-frequency")];
	      char *prop;
	      int fd;

	      /* Note that
		   strlen("/clock-frequency") > strlen("/device_type")
	      */
	      __stpcpy (prop = __stpcpy (__stpcpy (node, "/proc/openprom/"),
					 this_dirp->d_name),
			"/device_type");
	      fd = __open (node, O_RDONLY);
	      if (fd != -1)
		{
		  char type_string[128];
		  int ret;

		  ret = __read (fd, type_string, sizeof (type_string));
		  if (ret > 0 && strncmp (type_string, "'cpu'", 5) == 0)
		    {
		      int clkfreq_fd;

		      __stpcpy (prop, "/clock-frequency");
		      clkfreq_fd = __open (node, O_RDONLY);
		      if (clkfreq_fd != -1)
			{
			  if (__read (clkfreq_fd, type_string,
				      sizeof (type_string)) > 0)
			    result = (hp_timing_t)
			      strtoumax (type_string, NULL, 16);
			  __close (clkfreq_fd);
			}
		    }
		  __close (fd);
		}

	      if (result != 0)
		break;

	      len -= this_dirp->d_reclen;
	      this_dirp = (struct dirent *)
		((char *) this_dirp + this_dirp->d_reclen);
	    }
	  if (result != 0)
	    break;
	}
      __close (obp_fd);
    }

  return result;
}