aboutsummaryrefslogtreecommitdiff
path: root/src/core/io_moves.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-10-14 00:05:43 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-10-14 14:45:22 +0200
commit8a91354f7b94c669c77fe628a81f9bfe9f599ef0 (patch)
treeba29a8b0416cb3464b49fd7cfb69e7f407b892c8 /src/core/io_moves.h
parent7dbd34574f629cacf3b89292d2a06ad0ae612f26 (diff)
downloadnissy-core-8a91354f7b94c669c77fe628a81f9bfe9f599ef0.tar.gz
nissy-core-8a91354f7b94c669c77fe628a81f9bfe9f599ef0.zip
Interface changes, progress with python
Diffstat (limited to 'src/core/io_moves.h')
-rw-r--r--src/core/io_moves.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/core/io_moves.h b/src/core/io_moves.h
index be43568..806887b 100644
--- a/src/core/io_moves.h
+++ b/src/core/io_moves.h
@@ -43,6 +43,7 @@ writemoves(uint8_t *m, int n, uint64_t buf_size, char *buf)
43{ 43{
44 int i; 44 int i;
45 uint64_t len; 45 uint64_t len;
46 int64_t written;
46 const char *s; 47 const char *s;
47 char *b; 48 char *b;
48 49
@@ -51,16 +52,16 @@ writemoves(uint8_t *m, int n, uint64_t buf_size, char *buf)
51 return NISSY_ERROR_BUFFER_SIZE; 52 return NISSY_ERROR_BUFFER_SIZE;
52 } 53 }
53 54
54 for (i = 0, b = buf; i < n; i++, b++, buf_size--) { 55 for (i = 0, b = buf, written = 0; i < n; i++, b++, written++) {
55 s = movestr[m[i]]; 56 s = movestr[m[i]];
56 len = strlen(s); 57 len = strlen(s);
57 if (len >= buf_size) { 58 if (len + written >= buf_size) {
58 LOG("Error: the given buffer is too small for " 59 LOG("Error: the given buffer is too small for "
59 "writing the given moves.\n"); 60 "writing the given moves.\n");
60 goto writemoves_error; 61 goto writemoves_error;
61 } 62 }
62 memcpy(b, s, len); 63 memcpy(b, s, len);
63 buf_size -= len; 64 written += len;
64 b += len; 65 b += len;
65 *b = ' '; 66 *b = ' ';
66 } 67 }
@@ -69,7 +70,7 @@ writemoves(uint8_t *m, int n, uint64_t buf_size, char *buf)
69 b--; /* Remove last space */ 70 b--; /* Remove last space */
70 *b = '\0'; 71 *b = '\0';
71 72
72 return buf_size; 73 return written;
73 74
74writemoves_error: 75writemoves_error:
75 *buf = '\0'; 76 *buf = '\0';

Generated with cgit - Back to sebastiano.tronto.net