241 #include <sys/types.h> 242 #include <sys/stat.h> 271 #define DEBUG (debugSet > DEBUGOFF ) 275 #define NAMEBUFFLEN 256 276 #define MODEBUFFLEN 10 278 #define CURRENT_FILE (fptable[*unit]) 316 char namebuff[NAMEBUFFLEN+1], modebuff[MODEBUFFLEN+1];
327 for( loop = 0; loop < strlen(
debugLevel) ; loop++ ) {
329 printf(
"Invalid number string in BYTES_IO_DEBUG: %s\n",
debugLevel);
330 printf(
"BYTES_IO_DEBUG must comprise only digits [0-9].\n");
336 if( DEBUG ) printf(
"BYTES_IO_OPEN: debug switched on\n");
346 n1 = (l1>NAMEBUFFLEN) ? NAMEBUFFLEN : l1;
347 n2 = (l2>MODEBUFFLEN) ? MODEBUFFLEN : l2;
349 strncpy( namebuff, name, n1);
350 strncpy( modebuff, mode, n2);
364 p = namebuff + strlen(namebuff) - 1 ;
370 if( DEBUG ) printf(
"BYTES_IO_OPEN: filename = [%s]\n", namebuff);
379 case 'A': strcat(flags,
"a");
385 case 'W': strcat(flags,
"w");
400 if( DEBUG ) printf(
"BYTES_IO_OPEN: file open mode = %s\n", flags);
419 perror(
"Unable to allocate space for table of FILE pointers");
425 perror(
"Unable to allocate space for FILE buffers");
451 perror(
"Unable to reallocate space for table of FILE pointers");
458 perror(
"Unable to allocate space for FILE buffers");
471 if( DEBUG ) printf(
"BYTES_IO_OPEN: fptable slot = %d\n", *unit);
473 if( DEBUG ) printf(
"BYTES_IO_OPEN: using fopen\n");
474 fptable[
n] = fopen(namebuff, flags );
489 envSize = getenv(
"BYTES_IO_BUFSIZE");
494 for( loop = 0; loop < strlen(
envSize) ; loop++ ) {
495 if( ! isdigit(
envSize[loop]) ) {
496 printf(
"Invalid number string in BYTES_IO_BUFSIZE: %s\n",
envSize);
497 printf(
"BYTES_IO_BUFSIZE must comprise only digits [0-9].\n");
504 printf(
"Invalid buffer size in BYTES_IO_BUFSIZE: %s\n",
envSize);
505 printf(
"Buffer size defined by BYTES_IO_BUFSIZE must be positive.\n");
511 if( DEBUG ) printf(
"BYTES_IO_OPEN: file buffer size = %ld\n",
size);
518 perror(
"setvbuf failed");
561 int my_offset = (int) *offset;
562 int my_whence = (int) *whence;
568 printf(
"BYTES_IO_SEEK: fptable slot = %d\n", *unit);
569 printf(
"BYTES_IO_SEEK: Offset = %d\n", my_offset);
570 printf(
"BYTES_IO_SEEK: Type of offset = %d\n", my_whence);
573 if( my_whence == 2) my_offset = - abs(my_offset);
575 *iret = ftell(CURRENT_FILE);
576 if( DEBUG ) printf(
"BYTES_IO_SEEK: current position = %d\n", *iret);
577 if( *iret == my_offset && my_whence == 0)
580 *iret = fseek(CURRENT_FILE, my_offset, my_whence);
582 if( DEBUG ) printf(
"BYTES_IO_SEEK: fseek return code = %d\n",*iret);
585 if( ! feof(CURRENT_FILE) ) {
587 perror(
"bytes_io_seek");
592 clearerr(CURRENT_FILE);
599 *iret = ftell(CURRENT_FILE);
602 printf(
"BYTES_IO_SEEK: byte offset from start of file = %d\n",*iret);
638 *iret = ftell(CURRENT_FILE);
642 printf(
"BYTES_IO_TELL: fptable slot = %d. ", *unit);
643 printf(
"Error status = %d\n", *iret);
645 perror(
"bytes_io_tell");
650 printf(
"BYTES_IO_TELL: fptable slot = %d. ", *unit);
651 printf(
"Byte offset from start of file = %d\n",*iret);
689 printf(
"BYTES_IO_READ: fptable slot = %d. ", *unit);
690 printf(
"Number of bytes to read = %d\n", *nbytes);
693 if( (*iret = fread(buffer, 1, *nbytes, CURRENT_FILE) ) != *nbytes) {
694 if( ! feof(CURRENT_FILE) ) {
696 perror(
"bytes_io_read");
697 clearerr(CURRENT_FILE);
702 clearerr(CURRENT_FILE);
707 printf(
"BYTES_IO_READ: fptable slot = %d. ", *unit);
708 printf(
"Number of bytes read = %d\n", *nbytes);
745 printf(
"BYTES_IO_WRITE: fptable slot = %d. ", *unit);
746 printf(
"Number of bytes to write = %d\n", *nbytes);
749 if( (*iret = fwrite(buffer, 1, *nbytes, CURRENT_FILE) ) != *nbytes) {
750 perror(
"bytes_io_write");
755 printf(
"BYTES_IO_WRITE: fptable slot = %d. ", *unit);
756 printf(
"BYTES_IO_WRITE: number of bytes written = %d\n", *iret);
789 printf(
"BYTES_IO_CLOSE: fptable slot = %d\n", *unit);
791 if( ( *iret = fclose(CURRENT_FILE) ) != 0 ) perror(
"bytes_io_close");
815 printf(
"BYTES_IO_FLUSH: fptable slot = %d\n", *unit);
817 fflush(CURRENT_FILE);
void c_bytes_io_write__(int *unit, char *buffer, int *nbytes, int *iret)
void c_bytes_io_close_(int *unit, int *iret)
void c_bytes_io_open(int *unit, char *name, char *mode, int *iret, int l1, int l2)
static pthread_mutex_t fpTableBusy
void c_bytes_io_open_(int *unit, char *name, char *mode, int *iret, int l1, int l2)
void c_bytes_io_tell_(int *unit, int *iret)
void c_bytes_io_write_(int *unit, char *buffer, int *nbytes, int *iret)
quick &counting sorts only inumt inumt name
void c_bytes_io_seek_(int *unit, int *offset, int *whence, int *iret)
void c_bytes_io_close__(int *unit, int *iret)
void c_bytes_io_write(int *unit, char *buffer, int *nbytes, int *iret)
void c_bytes_io_read_(int *unit, char *buffer, int *nbytes, int *iret)
static char ** fileBuffer
void c_bytes_io_flush__(int *unit)
void c_bytes_io_open__(int *unit, char *name, char *mode, int *iret, int l1, int l2)
void c_bytes_io_tell(int *unit, int *iret)
void c_bytes_io_close(int *unit, int *iret)
void c_bytes_io_tell__(int *unit, int *iret)
void c_bytes_io_read__(int *unit, char *buffer, int *nbytes, int *iret)
void c_bytes_io_flush_(int *unit)
void c_bytes_io_flush(int *unit)
void c_bytes_io_seek(int *unit, int *offset, int *whence, int *iret)
void c_bytes_io_read(int *unit, char *buffer, int *nbytes, int *iret)