summaryrefslogtreecommitdiff
path: root/src/ot_scan.h
blob: a79ec13be3678026d7f7af5ae646c87c5727d841 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* This software was written by Dirk Engling <erdgeist@erdgeist.org>
   It is considered beerware. Prost. Skol. Cheers or whatever. */

#ifndef OT_SCAN_H__
#define OT_SCAN_H__

#include <stddef.h>
#include <stddef.h>
#include <stdint.h>

/* Read an unsigned decimal number from src into dest and return how many
   characters were consumed. Returns zero and leaves dest untouched when src
   does not begin with a digit, or when the value would exceed max. */
size_t scan_uint(const char *src, uint64_t *dest, uint64_t max);

/* As scan_uint, but following the bencode integer grammar, which permits a
   leading zero on zero alone. */
size_t scan_uint_bencode(const char *src, uint64_t *dest, uint64_t max);

/* Read a signed decimal number that has to take up exactly len characters,
   which is how a value lifted out of a query string arrives. Returns 0, or
   -1 leaving dest untouched. */
int    scan_int(const char *src, size_t len, int64_t *dest);

#endif