#include #include #include #include #include /* * The following are I/O routines. This file contains a vanilla C version, * which should work anywhere. * * NOTES: * * - Can be used with an SSD file system. * * - Does not do asynchronous transfers * * - Does not require an "assign -s bin secondary-storage-filename" as for * FORTRAN */ /* opntmp -- Open the specified secondary storage file * Calling routine provides: * name = Name of file to be created/opened * size = Size of file in words. * * Flags: * O_CREAT = Create the file if it does not exist. * O_RDWR = Open for reading and writing. * O_TRUNC = Truncate the file to 0 length if already exists. * * Returns: * A positive int value (the file descriptor), otherwise it returns * -1 to indicate that the file could not be opened. */ int opntmp (char *name, long int size) { return (open (name, O_CREAT | O_RDWR | O_TRUNC, 0640)); } /* rdtmp -- Read NWORDS words into ARRAY from Input file */ void rdtmp (int fd, char *ARRAY, long int nwords, long int buf) { int size, nr; size = sizeof (long int); if ((nr = read (fd, ARRAY, size * nwords)) < 0) { perror (" read failed"); printf("Bytes read = %d\n", nr); exit (1); } return; } /* wrtmp -- Write NWORDS words from ARRAY */ void wrtmp (int fd, char *ARRAY, long int nwords, long int buf) { int size, nw; size = sizeof (long int); if ((nw = write (fd, ARRAY, size * nwords)) != (size * nwords)) { perror (" write failed"); printf ("Bytes written to file = %d\n", nw); exit (1); } return; } /* sktmp -- Seek to word number POS in UNIT */ void sktmp (int fd, long int pos) { long int size; size = sizeof (long int); if (lseek (fd, size * pos, 0) != (size * pos)) { perror (" lseek failed"); exit (1); } return; } /* syntmp -- Make sure previous i/o to this unit is done * No action required as asynchronous I/O is not performed by * these routines. */ void syntmp (int fd, long int buf) { return; }