diff options
author | law <law@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-09-05 01:11:54 +0000 |
---|---|---|
committer | law <law@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-09-05 01:11:54 +0000 |
commit | ffcbbbab99149ea7d8e800326458b70b54438076 (patch) | |
tree | e2a997b294961a00f5d259edefbef93b8501c089 /libchill/writerecord.c | |
parent | ff8e09bdcb33f98c7094eec337fb5e93da360a0d (diff) | |
download | gcc-ffcbbbab99149ea7d8e800326458b70b54438076.tar.gz |
* Chill runtime moved into toplevel libchill.
* Makefile.in Revamped due to move. Add multilib support.
* configure.in: Similarly. Use autoconf.
* powerset.h: Do not depend on BITS_PER_UNIT.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@22238 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libchill/writerecord.c')
-rw-r--r-- | libchill/writerecord.c | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/libchill/writerecord.c b/libchill/writerecord.c new file mode 100644 index 00000000000..7e88322bd55 --- /dev/null +++ b/libchill/writerecord.c @@ -0,0 +1,133 @@ +/* Implement Input/Output runtime actions for CHILL. + Copyright (C) 1992,1993 Free Software Foundation, Inc. + Author: Wilfried Moser, et al + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include <setjmp.h> +#include <errno.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> + +#include "fileio.h" + +static +void +doWrite( Access_Mode* the_access, void* buf, size_t nbyte ) +{ + size_t nwrit; + + nwrit = write( the_access->association->handle, buf, nbyte ); + + if( nwrit < nbyte ) + { + the_access->association->syserrno = errno; + RWEXCEPTION( WRITEFAIL, OS_IO_ERROR ); + } +} + + +void +__writerecord( Access_Mode* the_access, + signed long the_index, + char* the_val_addr, + unsigned long the_val_len, + char* file, + int line ) + +{ + Association_Mode* the_assoc; + unsigned long info; + char* actaddr; + unsigned short actlen; + off_t filepos; + + if( !the_access ) + CHILLEXCEPTION( file, line, EMPTY, NULL_ACCESS ); + + if( !(the_assoc = the_access->association) ) + CHILLEXCEPTION( file, line, NOTCONNECTED, IS_NOT_CONNECTED ); + + /* Usage must no be ReadOnly */ + if( the_assoc->usage == ReadOnly ) + CHILLEXCEPTION( file, line, WRITEFAIL, BAD_USAGE ); + + /* + * Positioning + */ + if( TEST_FLAG( the_access, IO_INDEXED ) ) + { + /* index expression must be within bounds of index mode */ + if( the_index < the_access->lowindex + || the_access->highindex < the_index ) + CHILLEXCEPTION( file, line, RANGEFAIL, BAD_INDEX ); + filepos = the_access->base + + (the_index - the_access->lowindex) * the_access->reclength; + + if( lseek( the_assoc->handle, filepos, SEEK_SET ) == -1L ) + CHILLEXCEPTION( file, line, WRITEFAIL, LSEEK_FAILS ); + } + + if( (info = setjmp( __rw_exception )) ) + CHILLEXCEPTION( file, line, info>>16, info & 0xffff ); + + if( TEST_FLAG( the_access, IO_TEXTIO ) ) + { + if( TEST_FLAG( the_access, IO_INDEXED ) ) + { + int nspace = the_access->reclength - the_val_len; + memset( the_val_addr + 2 + the_val_len, ' ', nspace ); + actlen = the_access->reclength - 2; + MOV2(the_val_addr,&actlen); + doWrite( the_access, the_val_addr, the_access->reclength ); + } + else + { + if( the_assoc->ctl_pre ) + write( the_assoc->handle, &the_assoc->ctl_pre, 1 ); + MOV2(&actlen,the_val_addr); + write( the_assoc->handle, the_val_addr + 2, actlen ); + if( the_assoc->ctl_post ) + write( the_assoc->handle, &the_assoc->ctl_post, 1 ); + the_assoc->ctl_pre = '\0'; + the_assoc->ctl_post = '\n'; + } + } + else + { + switch( the_access->rectype ) + { + case Fixed: + if( TEST_FLAG( the_assoc, IO_VARIABLE ) ) + { + actlen = the_access->reclength; + doWrite( the_access, &actlen, sizeof(actlen) ); + } + doWrite( the_access, the_val_addr, the_val_len ); + break; + case VaryingChars: + MOV2(&actlen,the_val_addr); + if( actlen > the_access->reclength - 2 ) + CHILLEXCEPTION( file, line, RANGEFAIL, RECORD_TOO_LONG ); + actlen = TEST_FLAG( the_access, IO_INDEXED ) + ? the_access->reclength : actlen + 2; + doWrite( the_access, the_val_addr, actlen ); + break; + } + } +} |