Changeset 4c0fe8
- Timestamp:
- 09/20/09 17:11:04 (3 years ago)
- Branches:
- master
- Children:
- 05a23a
- Parents:
- fb1747
- git-author:
- J. A. Bezemer <J.A.Bezemer@…> (09/20/09 17:11:04)
- git-committer:
- Erik Ekman <erik@…> (02/04/12 20:34:03)
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/read.c
ra5031e r4c0fe8 127 127 128 128 int 129 readtxtbin(char *packet, char **src, size_t srcremain, char *dst, size_t dstremain) 130 { 131 unsigned char *uc; 132 int tocopy; 133 int dstused = 0; 134 135 while (srcremain > 0) 136 { 137 uc = (unsigned char*) (*src); 138 tocopy = *uc; 139 (*src)++; 140 srcremain--; 141 142 if (tocopy > srcremain) 143 return 0; /* illegal, better have nothing */ 144 if (tocopy > dstremain) 145 return 0; /* doesn't fit, better have nothing */ 146 147 memcpy(dst, *src, tocopy); 148 dst += tocopy; 149 (*src) += tocopy; 150 srcremain -= tocopy; 151 dstremain -= tocopy; 152 dstused += tocopy; 153 } 154 return dstused; 155 } 156 157 int 129 158 putname(char **buf, size_t buflen, const char *host) 130 159 { … … 213 242 } 214 243 244 int 245 puttxtbin(char **buf, size_t bufremain, char *from, size_t fromremain) 246 { 247 unsigned char uc; 248 unsigned char *ucp = &uc; 249 char *cp = (char *) ucp; 250 int tocopy; 251 int bufused = 0; 252 253 while (fromremain > 0) 254 { 255 tocopy = fromremain; 256 if (tocopy > 252) 257 tocopy = 252; /* allow off-by-1s in caches etc */ 258 if (tocopy + 1 > bufremain) 259 return -1; /* doesn't fit, better have nothing */ 260 261 uc = tocopy; 262 **buf = *cp; 263 (*buf)++; 264 bufremain--; 265 bufused++; 266 267 memcpy(*buf, from, tocopy); 268 (*buf) += tocopy; 269 from += tocopy; 270 bufremain -= tocopy; 271 fromremain -= tocopy; 272 bufused += tocopy; 273 } 274 return bufused; 275 } -
src/read.h
ra5031e r4c0fe8 22 22 int readlong(char *, char **, uint32_t *); 23 23 int readdata(char *, char **, char *, size_t); 24 int readtxtbin(char *, char **, size_t, char *, size_t); 24 25 25 26 int putname(char **, size_t, const char *); … … 28 29 int putlong(char **, uint32_t); 29 30 int putdata(char **, char *, size_t); 31 int puttxtbin(char **, size_t, char *, size_t); 30 32 31 33 #endif
Note: See TracChangeset
for help on using the changeset viewer.
