|
#include <stdio.h>
#include "CharBuf.h"
int ReadLine(FILE *pf, char *buf, int len){_CFE_;
char ch;
int p=0;
while( (ch=fgetc(pf))!=EOF && ch ){
if( ch=='\n' ){
if( !p || buf[p-1]!='\\') break;
}
if( p==len ) return -1;
buf[p++] = ch;
}
buf[p] = 0;
return p ? p : (ch==EOF ? -1 : 0);
}
// Resizes CharBuf for long lines
int ReadLine(FILE *pf, CharBuf &cb, int &len){_CFE_;
char ch;
int p=0;
if( cb.Get() ) *cb.Get()=0;
else { cb=""; len=0; }
char *buf = cb.Get();
while( true ){
if( p==len ){
int nlen = len ? len*2 : 32;
if( !cb.Resize( nlen ) )
return -2;
len = nlen;
buf = cb.Get();
}
if( (ch=fgetc(pf))==EOF || !ch || ch=='\n' ) break;
buf[p++] = ch;
}
buf[p] = 0;
return p ? p : (ch==EOF ? -1 : 0);
}
inline volatile long long RDTSC() {_CFE_;
#ifdef __GCC__
register long long TSC asm("eax");
asm volatile (".byte 15, 49" : : : "eax", "edx");
return TSC;
#else
return 0;
#endif
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.