ObjFW  Check-in [ff64ec30f4]

Overview
Comment:OFStrFTime: Don't use OFASPrintF()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ff64ec30f45277178df09526397b7384147067768aaf9f4c78be4de6d98cfd18
User & Date: js on 2023-08-23 13:54:33
Other Links: manifest | tags
Context
2023-08-23
15:39
OFHTTPClient: Don't enable non-blocking mode check-in: 3a8aa96e16 user: js tags: trunk
13:54
OFStrFTime: Don't use OFASPrintF() check-in: ff64ec30f4 user: js tags: trunk
12:44
Add OFStrFTime() consistent with OFStrPTime() check-in: 05d675eb07 user: js tags: trunk
Changes

Modified src/OFASPrintF.h from [a88266211f] to [a9b63bfa65].

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#import "macros.h"

OF_ASSUME_NONNULL_BEGIN

#ifdef __cplusplus
extern "C" {
#endif
extern int OFASPrintF(char *_Nullable *_Nonnull, const char *_Nonnull, ...);
extern int OFVASPrintF(
    char *_Nullable *_Nonnull, const char *_Nonnull, va_list);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END







<







25
26
27
28
29
30
31

32
33
34
35
36
37
38
#import "macros.h"

OF_ASSUME_NONNULL_BEGIN

#ifdef __cplusplus
extern "C" {
#endif

extern int OFVASPrintF(
    char *_Nullable *_Nonnull, const char *_Nonnull, va_list);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

Modified src/OFASPrintF.m from [1c0f37cece] to [ebfc63953a].

750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
	stringState,
	formatFlagsState,
	formatFieldWidthState,
	formatLengthModifierState,
	formatConversionSpecifierState
};

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

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

	return ret;
}

int
OFVASPrintF(char **string, const char *format, va_list arguments)
{
	struct Context ctx;

	ctx.format = format;
	ctx.formatLen = strlen(format);







<
<
<
<
<
<
<
<
<
<
<
<
<







750
751
752
753
754
755
756













757
758
759
760
761
762
763
	stringState,
	formatFlagsState,
	formatFieldWidthState,
	formatLengthModifierState,
	formatConversionSpecifierState
};














int
OFVASPrintF(char **string, const char *format, va_list arguments)
{
	struct Context ctx;

	ctx.format = format;
	ctx.formatLen = strlen(format);

Modified src/OFStrFTime.m from [48d4c4eaa5] to [6b4b50f001].

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <stdlib.h>
#include <string.h>
#include <time.h>

#import "OFStrFTime.h"
#import "OFASPrintF.h"
#import "macros.h"

static const char weekDays[7][4] = {
	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
static const char monthNames[12][4] = {
	"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",







<




<







11
12
13
14
15
16
17

18
19
20
21

22
23
24
25
26
27
28
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"


#include <string.h>
#include <time.h>

#import "OFStrFTime.h"

#import "macros.h"

static const char weekDays[7][4] = {
	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
static const char monthNames[12][4] = {
	"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
				buffer[j++] = format[i];
			}

			break;
		case stateInConversionSpecifier:;
			const char *appendFormat;
			unsigned int value = 0;
			char *append;
			int appendLen;

			switch (format[i]) {
			case '%':
				appendFormat = "%%";
				break;
			case 'a':







|







57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
				buffer[j++] = format[i];
			}

			break;
		case stateInConversionSpecifier:;
			const char *appendFormat;
			unsigned int value = 0;
			char append[5];
			int appendLen;

			switch (format[i]) {
			case '%':
				appendFormat = "%%";
				break;
			case 'a':
137
138
139
140
141
142
143

144
145

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

				value = (value / 60) * 100 + (value % 60);
				break;
			default:
				return 0;
			}


			appendLen = OFASPrintF(&append, appendFormat, value);
			if (appendLen < 0)

				return 0;

			if (bufferLen - j < (size_t)appendLen) {
				free(append);
				return 0;
			}

			memcpy(buffer + j, append, appendLen);
			j += appendLen;

			free(append);
			state = stateSearchConversionSpecifier;
		}
	}

	if (j >= bufferLen)
		return 0;

	buffer[j] = 0;

	return j;
}







>
|
|
>


|
<

<




<











135
136
137
138
139
140
141
142
143
144
145
146
147
148

149

150
151
152
153

154
155
156
157
158
159
160
161
162
163
164

				value = (value / 60) * 100 + (value % 60);
				break;
			default:
				return 0;
			}

			appendLen = snprintf(append, sizeof(append),
			    appendFormat, value);
			if (appendLen < 0 ||
			    (size_t)appendLen >= sizeof(append))
				return 0;

			if (bufferLen - j < (size_t)appendLen)

				return 0;


			memcpy(buffer + j, append, appendLen);
			j += appendLen;


			state = stateSearchConversionSpecifier;
		}
	}

	if (j >= bufferLen)
		return 0;

	buffer[j] = 0;

	return j;
}