/*************************************************************************/ /* */ /* Copyright (c) 1994 Stanford University */ /* */ /* All rights reserved. */ /* */ /* Permission is given to use, copy, and modify this software for any */ /* non-commercial purpose as long as this copyright notice is not */ /* removed. All other uses, including redistribution in whole or in */ /* part, are forbidden without prior written permission. */ /* */ /* This software is provided with absolutely no warranty and no */ /* support. */ /* */ /*************************************************************************/ /********** storing/loading of large arrays to/from files **********/ #include #include "incl.h" #define PMODE 0644 /* RW for owner, R for group, R for others */ #define RWMODE 0 /* Read-only */ EXTERN_ENV int Create_File(char filename[]) { int fd; if ((fd = creat(filename,PMODE)) == -1) { Error(" Can't create %s\n",filename); } return(fd); } int Open_File(char filename[]) { int fd; if ((fd = open(filename,RWMODE)) == -1) { Error(" Can't open %s\n",filename); } return(fd); } void Write_Bytes(int fd, unsigned char array[], long length) { long n_written; long more_written; n_written = write(fd,array,MIN(length,32766)); if (n_written != -1) { while (n_written < length) { more_written = write(fd,&array[n_written], MIN(length-n_written,32766)); if (more_written == -1) break; n_written += more_written; } } if (n_written != length) { Close_File(fd); Error(" Write failed on file %d\n",fd); } } void Write_Shorts(int fd, unsigned char array[], long length) { long n_written; long more_written; #ifdef FLIP for (i=0; i