aboutsummaryrefslogtreecommitdiff
path: root/src/outstream.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/outstream.c')
-rw-r--r--src/outstream.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/outstream.c b/src/outstream.c
new file mode 100644
index 00000000..10b5f981
--- /dev/null
+++ b/src/outstream.c
@@ -0,0 +1,122 @@
1/* Copyrights 2002 Luis Figueiredo (stdio@netc.pt) All rights reserved.
2 *
3 * See the LICENSE file
4 *
5 * The origin of this software must not be misrepresented, either by
6 * explicit claim or by omission. Since few users ever read sources,
7 * credits must appear in the documentation.
8 *
9 * date: Sat Mar 30 14:25:25 GMT 2002
10 *
11 * -- stream list functions
12 */
13
14
15#include "outstream.h"
16
17/*********************************************************************************************************/
18/*
19 * add_outstream, add a file to output (client) stream
20 */
21int __ILWS_add_outstream(struct outstream *list,char *fname,FILE* stream,int istmp){
22 struct outstream *temp=list;
23 FILE *tmp;
24 while(temp->next!=NULL)temp=temp->next;
25
26 if(!(temp->next=__ILWS_malloc(sizeof(struct outstream)))) {
27 LWSERR(LE_MEMORY);
28 return 0;
29 };
30 // file check (0.5.3);
31 tmp=fopen(fname,"rb");
32 if(tmp==NULL) {
33 __ILWS_free(temp->next);
34 temp->next=NULL;
35 return 0;
36 };
37 fclose(tmp);
38 // --
39 temp->next->fname=NULL;
40 if(fname!=NULL) {
41 if(!(temp->next->fname=__ILWS_malloc(strlen(fname)+1))) {
42 __ILWS_free(temp->next);
43 temp->next=NULL;
44 LWSERR(LE_MEMORY);
45 return 0;
46 };
47 memcpy(temp->next->fname,fname,strlen(fname));
48 temp->next->fname[strlen(fname)]='\0';
49 };
50 temp->next->todelete=istmp;
51 temp->next->fstream=stream;
52 temp->next->wsize=1;
53 temp->next->rsize=0;
54 temp->next->wrotesize=0;
55 temp->next->varsize=0;
56 temp->next->next=NULL;
57 return 1;
58}
59
60/*********************************************************************************************************/
61/*
62 * Initializate (allocate) outstream list
63 */
64struct outstream *__ILWS_init_outstream_list() {
65 struct outstream *ret;
66
67
68 if(!(ret=__ILWS_malloc(sizeof(struct outstream)))) {
69 LWSERR(LE_MEMORY);
70 return NULL;
71 };
72 ret->todelete=0;
73 ret->fname=NULL;
74 ret->flags=0;
75 ret->fstream=NULL;
76 ret->next=NULL;
77 return ret;
78}
79
80/*********************************************************************************************************/
81/*
82 * Delete a especific node
83 */
84void __ILWS_delete_outstream(struct outstream *node) { // Changed
85 int rt;
86 if(node->fstream!=NULL)fclose(node->fstream); // better here;
87 if(node->todelete) { // is temporary file
88 rt=unlink(node->fname);
89 if(rt==-1) {
90 LWSERR(LE_FILESYS);
91 };
92
93 };
94 if(node->fname!=NULL)__ILWS_free(node->fname);
95 __ILWS_free(node);
96}
97
98/*********************************************************************************************************/
99/*
100 * delete next node
101 */
102void __ILWS_delete_next_outstream(struct outstream *node) {
103 struct outstream *temp=node->next;
104 node->next=node->next->next;
105 __ILWS_delete_outstream(temp);
106}
107
108/*********************************************************************************************************/
109/*
110 * delete all nodes on the list (reset list)
111 */
112void __ILWS_delete_outstream_list(struct outstream *list) {
113 struct outstream *temp=list;
114 while(temp->next!=NULL) {
115
116 __ILWS_delete_next_outstream(temp);
117 };
118
119 __ILWS_delete_outstream(temp);
120
121}
122