summaryrefslogtreecommitdiffstats
path: root/libconfig/NumData.m
blob: 5cde6fb9db7d3bd295680ce8bfd4767e134edb98 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "NumData.h"
#include "Parser.h"
#include "String.h"

#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

@implementation NumData
-init
{
	self = [super init];
	return self;
}

-(String *)
createStr
{
	char buffer[1024];

	snprintf(buffer, sizeof(buffer), "%ld", data);
	return [[String new] setStr: buffer];
}

-setFromBuffer: (const char *)buffer withLength: (int)len
{
	char *endPtr;

	data = strtol(buffer, &endPtr, 0);
	if (*endPtr) {
		fprintf(stderr, "ERROR: `%s' is not a number.\n", buffer);
		return nil;
	}

	return self;
}

-(long)
getNum
{
	return data;
}
@end