Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/3d/dup3d.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1989-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* David Korn <[email protected]> *
19
* Eduardo Krell <[email protected]> *
20
* *
21
***********************************************************************/
22
#pragma prototyped
23
24
#include "3d.h"
25
26
#if FS
27
28
int
29
fs3d_dup(int ofd, int nfd)
30
{
31
register Mount_t* mp;
32
33
if (nfd >= 0 && ofd >= 0 && ofd < elementsof(state.file))
34
{
35
if (state.cache)
36
{
37
if (!(state.file[ofd].flags & FILE_OPEN))
38
fileinit(ofd, NiL, NiL, 0);
39
state.file[nfd] = state.file[ofd];
40
state.file[nfd].flags &= ~FILE_CLOEXEC;
41
state.file[nfd].reserved = 0;
42
if (nfd > state.cache)
43
state.cache = nfd;
44
if (nfd > state.open)
45
state.open = nfd;
46
if (mp = state.file[nfd].mount)
47
fscall(mp, MSG_dup, nfd, ofd);
48
for (mp = state.global; mp; mp = mp->global)
49
if (fssys(mp, MSG_dup))
50
fscall(mp, MSG_dup, nfd, ofd);
51
}
52
#if defined(fchdir3d)
53
if (state.file[nfd].dir)
54
{
55
free(state.file[nfd].dir);
56
state.file[nfd].dir = 0;
57
}
58
if (state.file[ofd].dir && (state.file[nfd].dir = newof(0, Dir_t, 1, strlen(state.file[ofd].dir->path))))
59
{
60
strcpy(state.file[nfd].dir->path, state.file[ofd].dir->path);
61
state.file[nfd].dir->dev = state.file[ofd].dir->dev;
62
state.file[nfd].dir->ino = state.file[ofd].dir->ino;
63
}
64
#endif
65
}
66
return 0;
67
}
68
69
#endif
70
71
#ifdef dup3d
72
73
int
74
dup3d(int fd)
75
{
76
register int r;
77
78
initialize();
79
r = DUP(fd);
80
#if FS
81
if (r >= 0 && r < elementsof(state.file))
82
fs3d_dup(fd, r);
83
#endif
84
return r;
85
}
86
87
#else
88
89
NoN(dup)
90
91
#endif
92
93