home *** CD-ROM | disk | FTP | other *** search
- /*********
- * FILEWRIT.C
- * by Tom Rettig, Leonard Zerman
- * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
- *
- * Syntax: FILEWRITE( [<drive>:][\<path>]<filename.ext>, <expC> )
- * Return: <expC> "DONE" if written successfully, otherwise error message.
- *********/
-
- #include "trlib.h"
-
- TRTYPE filewrite()
- {
- static char funcname[] = { "filewrite" };
- static char eofmark[] = { (char)EOF_MARK, NULLC };
- char *filename, *instr, *tempstr;
- int filenum, writebytes;
- int i, status;
- long maxbytes;
-
- if ( PCOUNT==2 && ISCHAR(1) && ISCHAR(2) )
- {
- filename = _parc(1);
- instr = _parc(2);
- filenum = _tr_creat( filename, FL_NORMAL );
-
- if ( filenum != FILEERROR && *filename && *instr )
- {
- i = 0;
- maxbytes = (long) _tr_strlen(instr);
-
- tempstr = instr;
- while (maxbytes > 32767L)
- {
- if (status = _tr_write( filenum, tempstr, 32767) == -1)
- {
- _retc( _tr_errmsgs(funcname,E_FWRITE) );
- _tr_close( filenum );
- }
- tempstr += 32767;
- maxbytes -= 32767L;
- }
-
- writebytes = _tr_write( filenum, tempstr, (int) maxbytes );
-
- if ( writebytes != FILEERROR )
- {
- _tr_write( filenum, eofmark, 1 );
- if ( !_tr_close(filenum) ) /* _tr_close returns 0 if successful */
- _retc( DONE );
- else
- _retc( _tr_errmsgs(funcname,E_FCLOSE) );
- }
- else
- {
- _retc( _tr_errmsgs(funcname,E_FWRITE) );
- _tr_close( filenum );
- }
- }
- else
- _retc( _tr_errmsgs(funcname,E_FOPEN) );
- }
- else
- _retc( _tr_errmsgs(funcname,E_SYNTAX) );
- }
-
-