summaryrefslogblamecommitdiff
path: root/src/dirent/readdir_r.c
blob: daa6c6ed608449051ae46fcf800fa521dbc24fa1 (plain) (tree)
1
2
3
4
5
6
7

                   



                     
                                                                                              




                               
                        


                            
                                  





                                              
                          




                                
#include <dirent.h>
#include <errno.h>
#include <string.h>
#include "__dirent.h"
#include "libc.h"

int readdir_r(DIR *restrict dir, struct dirent *restrict buf, struct dirent **restrict result)
{
	struct dirent *de;
	int errno_save = errno;
	int ret;
	
	LOCK(dir->lock);
	errno = 0;
	de = readdir(dir);
	if ((ret = errno)) {
		UNLOCK(dir->lock);
		return ret;
	}
	errno = errno_save;
	if (de) memcpy(buf, de, de->d_reclen);
	else buf = NULL;

	UNLOCK(dir->lock);
	*result = buf;
	return 0;
}

LFS64_2(readdir_r, readdir64_r);