home
·
contact
·
privacy
projects
/
plomrogue
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Server: Fix bug of ai module's dijkstra_map() hanging on too large maps.
[plomrogue]
/
src
/
common
/
readwrite.c
diff --git
a/src/common/readwrite.c
b/src/common/readwrite.c
index 026c9add7aba8e5434f158bb97c765d957d88d55..045bc4fbbc89f80ff2044bc971e98251488d1681 100644
(file)
--- a/
src/common/readwrite.c
+++ b/
src/common/readwrite.c
@@
-2,9
+2,9
@@
#include "readwrite.h"
#include <stddef.h> /* size_t */
#include "readwrite.h"
#include <stddef.h> /* size_t */
-#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
+#include <stdint.h> /* uint8_t, uint16_t, uint32_t
, UINT32_MAX
*/
#include <stdio.h> /* FILE, fseek(), sprintf(), fgets(), fgetc(), ferror(),
#include <stdio.h> /* FILE, fseek(), sprintf(), fgets(), fgetc(), ferror(),
- * fputc(), fwrite(), fclose(), fopen()
+ * fputc(), fwrite(), fclose(), fopen()
, clearerr()
*/
#include <string.h> /* strlen() */
#include <unistd.h> /* for access(), unlink() */
*/
#include <string.h> /* strlen() */
#include <unistd.h> /* for access(), unlink() */
@@
-53,6
+53,7
@@
extern void try_fputc(uint8_t c, FILE * file, char * f)
extern int try_fgetc(FILE * file, char * f)
{
extern int try_fgetc(FILE * file, char * f)
{
+ clearerr(file); /* OSX' (BSD?) fgetc() needs this to undo previous EOFs. */
int test = fgetc(file);
exit_trouble(EOF == test && ferror(file), f, "fgetc()");
return test;
int test = fgetc(file);
exit_trouble(EOF == test && ferror(file), f, "fgetc()");
return test;
@@
-95,12
+96,11
@@
extern void try_fclose_unlink_rename(FILE * file, char * p1, char * p2,
-extern uint32_t textfile_
sizes(FILE * file, uint32_t * n_lines_p
)
+extern uint32_t textfile_
width(FILE * file
)
{
{
- char * f_name = "textfile_
sizes
()";
+ char * f_name = "textfile_
width
()";
int c = 0;
uint32_t c_count = 0;
int c = 0;
uint32_t c_count = 0;
- uint32_t n_lines = 0;
uint32_t linemax = 0;
while (1)
{
uint32_t linemax = 0;
while (1)
{
@@
-110,6
+110,7
@@
extern uint32_t textfile_sizes(FILE * file, uint32_t * n_lines_p)
break;
}
c_count++;
break;
}
c_count++;
+ exit_trouble(UINT32_MAX == c_count, f_name, "too large text file line");
if ('\n' == c)
{
if (c_count > linemax)
if ('\n' == c)
{
if (c_count > linemax)
@@
-117,10
+118,6
@@
extern uint32_t textfile_sizes(FILE * file, uint32_t * n_lines_p)
linemax = c_count;
}
c_count = 0;
linemax = c_count;
}
c_count = 0;
- if (n_lines_p)
- {
- n_lines++;
- }
}
}
if (0 == linemax && 0 < c_count) /* Handle files that consist of only one */
}
}
if (0 == linemax && 0 < c_count) /* Handle files that consist of only one */
@@
-128,9
+125,5
@@
extern uint32_t textfile_sizes(FILE * file, uint32_t * n_lines_p)
linemax = c_count;
}
exit_trouble(-1 == fseek(file, 0, SEEK_SET), f_name, "fseek()");
linemax = c_count;
}
exit_trouble(-1 == fseek(file, 0, SEEK_SET), f_name, "fseek()");
- if (n_lines_p)
- {
- * n_lines_p = n_lines;
- }
return linemax;
}
return linemax;
}