Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/3d/close3d.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
int
27
close3d(int fd)
28
{
29
initialize();
30
if (fd >= 0 && fd < elementsof(state.file))
31
{
32
register int nfd;
33
register short* rp;
34
#if FS
35
register Mount_t* mp;
36
#endif
37
38
#if defined(fchdir3d)
39
if (state.file[fd].dir)
40
{
41
free(state.file[fd].dir);
42
state.file[fd].dir = 0;
43
}
44
#endif
45
if (rp = state.file[fd].reserved)
46
{
47
if ((nfd = FCNTL(fd, F_DUPFD, fd + 1)) < 0)
48
{
49
errno = EBADF;
50
return -1;
51
}
52
*rp = nfd;
53
state.file[nfd].reserved = rp;
54
state.file[nfd].flags = FILE_LOCK;
55
state.file[fd].reserved = 0;
56
CLOSE(fd);
57
}
58
#if FS
59
if ((mp = state.file[fd].mount) && fssys(mp, MSG_close))
60
{
61
if (FSTAT(fd, &state.path.st))
62
state.path.st.st_mtime = 0;
63
fscall(mp, MSG_close, 0, fd, state.path.st.st_mtime);
64
}
65
for (mp = state.global; mp; mp = mp->global)
66
if (fssys(mp, MSG_close))
67
{
68
if ((state.file[fd].flags & FILE_OPEN) ? FSTAT(fd, &state.path.st) : fileinit(fd, NiL, NiL, 0))
69
state.path.st.st_mtime = 0;
70
fscall(mp, MSG_close, 0, fd, state.path.st.st_mtime);
71
}
72
if (state.file[fd].flags)
73
{
74
state.file[fd].flags = 0;
75
state.file[fd].mount = 0;
76
if (state.cache == fd)
77
while (state.cache > 1 && !state.file[--state.cache].flags);
78
}
79
#endif
80
}
81
return(CLOSE(fd));
82
}
83
84