Skip to content
Snippets Groups Projects
Commit 0b106f6d authored by deuce's avatar deuce
Browse files

Because of the various translation modes, we can't fseek() based on the

buffer size, or really do anything except fgetc() in a loop.  Do that then.

Also, use DLLEXPORT/DLLCALL/etc. macros.
parent 8a2ddec5
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,7 @@
#include <sys/types.h> /* _dev_t */
#include <sys/stat.h> /* struct stat */
#include <limits.h> /* struct stat */
#include <stdlib.h> /* realloc() */
#include "filewrap.h" /* Verify prototypes */
......@@ -276,6 +277,9 @@ int DLLCALL unlock(int file, off_t offset, off_t size)
return(i);
}
#endif /* !Unix && (MSVC || MinGW) */
#if defined(_WIN32 )
static size_t
p2roundup(size_t n)
{
......@@ -315,13 +319,10 @@ static int expandtofit(char **linep, size_t len, size_t *linecapp)
return 0;
}
long getdelim(char **linep, size_t *linecapp, int delimiter, FILE *stream)
long DLLCALL getdelim(char **linep, size_t *linecapp, int delimiter, FILE *stream)
{
size_t linelen;
char lbuf[1024];
size_t bc;
char *term = NULL;
long pos = ftell(stream);
int ch;
if(linep == NULL || linecapp == NULL)
return -1;
......@@ -336,26 +337,21 @@ long getdelim(char **linep, size_t *linecapp, int delimiter, FILE *stream)
linelen = 0;
for(;;) {
bc = fread(lbuf, 1, sizeof(lbuf), stream);
if(expandtofit(linep, linelen+bc, linecapp))
return -1;
memcpy(*linep+linelen, lbuf, bc);
term = strchr(*linep+linelen, delimiter);
linelen += bc;
if(bc < sizeof(lbuf))
ch = fgetc(stream);
if(ch == EOF)
break;
if(term)
if(expandtofit(linep, linelen+1, linecapp))
return -1;
(*linep)[linelen++]=ch;
if(ch == delimiter)
break;
}
if(term) {
linelen = term - *linep;
linelen++;
fseek(stream, pos+linelen, SEEK_SET);
}
(*linep)[linelen]=0;
if(linelen==0)
return -1;
return linelen;
}
#endif /* !Unix && (MSVC || MinGW) */
#endif
#ifdef __unix__
FILE *_fsopen(const char *pszFilename, const char *pszMode, int shmode)
......
......@@ -166,8 +166,8 @@ extern "C" {
DLLEXPORT int DLLCALL unlock(int fd, off_t pos, off_t len);
#endif
#if (defined(_MSC_VER) || defined(__MINGW32__) || defined(__DMC__)) && !defined(__unix__)
long getdelim(char **linep, size_t *linecapp, int delimiter, FILE *stream);
#if defined(_WIN32 )
DLLEXPORT long DLLCALL getdelim(char **linep, size_t *linecapp, int delimiter, FILE *stream);
#endif
#if !defined(__BORLANDC__) && defined(__unix__)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment