Mercurial > hg > toybox
comparison lib/lib.c @ 1345:b7598d21ca10 draft
Forgot to check in strstart().
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 09 Jun 2014 07:12:49 -0500 |
parents | 313980d3d78c |
children | 46f068aaa480 |
comparison
equal
deleted
inserted
replaced
1344:788c6c097fa2 | 1345:b7598d21ca10 |
---|---|
276 if (!needle) return -1; | 276 if (!needle) return -1; |
277 off = strchr(haystack, needle); | 277 off = strchr(haystack, needle); |
278 if (!off) return -1; | 278 if (!off) return -1; |
279 | 279 |
280 return off-haystack; | 280 return off-haystack; |
281 } | |
282 | |
283 // If *a starts with b, advance *a past it and return 1, else return 0; | |
284 int strstart(char **a, char *b) | |
285 { | |
286 int len = strlen(b), i = !strncmp(*a, b, len); | |
287 | |
288 if (i) *a += len; | |
289 | |
290 return i; | |
281 } | 291 } |
282 | 292 |
283 // Return how long the file at fd is, if there's any way to determine it. | 293 // Return how long the file at fd is, if there's any way to determine it. |
284 off_t fdlength(int fd) | 294 off_t fdlength(int fd) |
285 { | 295 { |