Initial revision

This commit is contained in:
ceriel
1987-01-27 15:57:55 +00:00
parent ee89196671
commit e49bbfbe1f
112 changed files with 4068 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
#include <stdio.h>
#define PMODE 0666
FILE *fopen(name,mode)
char *name , *mode;
{
register int i;
FILE *fp;
char *malloc();
int fd,
flags = 0;
for (i = 0; _io_table[i] != 0 ; i++)
if ( i >= _NFILES )
return(NULL);
switch(*mode){
case 'w':
flags |= IO_WRITEMODE;
fd = creat (name,PMODE);
break;
case 'a':
flags |= IO_WRITEMODE;
if (( fd = open(name, 1)) < 0 )
fd = creat(name, PMODE);
if (fd >= 0) lseek(fd,0L,2);
break;
case 'r':
flags |= IO_READMODE;
if (( fd = open (name, 0)) < 0 )
return(NULL);
break;
default:
return(NULL);
}
if (fd < 0) return NULL;
if (( fp = (FILE *) malloc (sizeof( FILE))) == NULL ) {
close(fd);
return(NULL);
}
fp->_count = 0;
fp->_fd = fd;
fp->_flags = flags;
_io_table[i] = fp;
return(fp);
}