Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dirent.c « support - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4be44d8a1de7807442ce00d2487817e3760019ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * <dirent.h> wrapper functions.
 *
 * Authors:
 *   Jonathan Pryor (jonpryor@vt.edu)
 *
 * Copyright (C) 2004 Jonathan Pryor
 */

#include <dirent.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>

#include "mph.h"

G_BEGIN_DECLS

struct Mono_Posix_Syscall__Dirent {
	/* ino_t  */ mph_ino_t      d_ino;
	/* off_t  */ mph_off_t      d_off;
	/* ushort */ unsigned short d_reclen;
	/* byte   */ unsigned char  d_type;
	/* string */ char          *d_name;
};

gint32
Mono_Posix_Syscall_seekdir (DIR *dir, mph_off_t offset)
{
	mph_return_if_off_t_overflow (offset);

	errno = 0;

	seekdir (dir, (off_t) offset);

	return errno != 0;
}

mph_off_t
Mono_Posix_Syscall_telldir (DIR *dir)
{
	return telldir (dir);
}

static void
copy_dirent (struct Mono_Posix_Syscall__Dirent *to, struct dirent *from)
{
	to->d_ino    = from->d_ino;
#ifdef MPH_ON_BSD
	to->d_off    = 0;
#else
	to->d_off    = from->d_off;
#endif
	to->d_reclen = from->d_reclen;
	to->d_type   = from->d_type;
	to->d_name   = strdup (from->d_name);
}

gint32
Mono_Posix_Syscall_readdir (DIR *dirp, struct Mono_Posix_Syscall__Dirent *entry)
{
	struct dirent *d;

	if (entry == NULL) {
		errno = EFAULT;
		return -1;
	}

	d = readdir (dirp);

	if (d == NULL) {
		return -1;
	}

	copy_dirent (entry, d);

	return 0;
}

gint32
Mono_Posix_Syscall_readdir_r (DIR *dirp, struct Mono_Posix_Syscall__Dirent *entry, void **result)
{
	struct dirent _entry;
	int r;

	r = readdir_r (dirp, &_entry, (struct dirent**) result);

	if (r == 0 && result != NULL) {
		copy_dirent (entry, &_entry);
	}

	return r;
}

G_END_DECLS

/*
 * vim: noexpandtab
 */