Esempio n. 1
0
/*! \details Reads the next directory entry in the open directory (reentrant version).
 *
 * \return a pointer to a dirent or NULL with errno (see \ref errno) set to:
 * - EBADF: \a dirp is invalid
 * - ENOENT: the current position of the directory stream is invalid
 *
 */
int readdir_r(DIR * dirp /*! a pointer to the directory structure */,
				  struct dirent * entry /*! a pointer to the destination memory */,
				  struct dirent ** result /*! this value is assigned to \a entry on success and NULL on failure */){
	int err;
	const sysfs_t * fs;
	if (check_ebadf(dirp) < 0 ){
		if ( result ){
			*result = NULL;
		}
		return -1;
	}

	fs = dirp->fs;
	err = fs->readdir_r(fs->config, dirp->handle, dirp->loc, entry);
	if ( err < 0 ){
		//errno is set by fs->readdir_r
		SYSFS_PROCESS_RETURN(err);
		if ( result ){
			*result = NULL;
		}
		return err;
	}

	dirp->loc++;
	cortexm_assign_zero_sum32(dirp, sizeof(DIR)/sizeof(u32));

	if ( result ){
		*result = entry;
	}
	return 0;
}
Esempio n. 2
0
/*! \details This function closes the directory stream specified by \a dirp.
 *
 * \return Zero or -1 with errno (see \ref ERRNO) set to:
 * - EINVAL: \a dirp does not refere to an open directory stream
 *
 */
int closedir(DIR * dirp /*! A pointer to the open directory */){
	if (check_ebadf(dirp) < 0 ){
		return -1;
	}
	free(dirp);
	return 0;
}
Esempio n. 3
0
/*! \details This function reads the next directory entry in the open directory (reentrant version).
 *
 * \return a pointer to a dirent or NULL with errno (see \ref ERRNO) set to:
 * - EBADF: \a dirp is invalid
 * - ENOENT: the current position of the directory stream is invalid
 *
 */
int readdir_r(DIR * dirp /*! a pointer to the directory structure */,
		struct dirent * entry /*! a pointer to the destination memory */,
		struct dirent ** result /*! this value is assigned to \a entry on success and NULL on failure */){
	int err;
	const sysfs_t * fs;
	if (check_ebadf(dirp) < 0 ){
		if ( result ){
			*result = NULL;
		}
		return -1;
	}

	fs = dirp->fs;
	err = fs->readdir_r(fs->cfg, dirp->handle, dirp->loc, entry);
	if ( err < 0 ){
		//errno is set by fs->readdir_r
		if ( result ){
			*result = NULL;
		}
		return -1;
	}

	dirp->loc++;

	if ( result ){
		*result = entry;
	}
	return 0;
}
Esempio n. 4
0
/*! \details Closes the directory stream specified by \a dirp.
 *
 * \return Zero or -1 with errno (see \ref errno) set to:
 * - EINVAL: \a dirp does not refere to an open directory stream
 *
 */
int closedir(DIR * dirp /*! A pointer to the open directory */){
	int ret;
	const sysfs_t * fs;

	if (check_ebadf(dirp) < 0 ){ return -1; }
	fs = dirp->fs;
	ret = fs->closedir(fs->config, &(dirp->handle));
	SYSFS_PROCESS_RETURN(ret);

	free(dirp);
	return ret;
}
Esempio n. 5
0
/*! \details Gets the current location in the directory.
 *
 * \return The current directory location
 */
long telldir(DIR * dirp /*! a pointer to the directory structure */){
	if( check_ebadf(dirp) < 0 ){ return SYSFS_RETURN_EOF; }
	return dirp->loc;
}
Esempio n. 6
0
/*! \details Seeks to the specified location in
 * the directory.
 *
 */
void seekdir(DIR * dirp /*! a pointer to the directory structure */,
				 long loc /*! the target location */){
	if( check_ebadf(dirp) < 0 ){ return; }
	dirp->loc = loc;
	cortexm_assign_zero_sum32(dirp, sizeof(DIR)/sizeof(u32));
}
Esempio n. 7
0
/*! \details Rewinds \a dirp.
 *
 */
void rewinddir(DIR * dirp /*! a pointer to the directory structure */){
	if( check_ebadf(dirp) < 0 ){ return; }
	dirp->loc = 0;
	cortexm_assign_zero_sum32(dirp, sizeof(DIR)/sizeof(u32));
}