ObjFW  Diff

Differences From Artifact [6eaf017199]:

  • File src/of_asprintf.m — part of check-in [13ee56edf3] at 2014-06-21 21:43:43 on branch trunk — Move all macros from OFObject.h to macros.h

    This means that OFObject.h imports macros.h now, making it unnecessary
    to manually import macros.h in almost every file. And while at it, also
    import autorelease.h in OFObject.h, so that this doesn't need to be
    manually imported in almost every file as well. (user: js, size: 13463) [annotate] [blame] [check-ins using]

To Artifact [a27170a922]:


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdbool.h>
#include <wchar.h>

#include <sys/types.h>

#import "OFString.h"

#import "asprintf.h"

#define MAX_SUBFORMAT_LEN 64

struct context {
	const char *format;
	size_t formatLen;
	char subformat[MAX_SUBFORMAT_LEN + 1];
	size_t subformatLen;







<
<







23
24
25
26
27
28
29


30
31
32
33
34
35
36
#include <stdbool.h>
#include <wchar.h>

#include <sys/types.h>

#import "OFString.h"



#define MAX_SUBFORMAT_LEN 64

struct context {
	const char *format;
	size_t formatLen;
	char subformat[MAX_SUBFORMAT_LEN + 1];
	size_t subformatLen;
55
56
57
58
59
60
61































62
63
64
65
66
67
68
		LENGTH_MODIFIER_LL,
		LENGTH_MODIFIER_J,
		LENGTH_MODIFIER_Z,
		LENGTH_MODIFIER_T,
		LENGTH_MODIFIER_CAPITAL_L
	} lengthModifier;
};
































static bool
appendString(struct context *ctx, const char *append, size_t appendLen)
{
	char *newBuf;

	if (appendLen == 0)







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
		LENGTH_MODIFIER_LL,
		LENGTH_MODIFIER_J,
		LENGTH_MODIFIER_Z,
		LENGTH_MODIFIER_T,
		LENGTH_MODIFIER_CAPITAL_L
	} lengthModifier;
};

#ifndef HAVE_ASPRINTF
static int
vasprintf(char **string, const char *format, va_list arguments)
{
	int length;
	va_list argumentsCopy;

	va_copy(argumentsCopy, arguments);

	if ((length = vsnprintf(NULL, 0, format, argumentsCopy)) < 0)
		return length;
	if ((*string = malloc((size_t)length + 1)) == NULL)
		return -1;

	return vsnprintf(*string, (size_t)length + 1, format, arguments);
}

static int
asprintf(char **string, const char *format, ...)
{
	int ret;
	va_list arguments;

	va_start(arguments, format);
	ret = vasprintf(string, format, arguments);
	va_end(arguments);

	return ret;
}
#endif

static bool
appendString(struct context *ctx, const char *append, size_t appendLen)
{
	char *newBuf;

	if (appendLen == 0)