Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/librecsort/rsfile.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1996-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
* Phong Vo <[email protected]> *
18
* Glenn Fowler <[email protected]> *
19
* *
20
***********************************************************************/
21
#include "rshdr.h"
22
23
/*
24
* announce sp open for write on path
25
*/
26
27
#if __STD_C
28
int rsfilewrite(Rs_t* rs, Sfio_t* sp, const char* path)
29
#else
30
int rsfilewrite(rs, sp, path)
31
Rs_t* rs;
32
Sfio_t* sp;
33
char* path;
34
#endif
35
{
36
if ((rs->events & RS_FILE_WRITE) && rsnotify(rs, RS_FILE_WRITE, sp, (Void_t*)path, rs->disc) < 0)
37
return -1;
38
return 0;
39
}
40
41
/*
42
* announce sp open for read on path
43
*/
44
45
#if __STD_C
46
int rsfileread(Rs_t* rs, Sfio_t* sp, const char* path)
47
#else
48
int rsfileread(rs, sp, path)
49
Rs_t* rs;
50
Sfio_t* sp;
51
char* path;
52
#endif
53
{
54
if ((rs->events & RS_FILE_READ) && rsnotify(rs, RS_FILE_READ, sp, (Void_t*)path, rs->disc) < 0)
55
return -1;
56
return 0;
57
}
58
59
/*
60
* close file stream
61
*/
62
63
#if __STD_C
64
int rsfileclose(Rs_t* rs, Sfio_t* sp)
65
#else
66
int rsfileclose(rs, sp)
67
Rs_t* rs;
68
Sfio_t* sp;
69
#endif
70
{
71
int n;
72
73
if (rs->events & RS_FILE_CLOSE)
74
{
75
if ((n = rsnotify(rs, RS_FILE_CLOSE, sp, (Void_t*)0, rs->disc)) < 0)
76
return -1;
77
if (n)
78
return 0;
79
}
80
if (sp != sfstdout)
81
return sfclose(sp);
82
return 0;
83
}
84
85