This is readline.c in view mode; [Download] [Up]
#import "readline.h" #include <string.h> #include <stdlib.h> static char *buffer=NULL; static unsigned long length_of_buffer; char *readline(FILE *theFile) { void *ptr; int offset; if(buffer==NULL){ buffer=(char *)malloc(64*sizeof(char)); length_of_buffer=64; } ptr=NULL; offset=0; *buffer='\0'; while(ptr=fgets(buffer+offset,length_of_buffer-offset,theFile), ((ptr!=NULL)&&(buffer[strlen(buffer)-1]!='\n'))){ buffer=realloc((char *)buffer,length_of_buffer*2); offset=length_of_buffer-1; length_of_buffer*=2; } if(ptr==NULL) return NULL; else return buffer; } char *get_buffer() { return buffer; }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.