summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d48e70d)
raw | patch | inline | side by side (parent: d48e70d)
author | fgsfds <pvt.fgsfds@gmail.com> | |
Sun, 11 Aug 2019 00:28:48 +0000 (03:28 +0300) | ||
committer | fgsfds <pvt.fgsfds@gmail.com> | |
Sun, 11 Aug 2019 00:28:48 +0000 (03:28 +0300) |
src/mastersrv/master.c | patch | blob | history |
diff --git a/src/mastersrv/master.c b/src/mastersrv/master.c
index ce98cfcd0a6e0772edf32b8a0f3155bc3573b291..304f6b532ff2f0957187ea75c5326fb57a803e9b 100644 (file)
--- a/src/mastersrv/master.c
+++ b/src/mastersrv/master.c
typedef struct ms_server_s ms_server;
const char ms_game_ver[] = "0.63";
-char ms_motd[256] = "";
-char ms_urgent[256] = "";
+char ms_motd[255] = "";
+char ms_urgent[255] = "";
int ms_port = 25660;
int ms_timeout = 100000;
int d_readtextfile (const char *fname, char *buf, size_t max) {
FILE *f = fopen(fname, "r");
+ char *const end = buf + max - 1;
+ char *p = buf;
if (f) {
- char line[256] = { 0 };
- while(fgets(buffer, sizeof(line), (FILE*) fp))
- printf("%s\n", buffer);
+ char ln[max];
+ char *const lend = ln + max - 1;
+ while(p < end && fgets(ln, sizeof(ln), f)) {
+ for (char *n = ln; n < lend && *n && *n != '\r' && *n != '\n'; ++n) {
+ *(p++) = *n;
+ if (p == end) break;
+ }
+ }
+ *p = '\0';
fclose(f);
return 0;
}