home *** CD-ROM | disk | FTP | other *** search
- /*
- c_file.c
- */
- /* Copyright (c) 1994 Christian F. Tschudin. All rights reserved.
-
- Distributed under the terms of the GNU General Public License
- version 2 of june 1991 as published by the Free Software
- Foundation, Inc.
-
- This file is part of M0.
-
- M0 is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY. No author or distributor accepts responsibility to anyone for
- the consequences of using it or for whether it serves any particular
- purpose or works at all, unless he says so in writing. Refer to the GNU
- General Public License for full details.
-
- Everyone is granted permission to copy, modify and redistribute M0, but
- only under the conditions described in the GNU General Public License.
- A copy of this license is supposed to have been given to you along with
- M0 so you can know your rights and responsibilities. It should be in a
- file named LICENSE. Among other things, the copyright notice and this
- notice must be preserved on all copies. */
-
- #include "c_proto.h"
-
-
- #ifdef CHANNEL_FILE
-
- static void
- file_submit(mproc p, void *data, eindex m)
- {
- uint len = elen(p,m);
- char *fn = unique_filename("sbmt");
- FILE *f = fopen(fn, "w+b");
-
- if (!f) {
- fprintf(stderr, " ## writing to file <%s> failed\n");
- return;
- }
- for (i = 0; i < len; i++)
- fputc(str_get(p, m, i), f);
- fclose(f);
- TRACE(3, printf("file submit %s %s\n", fn, (char *) data))
- return;
- }
-
- eindex
- add_file_channel(uint i)
- {
- /* installs under key `i' a file channel.
- Note: the key is NOT removed after having used
- the channel. Instead, each submit creates a new
- file with an unique file name! */
- byte s[8], t[20];
- eindex key;
-
- memset(s,0,8);
- memcpy(s+4,&i,4);
-
- sprintf((char*)t, "%d", (int) i);
- key = key_add(s);
-
- if (dict_get(0, channeldict, key) != 0)
- return 0;
-
- new_channel(key, strdup(t), file_submit);
-
- return key;
- }
-
- #endif /* CHANNEL_FILE */
-